Documentation
¶
Overview ¶
Copyright 2025 Stoolap Contributors
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Package btree provides optimized B-tree implementations ¶
Copyright 2025 Stoolap Contributors ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- type BTree
- func (t *BTree[K, V]) Delete(key K) bool
- func (t *BTree[K, V]) ForEach(callback func(key K, value V) bool)
- func (t *BTree[K, V]) Insert(key K, value V)
- func (t *BTree[K, V]) Iterate() *Iterator[K, V]
- func (t *BTree[K, V]) Search(key K) (V, bool)
- func (t *BTree[K, V]) SeekGE(target K) *Iterator[K, V]
- func (t *BTree[K, V]) Size() int
- func (t *BTree[K, V]) String() string
- type Comparer
- type Int64BTree
- func (t *Int64BTree[V]) BatchInsert(keys []int64, values []V)
- func (t *Int64BTree[V]) Delete(key int64) bool
- func (t *Int64BTree[V]) ForEach(callback func(key int64, value V) bool)
- func (t *Int64BTree[V]) GetAll() iter.Seq2[int64, V]
- func (t *Int64BTree[V]) Insert(key int64, value V)
- func (t *Int64BTree[V]) RangeSearch(start, end int64) []V
- func (t *Int64BTree[V]) Search(key int64) (V, bool)
- func (t *Int64BTree[V]) Size() int
- type Iterator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BTree ¶
BTree is a generic B-tree implementation for any key type that implements Comparer
func (*BTree[K, V]) Insert ¶
func (t *BTree[K, V]) Insert(key K, value V)
Insert adds or updates a key-value pair in the tree
func (*BTree[K, V]) Search ¶
Search looks up a key in the tree Returns the value and true if found, or zero value and false if not found
func (*BTree[K, V]) SeekGE ¶
SeekGE positions the iterator at the first key greater than or equal to the target
type Comparer ¶
type Comparer[K any] interface { // Compare compares this key with another key // Returns negative if this < other, 0 if equal, positive if this > other Compare(other K) int }
Comparer defines the interface for objects that can be used as keys in a BTree
type Int64BTree ¶
type Int64BTree[V any] struct { // contains filtered or unexported fields }
Int64BTree is a highly optimized B-tree for int64 keys Key design points: 1. Fixed size arrays for keys/values/children to avoid resizing 2. Cache-friendly memory layout 3. Binary search for fast key lookup 4. Block transfer for bulk operations
func NewInt64BTree ¶
func NewInt64BTree[V any]() *Int64BTree[V]
NewInt64BTree creates a new BTree optimized for int64 keys
func (*Int64BTree[V]) BatchInsert ¶
func (t *Int64BTree[V]) BatchInsert(keys []int64, values []V)
BatchInsert efficiently inserts multiple key-value pairs
func (*Int64BTree[V]) Delete ¶
func (t *Int64BTree[V]) Delete(key int64) bool
Delete removes a key-value pair from the tree Returns true if the key was found and deleted, false otherwise
func (*Int64BTree[V]) ForEach ¶
func (t *Int64BTree[V]) ForEach(callback func(key int64, value V) bool)
ForEach visits all keys in the tree in order
func (*Int64BTree[V]) GetAll ¶
func (t *Int64BTree[V]) GetAll() iter.Seq2[int64, V]
GetAll returns all values in the tree
func (*Int64BTree[V]) Insert ¶
func (t *Int64BTree[V]) Insert(key int64, value V)
Insert adds or updates a key-value pair in the tree Returns true if a new key was inserted, false if an existing key was updated
func (*Int64BTree[V]) RangeSearch ¶
func (t *Int64BTree[V]) RangeSearch(start, end int64) []V
RangeSearch finds all values with keys in range [start, end] inclusive
func (*Int64BTree[V]) Search ¶
func (t *Int64BTree[V]) Search(key int64) (V, bool)
Search looks up a key in the tree Returns the value and true if found, or zero value and false if not found
func (*Int64BTree[V]) Size ¶
func (t *Int64BTree[V]) Size() int
Size returns the number of key-value pairs in the tree