Exemplo n.º 1
0
func (n *prefixNode) remove(z *cf.Zp, marray []*cf.Zp, bs *cf.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)
				children, err := n.Children()
				if err != nil {
					return err
				}
				n = children[childIndex].(*prefixNode)
				depth++
			}
		}
	}
	err = n.deleteElement(z)
	if err != nil {
		return err
	}
	return n.upsertNode()
}
Exemplo n.º 2
0
func (n *prefixNode) insert(z *cf.Zp, marray []*cf.Zp, bs *cf.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)
		children, err := n.Children()
		if err != nil {
			return err
		}
		n = children[childIndex].(*prefixNode)
		depth++
	}
}
Exemplo n.º 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 := cf.Zb(cf.P_SKS, element)
		bs := cf.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
}