Skip to content

MurmurHash: Step 2 #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: murmur3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions runtime/Go/antlr/atn_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type ATNConfig interface {
Hasher
Comparable

HashCode() int

GetState() ATNState
GetAlt() int
GetSemanticContext() SemanticContext
Expand Down Expand Up @@ -184,6 +186,20 @@ func (b *BaseATNConfig) Hash() string {
return strconv.Itoa(b.state.GetStateNumber()) + "/" + strconv.Itoa(b.alt) + "/" + c + "/" + b.semanticContext.String()
}

func (b *BaseATNConfig) HashCode() int {
var c int
if b.context != nil {
c = b.context.HashCode()
}

h := initHash(7)
h = update(h, b.state.GetStateNumber())
h = update(h, b.alt)
h = update(h, c)
h = update(h, b.semanticContext.HashCode())
return finish(h, 4)
}

func (b *BaseATNConfig) String() string {
var s1, s2, s3 string

Expand Down
28 changes: 28 additions & 0 deletions runtime/Go/antlr/atn_config_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "fmt"
type ATNConfigSet interface {
Hasher

HashCode() int
Add(ATNConfig, *DoubleDict) bool
AddAll([]ATNConfig) bool

Expand Down Expand Up @@ -50,6 +51,7 @@ type ATNConfigSet interface {
// graph-structured stack.
type BaseATNConfigSet struct {
cachedHashString string
cachedHash int

// configLookup is used to determine whether two BaseATNConfigSets are equal. We
// need all configurations with the same (s, i, _, semctx) to be equal. A key
Expand Down Expand Up @@ -246,6 +248,32 @@ func (b *BaseATNConfigSet) hashConfigs() string {
return s
}

func (b *BaseATNConfigSet) HashCode() int {
if b.readOnly {
if b.cachedHash == -1 {
b.cachedHash = b.hashCodeConfigs()
}

return b.cachedHash
}

return b.hashCodeConfigs()
}

func (b *BaseATNConfigSet) hashCodeConfigs() int {
h := 1

for _, c := range b.configs {
h += 31 * h

if c != nil {
h += c.HashCode()
}
}

return h
}

func (b *BaseATNConfigSet) Length() int {
return len(b.configs)
}
Expand Down
21 changes: 21 additions & 0 deletions runtime/Go/antlr/dfa_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,24 @@ func (d *DFAState) Hash() string {

return fmt.Sprint(d.configs) + s
}

func (d *DFAState) HashCode() int {
h := initHash(11)

c := 1
if d.isAcceptState {
if d.predicates != nil {
for _, p := range d.predicates {
h = update(h, p.alt)
h = update(h, p.pred.HashCode())
c += 2
}
} else {
h = update(h, d.prediction)
c += 1
}
}

h = update(h, d.configs.HashCode())
return finish(h, c)
}
1 change: 1 addition & 0 deletions runtime/Go/antlr/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ func PrintArrayJavaStyle(sa []string) string {
return buffer.String()
}


// murmur hash
const (
c1_32 = 0xCC9E2D51
Expand Down