Skip to content

Commit ee781de

Browse files
Merge pull request #128 from tylertreat-wf/ctrie_remove_hash_pool
Remove hasher pool from ctrie
2 parents 6519136 + 340b91f commit ee781de

File tree

1 file changed

+3
-17
lines changed

1 file changed

+3
-17
lines changed

trie/ctrie/ctrie.go

+3-17
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
"unsafe"
3333

3434
"github.com/Workiva/go-datastructures/list"
35-
"github.com/Workiva/go-datastructures/queue"
3635
)
3736

3837
const (
@@ -41,9 +40,6 @@ const (
4140

4241
// exp2 is 2^w, which is the hashcode space.
4342
exp2 = 32
44-
45-
// hasherPoolSize is the number of hashers to buffer.
46-
hasherPoolSize = 16
4743
)
4844

4945
// HashFactory returns a new Hash32 used to hash keys.
@@ -59,7 +55,6 @@ type Ctrie struct {
5955
root *iNode
6056
readOnly bool
6157
hashFactory HashFactory
62-
hasherPool *queue.RingBuffer
6358
}
6459

6560
// generation demarcates Ctrie snapshots. We use a heap-allocated reference
@@ -280,14 +275,9 @@ func New(hashFactory HashFactory) *Ctrie {
280275
}
281276

282277
func newCtrie(root *iNode, hashFactory HashFactory, readOnly bool) *Ctrie {
283-
hasherPool := queue.NewRingBuffer(hasherPoolSize)
284-
for i := 0; i < hasherPoolSize; i++ {
285-
hasherPool.Put(hashFactory())
286-
}
287278
return &Ctrie{
288279
root: root,
289280
hashFactory: hashFactory,
290-
hasherPool: hasherPool,
291281
readOnly: readOnly,
292282
}
293283
}
@@ -451,13 +441,9 @@ func (c *Ctrie) remove(entry *Entry) (interface{}, bool) {
451441
}
452442

453443
func (c *Ctrie) hash(k []byte) uint32 {
454-
hasher, _ := c.hasherPool.Get()
455-
h := hasher.(hash.Hash32)
456-
h.Write(k)
457-
hash := h.Sum32()
458-
h.Reset()
459-
c.hasherPool.Put(h)
460-
return hash
444+
hasher := c.hashFactory()
445+
hasher.Write(k)
446+
return hasher.Sum32()
461447
}
462448

463449
// iinsert attempts to insert the entry into the Ctrie. If false is returned,

0 commit comments

Comments
 (0)