代码拉取完成,页面将自动刷新
package merkletrie
import (
"sort"
"strings"
)
// A node is a Noder implementation for testing purposes: It is easier
// to create test trees using nodes than using real git tree objects.
type node struct {
hash []byte
key string
children []*node
}
// newNode returns a new Node with the given hash, key and children
// (children can be specified in any order).
func newNode(hash []byte, key string, children []*node) *node {
sort.Sort(reverseAlphabeticallyByKey(children))
return &node{
hash: hash,
key: key,
children: children,
}
}
// Hash returns the hash of the node.
func (n *node) Hash() []byte {
return n.hash
}
// Key returns the key of the node.
func (n *node) Key() string {
return n.key
}
// NumChildren returns the number of children.
func (n *node) NumChildren() int {
return len(n.children)
}
// Children returns the node's children in reverse key alphabetical
// order.
func (n *node) Children() []Noder {
ret := make([]Noder, n.NumChildren())
for i := range n.children {
ret[i] = n.children[i]
}
return ret
}
type reverseAlphabeticallyByKey []*node
func (a reverseAlphabeticallyByKey) Len() int {
return len(a)
}
func (a reverseAlphabeticallyByKey) Swap(i, j int) {
a[i], a[j] = a[j], a[i]
}
func (a reverseAlphabeticallyByKey) Less(i, j int) bool {
return strings.Compare(a[i].key, a[j].key) > 0
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。