-
Notifications
You must be signed in to change notification settings - Fork 35
/
compact_test.go
48 lines (35 loc) · 1016 Bytes
/
compact_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package offheap_test
import (
"testing"
"github.com/glycerine/offheap"
cv "github.com/glycerine/goconvey/convey"
)
func TestCompact(t *testing.T) {
cv.Convey("Given a big table with no values it, Compact() should re-allocate it to be smaller", t, func() {
h := offheap.NewHashTable(128)
cv.So(h.ArraySize, cv.ShouldEqual, 128)
cv.So(h.Population, cv.ShouldEqual, 0)
h.Compact()
cv.So(h.ArraySize, cv.ShouldEqual, 1)
cv.So(h.Population, cv.ShouldEqual, 0)
})
}
func TestCompatAfterDelete(t *testing.T) {
h := offheap.NewHashTable(2)
h.Clear()
cv.Convey("after being filled up and then deleted down to just 2 elements, Compact() should reduce table size to 4", t, func() {
N := 100
// fill up a table
cv.So(h.Population, cv.ShouldEqual, 0)
for i := 0; i < N; i++ {
h.Insert(uint64(i))
}
// now delete from it
for i := 0; i < N-2; i++ {
h.DeleteKey(uint64(i))
}
cv.So(h.ArraySize, cv.ShouldEqual, 256)
h.Compact()
cv.So(h.ArraySize, cv.ShouldEqual, 4)
})
}