Beispiel #1
0
func ReadZp(r io.Reader) (*cf.Zp, error) {
	buf := make([]byte, SksZpNbytes)
	_, err := io.ReadFull(r, buf)
	if err != nil {
		return nil, err
	}
	z := cf.Zb(cf.P_SKS, buf)
	z.Norm()
	return z, nil
}
Beispiel #2
0
func (n *prefixNode) Elements() ([]*cf.Zp, error) {
	var result []*cf.Zp
	if n.IsLeaf() {
		for _, element := range n.NodeElements {
			result = append(result, cf.Zb(cf.P_SKS, element))
		}
	} else {
		children, err := n.Children()
		if err != nil {
			return nil, err
		}
		for _, child := range children {
			elements, err := child.Elements()
			if err != nil {
				return nil, err
			}
			result = append(result, elements...)
		}
	}
	return result, nil
}
Beispiel #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
}