Esempio n. 1
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
}
Esempio n. 2
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
}