mirror of https://github.com/tidwall/buntdb.git
Updated for latest btree
This commit is contained in:
parent
cf4e3bfc63
commit
46f673238a
39
buntdb.go
39
buntdb.go
|
@ -66,8 +66,8 @@ type DB struct {
|
|||
mu sync.RWMutex // the gatekeeper for all fields
|
||||
file *os.File // the underlying file
|
||||
buf []byte // a buffer to write to
|
||||
keys *btree.BTree[*dbItem] // a tree of all item ordered by key
|
||||
exps *btree.BTree[*dbItem] // a tree of items ordered by expiration
|
||||
keys *btree.Generic[*dbItem] // a tree of all item ordered by key
|
||||
exps *btree.Generic[*dbItem] // a tree of items ordered by expiration
|
||||
idxs map[string]*index // the index trees.
|
||||
insIdxs []*index // a reuse buffer for gathering indexes
|
||||
flushes int // a count of the number of disk flushes
|
||||
|
@ -245,7 +245,7 @@ func (db *DB) Load(rd io.Reader) error {
|
|||
// index represents a b-tree or r-tree index and also acts as the
|
||||
// b-tree/r-tree context for itself.
|
||||
type index struct {
|
||||
btr *btree.BTree[*dbItem] // contains the items
|
||||
btr *btree.Generic[*dbItem] // contains the items
|
||||
rtr *rtred.RTree // contains the items
|
||||
name string // name of the index
|
||||
pattern string // a required key pattern
|
||||
|
@ -1037,8 +1037,8 @@ type Tx struct {
|
|||
|
||||
type txWriteContext struct {
|
||||
// rollback when deleteAll is called
|
||||
rbkeys *btree.BTree[*dbItem] // a tree of all item ordered by key
|
||||
rbexps *btree.BTree[*dbItem] // a tree of items ordered by expiration
|
||||
rbkeys *btree.Generic[*dbItem] // a tree of all item ordered by key
|
||||
rbexps *btree.Generic[*dbItem] // a tree of items ordered by expiration
|
||||
rbidxs map[string]*index // the index trees.
|
||||
|
||||
rollbackItems map[string]*dbItem // details for rolling back tx.
|
||||
|
@ -1616,7 +1616,7 @@ func (tx *Tx) scan(desc, gt, lt bool, index, start, stop string,
|
|||
iter := func(dbi *dbItem) bool {
|
||||
return iterator(dbi.key, dbi.val)
|
||||
}
|
||||
var tr *btree.BTree[*dbItem]
|
||||
var tr *btree.Generic[*dbItem]
|
||||
if index == "" {
|
||||
// empty index means we will use the keys tree.
|
||||
tr = tx.db.keys
|
||||
|
@ -2299,23 +2299,20 @@ func Desc(less func(a, b string) bool) func(a, b string) bool {
|
|||
|
||||
//// Wrappers around btree Ascend/Descend
|
||||
|
||||
func bLT(tr *btree.BTree[*dbItem], a, b *dbItem) bool {
|
||||
func bLT(tr *btree.Generic[*dbItem], a, b *dbItem) bool {
|
||||
return tr.Less(a, b)
|
||||
}
|
||||
func bGT(tr *btree.BTree[*dbItem], a, b *dbItem) bool {
|
||||
func bGT(tr *btree.Generic[*dbItem], a, b *dbItem) bool {
|
||||
return tr.Less(b, a)
|
||||
}
|
||||
|
||||
// func bLTE(tr *btree.BTree, a, b *dbItem) bool { return !tr.Less(b, a) }
|
||||
// func bGTE(tr *btree.BTree, a, b *dbItem) bool { return !tr.Less(a, b) }
|
||||
|
||||
// Ascend
|
||||
|
||||
func btreeAscend(tr *btree.BTree[*dbItem], iter func(item *dbItem) bool) {
|
||||
func btreeAscend(tr *btree.Generic[*dbItem], iter func(item *dbItem) bool) {
|
||||
tr.Scan(iter)
|
||||
}
|
||||
|
||||
func btreeAscendLessThan(tr *btree.BTree[*dbItem], pivot *dbItem,
|
||||
func btreeAscendLessThan(tr *btree.Generic[*dbItem], pivot *dbItem,
|
||||
iter func(item *dbItem) bool,
|
||||
) {
|
||||
tr.Scan(func(item *dbItem) bool {
|
||||
|
@ -2323,13 +2320,13 @@ func btreeAscendLessThan(tr *btree.BTree[*dbItem], pivot *dbItem,
|
|||
})
|
||||
}
|
||||
|
||||
func btreeAscendGreaterOrEqual(tr *btree.BTree[*dbItem], pivot *dbItem,
|
||||
func btreeAscendGreaterOrEqual(tr *btree.Generic[*dbItem], pivot *dbItem,
|
||||
iter func(item *dbItem) bool,
|
||||
) {
|
||||
tr.Ascend(pivot, iter)
|
||||
}
|
||||
|
||||
func btreeAscendRange(tr *btree.BTree[*dbItem], greaterOrEqual,
|
||||
func btreeAscendRange(tr *btree.Generic[*dbItem], greaterOrEqual,
|
||||
lessThan *dbItem, iter func(item *dbItem) bool,
|
||||
) {
|
||||
tr.Ascend(greaterOrEqual, func(item *dbItem) bool {
|
||||
|
@ -2339,11 +2336,11 @@ func btreeAscendRange(tr *btree.BTree[*dbItem], greaterOrEqual,
|
|||
|
||||
// Descend
|
||||
|
||||
func btreeDescend(tr *btree.BTree[*dbItem], iter func(item *dbItem) bool) {
|
||||
func btreeDescend(tr *btree.Generic[*dbItem], iter func(item *dbItem) bool) {
|
||||
tr.Reverse(iter)
|
||||
}
|
||||
|
||||
func btreeDescendGreaterThan(tr *btree.BTree[*dbItem], pivot *dbItem,
|
||||
func btreeDescendGreaterThan(tr *btree.Generic[*dbItem], pivot *dbItem,
|
||||
iter func(item *dbItem) bool,
|
||||
) {
|
||||
tr.Reverse(func(item *dbItem) bool {
|
||||
|
@ -2351,7 +2348,7 @@ func btreeDescendGreaterThan(tr *btree.BTree[*dbItem], pivot *dbItem,
|
|||
})
|
||||
}
|
||||
|
||||
func btreeDescendRange(tr *btree.BTree[*dbItem], lessOrEqual,
|
||||
func btreeDescendRange(tr *btree.Generic[*dbItem], lessOrEqual,
|
||||
greaterThan *dbItem, iter func(item *dbItem) bool,
|
||||
) {
|
||||
tr.Descend(lessOrEqual, func(item *dbItem) bool {
|
||||
|
@ -2359,12 +2356,12 @@ func btreeDescendRange(tr *btree.BTree[*dbItem], lessOrEqual,
|
|||
})
|
||||
}
|
||||
|
||||
func btreeDescendLessOrEqual(tr *btree.BTree[*dbItem], pivot *dbItem,
|
||||
func btreeDescendLessOrEqual(tr *btree.Generic[*dbItem], pivot *dbItem,
|
||||
iter func(item *dbItem) bool,
|
||||
) {
|
||||
tr.Descend(pivot, iter)
|
||||
}
|
||||
|
||||
func btreeNew(less func(a, b *dbItem) bool) *btree.BTree[*dbItem] {
|
||||
return btree.NewOptions(less, btree.Options{NoLocks: true})
|
||||
func btreeNew(less func(a, b *dbItem) bool) *btree.Generic[*dbItem] {
|
||||
return btree.NewGenericOptions(less, btree.Options{NoLocks: true})
|
||||
}
|
||||
|
|
2
go.mod
2
go.mod
|
@ -4,7 +4,7 @@ go 1.18
|
|||
|
||||
require (
|
||||
github.com/tidwall/assert v0.1.0
|
||||
github.com/tidwall/btree v0.7.2-0.20211218005449-cbb03286d2f2
|
||||
github.com/tidwall/btree v1.1.1-0.20211224172409-40e5f803476c
|
||||
github.com/tidwall/gjson v1.12.1
|
||||
github.com/tidwall/grect v0.1.4
|
||||
github.com/tidwall/lotsa v1.0.2
|
||||
|
|
4
go.sum
4
go.sum
|
@ -1,7 +1,7 @@
|
|||
github.com/tidwall/assert v0.1.0 h1:aWcKyRBUAdLoVebxo95N7+YZVTFF/ASTr7BN4sLP6XI=
|
||||
github.com/tidwall/assert v0.1.0/go.mod h1:QLYtGyeqse53vuELQheYl9dngGCJQ+mTtlxcktb+Kj8=
|
||||
github.com/tidwall/btree v0.7.2-0.20211218005449-cbb03286d2f2 h1:ehSxDCH+l3iIecsbPBzed/grEc5R24bhLbJdU+QMbHQ=
|
||||
github.com/tidwall/btree v0.7.2-0.20211218005449-cbb03286d2f2/go.mod h1:LGm8L/DZjPLmeWGjv5kFrY8dL4uVhMmzmmLYmsObdKE=
|
||||
github.com/tidwall/btree v1.1.1-0.20211224172409-40e5f803476c h1:jSRtuFkVrUK4P3VUVYD4WssGige8x3iYKyDBW+FuIsA=
|
||||
github.com/tidwall/btree v1.1.1-0.20211224172409-40e5f803476c/go.mod h1:LGm8L/DZjPLmeWGjv5kFrY8dL4uVhMmzmmLYmsObdKE=
|
||||
github.com/tidwall/gjson v1.12.1 h1:ikuZsLdhr8Ws0IdROXUS1Gi4v9Z4pGqpX/CvJkxvfpo=
|
||||
github.com/tidwall/gjson v1.12.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/grect v0.1.4 h1:dA3oIgNgWdSspFzn1kS4S/RDpZFLrIxAZOdJKjYapOg=
|
||||
|
|
Loading…
Reference in New Issue