Exemple #1
0
func Dump(prefix bitrie.Bits, balances bitrie.Bitrie, c comp.C) {
	if leaf, ok := balances.(*bitrie.BitrieLeaf); ok {
		c.Use(leaf)
		c.Use(leaf.Value)
		fmt.Printf("%v: %v\n", hex.EncodeToString(prefix.Cat(leaf.Bits).Bits), leaf.Value.(*OutpointInfo).Count)
	}

	if node, ok := balances.(*bitrie.BitrieNode); ok {
		c.Use(node)
		Dump(prefix.Cat(node.Bits).Append(0), node.Left, c)
		Dump(prefix.Cat(node.Bits).Append(1), node.Right, c)
	}
}
Exemple #2
0
func RandomKey(prefix bitrie.Bits, balances bitrie.Bitrie, c comp.C) bitrie.Bits {
	if leaf, ok := balances.(*bitrie.BitrieLeaf); ok {
		c.Use(leaf)
		return prefix.Cat(leaf.Bits)
	}

	if node, ok := balances.(*bitrie.BitrieNode); ok {
		c.Use(node)
		if rand.Intn(2) == 0 {
			return RandomKey(prefix.Cat(node.Bits).Append(0), node.Left, c)
		} else {
			return RandomKey(prefix.Cat(node.Bits).Append(1), node.Right, c)
		}
	}

	panic(balances)
}