Skip to content

Commit

Permalink
Use BTreeG instead of Generics and various optimizations
Browse files Browse the repository at this point in the history
This commit includes:
- deprecates the Generic type in favor of BTreeG.
- uses an atomic uint64 for copy-on-write marker.
- minimized new allocations on splits.
  • Loading branch information
tidwall committed Aug 12, 2022
1 parent 02d65cd commit 297a9f5
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 131 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ Go 1.18+
- [`btree.Set`](#btreeset):
Like `Map`, but only for storing keys.
Go 1.18+
- [`btree.Generic`](#btreegeneric):
- [`btree.BTreeG`](#btreegeneric):
A feature-rich B-tree for storing data using a custom comparator.
Go 1.18+
- [`btree.BTree`](#btreebtree):
Like `Generic` but uses the `interface{}` type for data. Backwards compatible.
Like `BTreeG` but uses the `interface{}` type for data. Backwards compatible.
Go 1.16+

### btree.Map
Expand Down Expand Up @@ -194,7 +194,7 @@ func main() {
}
```

### btree.Generic
### btree.BTreeG

```go
// Basic
Expand Down Expand Up @@ -265,8 +265,8 @@ func main() {
// Create a tree for keys and a tree for values.
// The "keys" tree will be sorted on the Keys field.
// The "values" tree will be sorted on the Values field.
keys := btree.NewGeneric[Item](byKeys)
vals := btree.NewGeneric[Item](byVals)
keys := btree.NewBTreeG[Item](byKeys)
vals := btree.NewBTreeG[Item](byVals)

// Create some items.
users := []Item{
Expand Down
6 changes: 3 additions & 3 deletions btree.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package btree

type BTree struct {
base *Generic[any]
base *BTreeG[any]
}

// New returns a new BTree
Expand All @@ -13,7 +13,7 @@ func New(less func(a, b any) bool) *BTree {
panic("nil less")
}
return &BTree{
base: NewGeneric(less),
base: NewBTreeG(less),
}
}

Expand All @@ -27,7 +27,7 @@ func NewNonConcurrent(less func(a, b any) bool) *BTree {
panic("nil less")
}
return &BTree{
base: NewGenericOptions(less,
base: NewBTreeGOptions(less,
Options{
NoLocks: true,
}),
Expand Down
Loading

0 comments on commit 297a9f5

Please sign in to comment.