Skip to content

Commit e9712ca

Browse files
committed
change HasBit to GetBit
1 parent 8669921 commit e9712ca

File tree

5 files changed

+23
-28
lines changed

5 files changed

+23
-28
lines changed

bitarray/bitmap.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ func (b Bitmap32) ClearBit(pos uint) Bitmap32 {
4141
return b & ^(1 << pos)
4242
}
4343

44-
// HasBit returns true if the bit at the given position in the Bitmap32 is 1
45-
func (b Bitmap32) HasBit(pos uint) bool {
44+
// GetBit returns true if the bit at the given position in the Bitmap32 is 1
45+
func (b Bitmap32) GetBit(pos uint) bool {
4646
return (b & (1 << pos)) != 0
4747
}
4848

@@ -70,8 +70,8 @@ func (b Bitmap64) ClearBit(pos uint) Bitmap64 {
7070
return b & ^(1 << pos)
7171
}
7272

73-
// HasBit returns true if the bit at the given position in the Bitmap64 is 1
74-
func (b Bitmap64) HasBit(pos uint) bool {
73+
// GetBit returns true if the bit at the given position in the Bitmap64 is 1
74+
func (b Bitmap64) GetBit(pos uint) bool {
7575
return (b & (1 << pos)) != 0
7676
}
7777

bitarray/bitmap_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ func TestBitmap32_ClearBit(t *testing.T) {
6868
assert.Equal(t, Bitmap32(0), m.ClearBit(2))
6969
}
7070

71-
func TestBitmap32_HasBit(t *testing.T) {
71+
func TestBitmap32_zGetBit(t *testing.T) {
7272
m := Bitmap32(0x55555555)
73-
assert.Equal(t, true, m.HasBit(2))
73+
assert.Equal(t, true, m.GetBit(2))
7474
}
7575

7676
func TestBitmap64_SetBit(t *testing.T) {
@@ -83,9 +83,9 @@ func TestBitmap64_ClearBit(t *testing.T) {
8383
assert.Equal(t, Bitmap64(0), m.ClearBit(2))
8484
}
8585

86-
func TestBitmap64_HasBit(t *testing.T) {
86+
func TestBitmap64_GetBit(t *testing.T) {
8787
m := Bitmap64(0x55555555)
88-
assert.Equal(t, true, m.HasBit(2))
88+
assert.Equal(t, true, m.GetBit(2))
8989
}
9090

9191
func BenchmarkBitmap32_PopCount(b *testing.B) {

trie/dtrie/dtrie.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ func (d *Dtrie) Size() (size int) {
7777
return size
7878
}
7979

80-
// Get returns the Entry for the associated key or returns nil if the
80+
// Get returns the value for the associated key or returns nil if the
8181
// key does not exist.
82-
func (d *Dtrie) Get(key interface{}) Entry {
83-
return get(d.root, d.hasher(key), key)
82+
func (d *Dtrie) Get(key interface{}) interface{} {
83+
return get(d.root, d.hasher(key), key).Value()
8484
}
8585

86-
// Insert adds an entry to the Dtrie, replacing the existing value if
86+
// Insert adds a key value pair to the Dtrie, replacing the existing value if
8787
// the key already exists and returns the resulting Dtrie.
8888
func (d *Dtrie) Insert(key, value interface{}) *Dtrie {
8989
root := insert(d.root, &entry{d.hasher(key), key, value})

trie/dtrie/dtrie_test.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2727
package dtrie
2828

2929
import (
30-
"fmt"
3130
"testing"
3231

3332
"github.com/stretchr/testify/assert"
@@ -40,10 +39,6 @@ func TestDefaultHasher(t *testing.T) {
4039
assert.NotEqual(t, defaultHasher("foo"), defaultHasher("bar"))
4140
}
4241

43-
func (e *entry) String() string {
44-
return fmt.Sprint(e.value)
45-
}
46-
4742
func collisionHash(key interface{}) uint32 {
4843
return uint32(0xffffffff) // for testing collisions
4944
}
@@ -121,7 +116,7 @@ func TestIterate(t *testing.T) {
121116
close(stop)
122117
}
123118
}
124-
assert.True(t, c > 99 && c < 102)
119+
assert.True(t, c == 100)
125120
// test with collisions
126121
n = insertTest(t, collisionHash, 1000)
127122
c = 0

trie/dtrie/node.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func insert(n *node, entry Entry) *node {
8080
newNode.dataMap = newNode.dataMap.SetBit(index)
8181
return newNode
8282
}
83-
if newNode.dataMap.HasBit(index) {
83+
if newNode.dataMap.GetBit(index) {
8484
if newNode.entries[index].Key() == entry.Key() {
8585
newNode.entries[index] = entry
8686
return newNode
@@ -96,12 +96,12 @@ func insert(n *node, entry Entry) *node {
9696
cNode.entries = append(cNode.entries, entry)
9797
return newNode
9898
}
99-
if !newNode.dataMap.HasBit(index) && !newNode.nodeMap.HasBit(index) { // insert directly
99+
if !newNode.dataMap.GetBit(index) && !newNode.nodeMap.GetBit(index) { // insert directly
100100
newNode.entries[index] = entry
101101
newNode.dataMap = newNode.dataMap.SetBit(index)
102102
return newNode
103103
}
104-
if newNode.nodeMap.HasBit(index) { // insert into sub-node
104+
if newNode.nodeMap.GetBit(index) { // insert into sub-node
105105
newNode.entries[index] = insert(newNode.entries[index].(*node), entry)
106106
return newNode
107107
}
@@ -127,10 +127,10 @@ func insert(n *node, entry Entry) *node {
127127
// returns nil if not found
128128
func get(n *node, keyHash uint32, key interface{}) Entry {
129129
index := uint(mask(keyHash, n.level))
130-
if n.dataMap.HasBit(index) {
130+
if n.dataMap.GetBit(index) {
131131
return n.entries[index]
132132
}
133-
if n.nodeMap.HasBit(index) {
133+
if n.nodeMap.GetBit(index) {
134134
return get(n.entries[index].(*node), keyHash, key)
135135
}
136136
if n.level == 6 { // get from collisionNode
@@ -150,19 +150,19 @@ func get(n *node, keyHash uint32, key interface{}) Entry {
150150
func remove(n *node, keyHash uint32, key interface{}) *node {
151151
index := uint(mask(keyHash, n.level))
152152
newNode := n
153-
if n.dataMap.HasBit(index) {
153+
if n.dataMap.GetBit(index) {
154154
newNode.entries[index] = nil
155155
newNode.dataMap = newNode.dataMap.ClearBit(index)
156156
return newNode
157157
}
158-
if n.nodeMap.HasBit(index) {
158+
if n.nodeMap.GetBit(index) {
159159
subNode := newNode.entries[index].(*node)
160160
subNode = remove(subNode, keyHash, key)
161161
// compress if only 1 entry exists in sub-node
162162
if subNode.nodeMap.PopCount() == 0 && subNode.dataMap.PopCount() == 1 {
163163
var e Entry
164164
for i := uint(0); i < 32; i++ {
165-
if subNode.dataMap.HasBit(i) {
165+
if subNode.dataMap.GetBit(i) {
166166
e = subNode.entries[i]
167167
break
168168
}
@@ -210,9 +210,9 @@ func pushEntries(n *node, stop <-chan struct{}, out chan Entry) {
210210
default:
211211
index := uint(i)
212212
switch {
213-
case n.dataMap.HasBit(index):
213+
case n.dataMap.GetBit(index):
214214
out <- e
215-
case n.nodeMap.HasBit(index):
215+
case n.nodeMap.GetBit(index):
216216
wg.Add(1)
217217
go func() {
218218
defer wg.Done()

0 commit comments

Comments
 (0)