示例#1
0
文件: messages.go 项目: cmars/conflux
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
}
示例#2
0
文件: ptree.go 项目: cmars/conflux
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
}