set flag SymbolWithMasterSymbol. static class Symbol implements CharSequence, Comparable<Symbol> { S text; MasterSymbol master; *() {} *(S *text, bool dummy) {} // weird signature to prevent accidental calling *(S *text, MasterSymbol *master) {} bool isMaster() { ret master == this; } final public int hashCode() { ret master.lowerCaseHash; } S text() { ret text; } final toString { ret text; } S lowerCase() { ret lower(text()); } final public bool equals(O o) { if (!(o instanceof Symbol)) false; bool result = o instanceof Symbol && master == o/Symbol.master; ifdef symbol_debug print("Symbol.equals: " + this + " vs " + o + " => " + result); endifdef ret result; } public int length() { ret text.length(); } public char charAt(int index) { ret text.charAt(index); } public CharSequence subSequence(int start, int end) { ret text.substring(start, end); } // This really has to be correct for TreeMap<Symbol, ...> // equals() <=> compareTo() == 0 or at least // equals() => compareTo() == 0. public int compareTo(Symbol s) { //ret lowerCase().compareTo(s.lowerCase()); ret lowerCaseCompare(text, s.text); } } static final class MasterSymbol extends Symbol { //S lowerCase; int lowerCaseHash; bool dollarVar; *() {} *(S *text, bool dummy) { master = this; S lowerCase = lower(text); lowerCaseHash = lowerCase.hashCode(); dollarVar = isDollarVar(lowerCase); } int lowerCaseHash() { ret lowerCaseHash; } }
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1010608 |
Snippet name: | class Symbol [CharSequence comparable with ==] + MasterSymbol v2 - a case-insensitive string with faster compare (though not with == anymore) |
Eternal ID of this version: | #1010608/28 |
Text MD5: | 8e070907420aa9097a8639f4eabaac4e |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-09-08 03:49:25 |
Source code size: | 1588 bytes / 54 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 611 / 1324 |
Version history: | 27 change(s) |
Referenced in: | [show references] |