Skip to content

Commit

Permalink
v2: place modified skiplist and pager under v2 directory, optimize pa…
Browse files Browse the repository at this point in the history
…ger smaller page size and header size.
  • Loading branch information
guycipher committed Nov 12, 2024
1 parent 99844e0 commit 9da666c
Show file tree
Hide file tree
Showing 7 changed files with 1,153 additions and 9 deletions.
7 changes: 1 addition & 6 deletions skiplist/skiplist.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,7 @@ func NewNode(level int, key, value []byte, ttl *time.Duration) *Node {

// Size returns the size of the node in bytes
func (n *Node) Size() int {
size := len(n.key) + len(n.value) + len(n.forward)*int(unsafe.Sizeof(uintptr(0)))
if n.ttl != nil {
size += int(unsafe.Sizeof(*n.ttl))
}

return size
return int(unsafe.Sizeof(*n)) + len(n.key) + len(n.value)
}

// IsExpired checks if the node is expired
Expand Down
4 changes: 2 additions & 2 deletions v2/k4.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ import (
"encoding/gob"
"fmt"
"github.com/guycipher/k4/compressor"
"github.com/guycipher/k4/pager"
"github.com/guycipher/k4/skiplist"
"github.com/guycipher/k4/v2/cuckoofilter"
"github.com/guycipher/k4/v2/pager"
"github.com/guycipher/k4/v2/skiplist"
"log"
"os"
"sort"
Expand Down
5 changes: 4 additions & 1 deletion v2/k4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,12 @@ func TestMemtableFlush(t *testing.T) {
t.Fatalf("Failed to open K4: %v", err)
}

totalBytes := 0

for i := 0; i < 100; i++ {
key := []byte("key" + fmt.Sprintf("%d", i))
value := []byte("value" + fmt.Sprintf("%d", i))
totalBytes += len(key) + len(value)

err = k4.Put(key, value, nil)
if err != nil {
Expand Down Expand Up @@ -375,7 +378,7 @@ func TestCompaction2(t *testing.T) {
dir := setup(t)
defer teardown(dir)

k4, err := Open(dir, 950*2, 1000, true, false)
k4, err := Open(dir, 950*2, 2000, true, false)
if err != nil {
t.Fatalf("Failed to open K4: %v", err)
}
Expand Down
Loading

0 comments on commit 9da666c

Please sign in to comment.