Skip to content

Commit

Permalink
Dev to Maiin (#36)
Browse files Browse the repository at this point in the history
* fix mod

* try fixing race

* Revert "try fixing race"

This reverts commit 02ff901.

* using lock for set child and get child

* using locks only for set child and get child

* fix nil mu

* fix delete

* fix delete

* using locks to set attribute of node

* fix memdb tests

* tracking channel of child changes

* removed process lazy redundant

* fix nil check
  • Loading branch information
absolutelightning authored May 28, 2024
1 parent 31f86ec commit db38a35
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ func (t *Txn[T]) recursiveInsert(node Node[T], key []byte, value T, depth int, o
// This means node is nil
if node.getKeyLen() == 0 {
nl := t.makeLeaf(key, value)
node.processLazyRef()
nl.processLazyRef()
if t.trackMutate {
t.trackChannel(node)
Expand Down Expand Up @@ -355,6 +354,9 @@ func (t *Txn[T]) recursiveDelete(node Node[T], key []byte, depth int) (Node[T],
if t.trackMutate {
t.trackChannel(oldRef)
}

t.trackChannel(child)

if doClone {
node = t.writeNode(node)
} else {
Expand Down Expand Up @@ -409,6 +411,12 @@ func (t *Txn[T]) Commit() *RadixTree[T] {
// CommitOnly is used to finalize the transaction and return a new tree, but
// does not issue any notifications until Notify is called.
func (t *Txn[T]) CommitOnly() *RadixTree[T] {
if t.tree.root == nil {
var zero T
t.tree.root = t.makeLeaf(nil, zero)
t.tree.root.setId(0)
t.tree.root.setMutateCh(make(chan struct{}))
}
t.tree.root.incrementLazyRefCount(-1)
t.tree.root.processLazyRef()
nt := &RadixTree[T]{t.tree.root,
Expand Down

0 comments on commit db38a35

Please sign in to comment.