diff --git a/runtime/Go/antlr/atn_config.go b/runtime/Go/antlr/atn_config.go index 1348b0e3dd..f49d7f4c46 100644 --- a/runtime/Go/antlr/atn_config.go +++ b/runtime/Go/antlr/atn_config.go @@ -6,7 +6,6 @@ package antlr import ( "fmt" - "strconv" ) type Comparable interface { @@ -37,8 +36,6 @@ type ATNConfig interface { getPrecedenceFilterSuppressed() bool setPrecedenceFilterSuppressed(bool) - - shortHash() string } type BaseATNConfig struct { @@ -169,10 +166,6 @@ func (b *BaseATNConfig) equals(o interface{}) bool { return nums && alts && cons && sups && equal } -func (b *BaseATNConfig) shortHash() string { - return strconv.Itoa(b.state.GetStateNumber()) + "/" + strconv.Itoa(b.alt) + "/" + b.semanticContext.String() -} - func (b *BaseATNConfig) HashCode() int { var c int if b.context != nil { diff --git a/runtime/Go/antlr/dfa_state.go b/runtime/Go/antlr/dfa_state.go index 6c8e3c0798..71067eecfb 100644 --- a/runtime/Go/antlr/dfa_state.go +++ b/runtime/Go/antlr/dfa_state.go @@ -6,7 +6,6 @@ package antlr import ( "fmt" - "strconv" ) // PredPrediction maps a predicate to a predicted alternative. @@ -133,12 +132,7 @@ func (d *DFAState) equals(other interface{}) bool { } func (d *DFAState) String() string { - return strconv.Itoa(d.stateNumber) + ":" + d.Hash() -} - -func (d *DFAState) Hash() string { var s string - if d.isAcceptState { if d.predicates != nil { s = "=>" + fmt.Sprint(d.predicates) @@ -147,7 +141,7 @@ func (d *DFAState) Hash() string { } } - return fmt.Sprint(d.configs) + s + return fmt.Sprintf("%d:%s%s", fmt.Sprint(d.configs), s) } func (d *DFAState) HashCode() int { diff --git a/runtime/Go/antlr/lexer_action.go b/runtime/Go/antlr/lexer_action.go index f1bbce4b93..8e32e9d397 100644 --- a/runtime/Go/antlr/lexer_action.go +++ b/runtime/Go/antlr/lexer_action.go @@ -21,7 +21,6 @@ type LexerAction interface { getActionType() int getIsPositionDependent() bool execute(lexer Lexer) - Hash() string HashCode() int equals(other LexerAction) bool } @@ -56,10 +55,6 @@ func (b *BaseLexerAction) HashCode() int { return b.actionType } -func (b *BaseLexerAction) Hash() string { - return strconv.Itoa(b.actionType) -} - func (b *BaseLexerAction) equals(other LexerAction) bool { return b == other } @@ -109,8 +104,11 @@ func (l *LexerTypeAction) execute(lexer Lexer) { lexer.setType(l.thetype) } -func (l *LexerTypeAction) Hash() string { - return strconv.Itoa(l.actionType) + strconv.Itoa(l.thetype) +func (l *LexerTypeAction) HashCode() int { + h := initHash(0) + h = update(h, l.actionType) + h = update(h, l.thetype) + return finish(h, 2) } func (l *LexerTypeAction) equals(other LexerAction) bool { @@ -150,8 +148,11 @@ func (l *LexerPushModeAction) execute(lexer Lexer) { lexer.pushMode(l.mode) } -func (l *LexerPushModeAction) Hash() string { - return strconv.Itoa(l.actionType) + strconv.Itoa(l.mode) +func (l *LexerPushModeAction) HashCode() int { + h := initHash(0) + h = update(h, l.actionType) + h = update(h, l.mode) + return finish(h, 2) } func (l *LexerPushModeAction) equals(other LexerAction) bool { @@ -244,8 +245,11 @@ func (l *LexerModeAction) execute(lexer Lexer) { lexer.setMode(l.mode) } -func (l *LexerModeAction) Hash() string { - return strconv.Itoa(l.actionType) + strconv.Itoa(l.mode) +func (l *LexerModeAction) HashCode() int { + h := initHash(0) + h = update(h, l.actionType) + h = update(h, l.mode) + return finish(h, 2) } func (l *LexerModeAction) equals(other LexerAction) bool { @@ -299,8 +303,12 @@ func (l *LexerCustomAction) execute(lexer Lexer) { lexer.Action(nil, l.ruleIndex, l.actionIndex) } -func (l *LexerCustomAction) Hash() string { - return strconv.Itoa(l.actionType) + strconv.Itoa(l.ruleIndex) + strconv.Itoa(l.actionIndex) +func (l *LexerCustomAction) HashCode() int { + h := initHash(0) + h = update(h, l.actionType) + h = update(h, l.ruleIndex) + h = update(h, l.actionIndex) + return finish(h, 3) } func (l *LexerCustomAction) equals(other LexerAction) bool { @@ -336,8 +344,11 @@ func (l *LexerChannelAction) execute(lexer Lexer) { lexer.setChannel(l.channel) } -func (l *LexerChannelAction) Hash() string { - return strconv.Itoa(l.actionType) + strconv.Itoa(l.channel) +func (l *LexerChannelAction) HashCode() int { + h := initHash(0) + h = update(h, l.actionType) + h = update(h, l.channel) + return finish(h, 2) } func (l *LexerChannelAction) equals(other LexerAction) bool { @@ -401,8 +412,12 @@ func (l *LexerIndexedCustomAction) execute(lexer Lexer) { l.lexerAction.execute(lexer) } -func (l *LexerIndexedCustomAction) Hash() string { - return strconv.Itoa(l.actionType) + strconv.Itoa(l.offset) + l.lexerAction.Hash() +func (l *LexerIndexedCustomAction) HashCode() int { + h := initHash(0) + h = update(h, l.actionType) + h = update(h, l.offset) + h = update(h, l.lexerAction.HashCode()) + return finish(h, 3) } func (l *LexerIndexedCustomAction) equals(other LexerAction) bool { diff --git a/runtime/Go/antlr/lexer_action_executor.go b/runtime/Go/antlr/lexer_action_executor.go index b281d036ba..62f32609c7 100644 --- a/runtime/Go/antlr/lexer_action_executor.go +++ b/runtime/Go/antlr/lexer_action_executor.go @@ -13,7 +13,6 @@ package antlr type LexerActionExecutor struct { lexerActions []LexerAction - cachedHashString string cachedHash int } @@ -29,16 +28,11 @@ func NewLexerActionExecutor(lexerActions []LexerAction) *LexerActionExecutor { // Caches the result of {@link //hashCode} since the hash code is an element // of the performance-critical {@link LexerATNConfig//hashCode} operation. - - var s string l.cachedHash = initHash(57) for _, a := range lexerActions { - s += a.Hash() l.cachedHash = update(l.cachedHash, a.HashCode()) } - l.cachedHashString = s // "".join([str(la) for la in - return l } @@ -60,10 +54,7 @@ func LexerActionExecutorappend(lexerActionExecutor *LexerActionExecutor, lexerAc return NewLexerActionExecutor([]LexerAction{lexerAction}) } - lexerActions := append(lexerActionExecutor.lexerActions, lexerAction) - - // lexerActions := lexerActionExecutor.lexerActions.concat([ lexerAction ]) - return NewLexerActionExecutor(lexerActions) + return NewLexerActionExecutor(append(lexerActionExecutor.lexerActions, lexerAction)) } // Creates a {@link LexerActionExecutor} which encodes the current offset @@ -160,10 +151,6 @@ func (l *LexerActionExecutor) execute(lexer Lexer, input CharStream, startIndex } } -func (l *LexerActionExecutor) Hash() string { - return l.cachedHashString -} - func (l *LexerActionExecutor) HashCode() int { if l == nil { return 61 @@ -177,7 +164,7 @@ func (l *LexerActionExecutor) equals(other interface{}) bool { } else if _, ok := other.(*LexerActionExecutor); !ok { return false } else { - return l.cachedHashString == other.(*LexerActionExecutor).cachedHashString && + return l.cachedHash == other.(*LexerActionExecutor).cachedHash && &l.lexerActions == &other.(*LexerActionExecutor).lexerActions } } diff --git a/runtime/Go/antlr/semantic_context.go b/runtime/Go/antlr/semantic_context.go index f42d883b30..44c99751ea 100644 --- a/runtime/Go/antlr/semantic_context.go +++ b/runtime/Go/antlr/semantic_context.go @@ -95,10 +95,6 @@ func (p *Predicate) evaluate(parser Recognizer, outerContext RuleContext) bool { return parser.Sempred(localctx, p.ruleIndex, p.predIndex) } -func (p *Predicate) Hash() string { - return strconv.Itoa(p.ruleIndex) + "/" + strconv.Itoa(p.predIndex) + "/" + fmt.Sprint(p.isCtxDependent) -} - func (p *Predicate) equals(other interface{}) bool { if p == other { return true @@ -147,10 +143,6 @@ func (p *PrecedencePredicate) compareTo(other *PrecedencePredicate) int { return p.precedence - other.precedence } -func (p *PrecedencePredicate) Hash() string { - return "31" -} - func (p *PrecedencePredicate) equals(other interface{}) bool { if p == other { return true diff --git a/runtime/Go/antlr/utils.go b/runtime/Go/antlr/utils.go index c276c8b282..ea072751e6 100644 --- a/runtime/Go/antlr/utils.go +++ b/runtime/Go/antlr/utils.go @@ -94,20 +94,9 @@ func standardHashFunction(a interface{}) int { return h.HashCode() } - if h, ok := a.(Hasher); ok { - s := h.Hash() - ha := fnv.New32a() - ha.Write([]byte((s))) - return int(ha.Sum32()) - } - panic("Not Hasher") } -type Hasher interface { - Hash() string -} - type HashCoder interface { HashCode() int }