Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions go/store/prolly/tree/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ func (t StaticMap[K, V, O]) WalkNodes(ctx context.Context, cb NodeCb) error {
}

func (t StaticMap[K, V, O]) Get(ctx context.Context, query K, cb KeyValueFn[K, V]) (err error) {
cur, err := newLeafCursorAtKey(ctx, t.NodeStore, t.Root, query, t.Order)
cur := &cursor{nd: t.Root, nrw: t.NodeStore}
err = moveCursorToKey(ctx, cur, query, t.Order)
if err != nil {
return err
}
Expand All @@ -260,7 +261,8 @@ func (t StaticMap[K, V, O]) Get(ctx context.Context, query K, cb KeyValueFn[K, V
}

func (t StaticMap[K, V, O]) GetPrefix(ctx context.Context, query K, prefixOrder O, cb KeyValueFn[K, V]) (err error) {
cur, err := newLeafCursorAtKey(ctx, t.NodeStore, t.Root, query, prefixOrder)
cur := &cursor{nd: t.Root, nrw: t.NodeStore}
err = moveCursorToKey(ctx, cur, query, prefixOrder)
if err != nil {
return err
}
Expand All @@ -280,7 +282,8 @@ func (t StaticMap[K, V, O]) GetPrefix(ctx context.Context, query K, prefixOrder
}

func (t StaticMap[K, V, O]) Has(ctx context.Context, query K) (ok bool, err error) {
cur, err := newLeafCursorAtKey(ctx, t.NodeStore, t.Root, query, t.Order)
cur := &cursor{nd: t.Root, nrw: t.NodeStore}
err = moveCursorToKey(ctx, cur, query, t.Order)
if err != nil {
return false, err
} else if cur.Valid() {
Expand All @@ -290,7 +293,8 @@ func (t StaticMap[K, V, O]) Has(ctx context.Context, query K) (ok bool, err erro
}

func (t StaticMap[K, V, O]) HasPrefix(ctx context.Context, query K, prefixOrder O) (ok bool, err error) {
cur, err := newLeafCursorAtKey(ctx, t.NodeStore, t.Root, query, prefixOrder)
cur := &cursor{nd: t.Root, nrw: t.NodeStore}
err = moveCursorToKey(ctx, cur, query, prefixOrder)
if err != nil {
return false, err
} else if cur.Valid() {
Expand Down
9 changes: 4 additions & 5 deletions go/store/prolly/tree/node_cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,8 @@ func newCursorFromSearchFn(ctx context.Context, ns NodeStore, nd *Node, search S
return
}

func newLeafCursorAtKey[K ~[]byte, O Ordering[K]](ctx context.Context, ns NodeStore, nd *Node, key K, order O) (cursor, error) {
func moveCursorToKey[K ~[]byte, O Ordering[K]](ctx context.Context, cur *cursor, key K, order O) error {
var err error
cur := cursor{nd: nd, nrw: ns}
for {
// binary search |cur.nd| for |key|
i, j := 0, cur.nd.Count()
Expand All @@ -208,12 +207,12 @@ func newLeafCursorAtKey[K ~[]byte, O Ordering[K]](ctx context.Context, ns NodeSt
cur.keepInBounds()

// reuse |cur| object to keep stack alloc'd
cur.nd, err = fetchChild(ctx, ns, cur.currentRef())
cur.nd, err = fetchChild(ctx, cur.nrw, cur.currentRef())
if err != nil {
return cur, err
return err
}
}
return cur, nil
return nil
}

// searchForKey returns a SearchFn for |key|.
Expand Down
Loading