Example #1
0
func NextChild(n PrefixNode, bs *cf.Bitstring, depth int) int {
	if n.IsLeaf() {
		panic("Cannot dereference child of leaf node")
	}
	childIndex := 0
	nbq := n.Config().BitQuantum
	for i := 0; i < nbq; i++ {
		mask := 1 << uint(i)
		if bs.Get(depth*nbq+i) == 1 {
			childIndex |= mask
		}
	}
	return childIndex
}
Example #2
0
func (t *prefixTree) Node(bs *cf.Bitstring) (node recon.PrefixNode, err error) {
	nbq := t.BitQuantum
	key := bs
	nodeKey := mustEncodeBitstring(key)
	for {
		node, err = t.getNode(nodeKey)
		if err != recon.ErrNodeNotFound || key.BitLen() == 0 {
			break
		}
		key = cf.NewBitstring(key.BitLen() - nbq)
		key.SetBytes(bs.Bytes())
		nodeKey = mustEncodeBitstring(key)
	}
	return node, err
}
Example #3
0
func (t *MemPrefixTree) Node(bs *cf.Bitstring) (PrefixNode, error) {
	node := t.root
	nbq := t.BitQuantum
	for i := 0; i < bs.BitLen() && !node.IsLeaf(); i += nbq {
		childIndex := 0
		for j := 0; j < nbq; j++ {
			mask := 1 << uint(j)
			if bs.Get(i+j) == 1 {
				childIndex |= mask
			}
		}
		node = node.children[childIndex]
	}
	return node, nil
}
Example #4
0
func (t *prefixTree) newChildNode(parent *prefixNode, childIndex int) *prefixNode {
	n := &prefixNode{prefixTree: t, Leaf: true}
	var key *cf.Bitstring
	if parent != nil {
		parentKey := parent.Key()
		key = cf.NewBitstring(parentKey.BitLen() + t.BitQuantum)
		key.SetBytes(parentKey.Bytes())
		for j := 0; j < parent.BitQuantum; j++ {
			if (1<<uint(j))&childIndex == 0 {
				key.Clear(parentKey.BitLen() + j)
			} else {
				key.Set(parentKey.BitLen() + j)
			}
		}
	} else {
		key = cf.NewBitstring(0)
	}
	n.NodeKey = mustEncodeBitstring(key)
	svalues := make([]*cf.Zp, t.NumSamples())
	for i := 0; i < len(svalues); i++ {
		svalues[i] = cf.Zi(cf.P_SKS, 1)
	}
	n.NodeSValues = mustEncodeZZarray(svalues)
	return n
}
Example #5
0
func WriteBitstring(w io.Writer, bs *cf.Bitstring) (err error) {
	err = WriteInt(w, bs.BitLen())
	if err != nil {
		return
	}
	err = WriteInt(w, len(bs.Bytes()))
	if err != nil {
		return
	}
	_, err = w.Write(bs.Bytes())
	return
}