refactor: constructors, update docs
- NewCustomTable -> NewCustom - NewTableBy -> NewBy - NewTable -> New
This commit is contained in:
@@ -14,7 +14,7 @@ import (
|
||||
func TestNewTable(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
table := cuckoo.NewTable[int, bool]()
|
||||
table := cuckoo.New[int, bool]()
|
||||
|
||||
assert.NotNil(table)
|
||||
assert.Zero(table.Size())
|
||||
@@ -23,7 +23,7 @@ func TestNewTable(t *testing.T) {
|
||||
func TestAddItem(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
key, value := 0, true
|
||||
table := cuckoo.NewTable[int, bool]()
|
||||
table := cuckoo.New[int, bool]()
|
||||
|
||||
err := table.Put(key, value)
|
||||
|
||||
@@ -35,7 +35,7 @@ func TestAddItem(t *testing.T) {
|
||||
func TestPutOverwrite(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
key, value, newValue := 0, 1, 2
|
||||
table := cuckoo.NewTable[int, int]()
|
||||
table := cuckoo.New[int, int]()
|
||||
(table.Put(key, value))
|
||||
|
||||
err := table.Put(key, newValue)
|
||||
@@ -50,7 +50,7 @@ func TestPutOverwrite(t *testing.T) {
|
||||
func TestSameHash(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
hash := func(int) uint64 { return 0 }
|
||||
table := cuckoo.NewCustomTable[int, bool](hash, hash, cuckoo.DefaultEqualFunc[int])
|
||||
table := cuckoo.NewCustom[int, bool](hash, hash, cuckoo.DefaultEqualFunc[int])
|
||||
|
||||
errA := table.Put(0, true)
|
||||
errB := table.Put(1, true)
|
||||
@@ -63,14 +63,14 @@ func TestSameHash(t *testing.T) {
|
||||
|
||||
func TestStartingCapacity(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
table := cuckoo.NewTable[int, bool](cuckoo.Capacity(64))
|
||||
table := cuckoo.New[int, bool](cuckoo.Capacity(64))
|
||||
|
||||
assert.Equal(uint64(128), table.TotalCapacity())
|
||||
}
|
||||
|
||||
func TestResizeCapacity(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
table := cuckoo.NewTable[int, bool](
|
||||
table := cuckoo.New[int, bool](
|
||||
cuckoo.Capacity(8),
|
||||
cuckoo.GrowthFactor(2),
|
||||
)
|
||||
@@ -85,7 +85,7 @@ func TestResizeCapacity(t *testing.T) {
|
||||
|
||||
func TestPutMany(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
expected, actual := map[int]bool{}, cuckoo.NewTable[int, bool]()
|
||||
expected, actual := map[int]bool{}, cuckoo.New[int, bool]()
|
||||
|
||||
for i := range 1_000 {
|
||||
expected[i] = true
|
||||
@@ -100,7 +100,7 @@ func TestPutMany(t *testing.T) {
|
||||
|
||||
func TestGetMany(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
table := cuckoo.NewTable[int, bool]()
|
||||
table := cuckoo.New[int, bool]()
|
||||
|
||||
for i := range 1_000 {
|
||||
err := table.Put(i, true)
|
||||
@@ -121,7 +121,7 @@ func TestGetMany(t *testing.T) {
|
||||
func TestDropExistingItem(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
key, value := 0, true
|
||||
table := cuckoo.NewTable[int, bool]()
|
||||
table := cuckoo.New[int, bool]()
|
||||
(table.Put(key, value))
|
||||
|
||||
err := table.Drop(key)
|
||||
@@ -134,7 +134,7 @@ func TestDropExistingItem(t *testing.T) {
|
||||
func TestDropNoItem(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
key := 0
|
||||
table := cuckoo.NewTable[int, bool]()
|
||||
table := cuckoo.New[int, bool]()
|
||||
|
||||
err := table.Drop(key)
|
||||
|
||||
@@ -146,7 +146,7 @@ func TestDropNoItem(t *testing.T) {
|
||||
func TestDropItemCapacity(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
key := 0
|
||||
table := cuckoo.NewTable[int, bool](
|
||||
table := cuckoo.New[int, bool](
|
||||
cuckoo.Capacity(64),
|
||||
cuckoo.GrowthFactor(2),
|
||||
)
|
||||
@@ -164,7 +164,7 @@ func TestDropItemCapacity(t *testing.T) {
|
||||
func TestPutNoCapacity(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
key, value := 0, true
|
||||
table := cuckoo.NewTable[int, bool](
|
||||
table := cuckoo.New[int, bool](
|
||||
cuckoo.Capacity(0),
|
||||
)
|
||||
|
||||
@@ -177,7 +177,7 @@ func TestPutNoCapacity(t *testing.T) {
|
||||
|
||||
func TestBadHashCapacity(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
table := cuckoo.NewCustomTable[int, bool](
|
||||
table := cuckoo.NewCustom[int, bool](
|
||||
func(int) uint64 { return 0 },
|
||||
func(int) uint64 { return 0 },
|
||||
func(a, b int) bool { return a == b },
|
||||
@@ -197,7 +197,7 @@ func TestBadHashCapacity(t *testing.T) {
|
||||
|
||||
func TestDropResizeCapacity(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
table := cuckoo.NewTable[int, bool](
|
||||
table := cuckoo.New[int, bool](
|
||||
cuckoo.Capacity(10),
|
||||
)
|
||||
|
||||
@@ -217,9 +217,7 @@ func TestNewTableBy(t *testing.T) {
|
||||
}
|
||||
|
||||
assert := assert.New(t)
|
||||
table := cuckoo.NewTableBy[User, bool](
|
||||
func(u User) string { return u.id },
|
||||
)
|
||||
table := cuckoo.NewBy[User, bool](func(u User) string { return u.id })
|
||||
|
||||
err := table.Put(User{nil, "1", "Robert"}, true)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user