diff --git a/forest.go b/forest.go index 0639821..fd783fa 100644 --- a/forest.go +++ b/forest.go @@ -14,6 +14,21 @@ type treeNode struct { children map[int]*treeNode } +func (node *treeNode) recursiveDelete() { + for _, child := range node.children { + if len((child).children) > 0 { + (child).recursiveDelete() + } + + if len(child.indices) > 0 { + node.indices = nil + } + } + + node.indices = nil + node.children = nil +} + // recursiveAdd recurses down the tree to find the correct location to insert id. // Returns whether a new hash value was added. func (node *treeNode) recursiveAdd(level int, id int, tableKey hashTableKey) bool { @@ -136,6 +151,12 @@ func NewLshForest(dim, l, m int, w float64) *LshForest { } } +func (index *LshForest) Delete() { + for _, tree := range index.trees { + (*tree.root).recursiveDelete() + } +} + // Insert adds a new data point to the LSH Forest. // id is the unique identifier for the data point. func (index *LshForest) Insert(point Point, id int) {