Example #1
0
func (n *prefixNode) remove(z *Zp, marray []*Zp, bs *Bitstring, depth int) error {
	var err error
	for {
		n.updateSvalues(z, marray)
		n.NumElements--
		if n.IsLeaf() {
			break
		} else {
			if n.NumElements <= n.JoinThreshold() {
				err = n.join()
				if err != nil {
					return err
				}
				break
			} else {
				err = n.upsertNode()
				if err != nil {
					return err
				}
				childIndex := recon.NextChild(n, bs, depth)
				n = n.Children()[childIndex].(*prefixNode)
				depth++
			}
		}
	}
	err = n.deleteElement(z)
	if err != nil {
		return err
	}
	return n.upsertNode()
}
Example #2
0
func (n *prefixNode) insert(z *Zp, marray []*Zp, bs *Bitstring, depth int) error {
	for {
		n.updateSvalues(z, marray)
		n.NumElements++
		var err error
		if n.IsLeaf() {
			if len(n.NodeElements) > n.SplitThreshold() {
				err = n.split(depth)
				if err != nil {
					return err
				}
			} else {
				err = n.insertElement(z)
				if err != nil {
					return err
				}
				return n.upsertNode()
			}
		}
		err = n.upsertNode()
		if err != nil {
			return err
		}
		childIndex := recon.NextChild(n, bs, depth)
		n = n.Children()[childIndex].(*prefixNode)
		depth++
	}
}
Example #3
0
func (n *prefixNode) split(depth int) (err error) {
	splitElements := n.NodeElements
	n.Leaf = false
	n.NodeElements = nil
	err = n.upsertNode()
	if err != nil {
		return err
	}
	// Create child nodes
	numChildren := 1 << uint(n.BitQuantum())
	var children []*prefixNode
	for i := 0; i < numChildren; i++ {
		// Create new empty child node
		child := n.newChildNode(n, i)
		err = child.upsertNode()
		if err != nil {
			return err
		}
		children = append(children, child)
	}
	// Move elements into child nodes
	for _, element := range splitElements {
		z := Zb(P_SKS, element)
		bs := NewZpBitstring(z)
		childIndex := recon.NextChild(n, bs, depth)
		child := children[childIndex]
		marray, err := recon.AddElementArray(child, z)
		if err != nil {
			return err
		}
		err = child.insert(z, marray, bs, depth+1)
		if err != nil {
			return err
		}
	}
	return nil
}