Skip to content

Commit

Permalink
optimize setDIB by apply the hash mask
Browse files Browse the repository at this point in the history
  • Loading branch information
0-haha committed Apr 7, 2023
1 parent 3e19ee4 commit 9d2f4df
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions map_shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const (
hashBitSize = 64 - dibBitSize // 0xFFFFFFFFFFFF
maxHash = ^uint64(0) >> dibBitSize // max 28,147,497,671,0655
maxDIB = ^uint64(0) >> hashBitSize // max 65,535
hashMask = ^maxDIB // 0xFFFF FFFF FFFF 0000
)

type entry[K comparable, V any] struct {
Expand All @@ -25,10 +26,10 @@ func (e *entry[K, V]) hash() uint64 {
return e.hdib >> dibBitSize
}
func (e *entry[K, V]) setDIB(dib uint64) {
e.hdib = e.hdib>>dibBitSize<<dibBitSize | dib&maxDIB
e.hdib = e.hdib&hashMask | dib&maxDIB
}
func (e *entry[K, V]) setHash(hash uint64) {
e.hdib = uint64(hash)<<dibBitSize | e.hdib&maxDIB
e.hdib = hash<<dibBitSize | e.hdib&maxDIB
}
func makeHDIB(hash, dib uint64) uint64 {
return hash<<dibBitSize | dib&maxDIB
Expand Down

0 comments on commit 9d2f4df

Please sign in to comment.