本文整理汇总了Golang中tree.Key类的典型用法代码示例。如果您正苦于以下问题:Golang Key类的具体用法?Golang Key怎么用?Golang Key使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Key类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Find
func (b *Branch) Find(key tree.Key) (interface{}, bool) {
i := 0
for ; i < b.numKeys; i++ {
if key.Less(b.key[i]) {
break
}
}
return b.twig[i].Find(key)
}
示例2: Delete
func (b *Branch) Delete(key tree.Key) {
i := 0
for ; i < b.numKeys; i++ {
if key.Less(b.key[i]) {
break
}
}
b.twig[i].Delete(key)
}
示例3: Check
func (t *Tree) Check(key tree.Key) tree.Key {
var next tree.Key
for _, r := range t.rec {
next = r.Key
if next.Less(key) {
log.Fatal("keys out of order")
}
key = next
}
return key
}
示例4: Insert
func (l *Leaf) Insert(key tree.Key, value interface{}) {
var i int
for i = 0; i < l.numKeys; i++ {
if key.Less(l.record[i].Key) {
for j := l.numKeys; j > i; j-- {
l.record[j] = l.record[j-1]
}
break
}
}
l.numKeys++
l.record[i] = tree.Record{key, value}
}
示例5: Find
func (t *Tree) Find(key tree.Key) (interface{}, bool) {
for node := t.root; node != nil; {
switch {
case node.rec.Key.Less(key):
node = node.right
case key.Less(node.rec.Key):
node = node.left
default:
return node.rec.Value, true
}
}
return nil, false
}
示例6: Succ
func (b *Branch) Succ(key tree.Key) (tree.Record, bool) {
i := 0
for ; i < b.numKeys; i++ {
if key.Less(b.key[i]) {
break
}
}
for ; i < b.numKeys; i++ {
rec, found := b.twig[i].Succ(key)
if found {
return rec, found
}
}
return b.twig[i].Succ(key)
}
示例7: bsearch
func (t *Tree) bsearch(key tree.Key) (int, bool) {
left := 0
right := len(t.rec) - 1
for left <= right {
middle := (left + right) / 2
if key.Less(t.rec[middle].Key) {
right = middle - 1
} else if key == t.rec[middle].Key {
return middle, true
} else {
left = middle + 1
}
}
return left, false
}
示例8: Succ
func (t *Tree) Succ(key tree.Key) (tree.Record, bool) {
var next *Node
for node := t.root; node != nil; {
if node.rec.Key.Less(key) {
node = node.right
} else if key.Less(node.rec.Key) {
next = node
node = node.left
} else {
if node.right != nil {
for next = node.right; next.left != nil; next = next.left {
}
}
break
}
}
if next == nil {
return tree.Record{}, false
}
return next.rec, true
}
示例9: Insert
func (b *Branch) Insert(key tree.Key, value interface{}) {
var i int
for i = 0; i < b.numKeys; i++ {
if key.Less(b.key[i]) {
break
}
}
twig := b.twig[i]
if twig.isFull() {
sibling, newKey := twig.split()
for j := b.numKeys; j > i; j-- {
b.key[j] = b.key[j-1]
b.twig[j+1] = b.twig[j] // One more twig than keys
}
b.key[i] = newKey
b.twig[i+1] = sibling
b.numKeys++
if newKey.Less(key) {
twig = sibling
}
}
twig.Insert(key, value)
}
示例10: Delete
func (t *Tree) Delete(key tree.Key) {
np := &t.root
for node := t.root; node != nil; node = *np {
switch {
case node.rec.Key.Less(key):
np = &node.right
case key.Less(node.rec.Key):
np = &node.left
default:
switch {
case node.left == nil:
*np = node.right
case node.right == nil:
*np = node.left
default:
replacement := delRight(&node.left)
replacement.left = node.left
replacement.right = node.right
*np = replacement
}
return
}
}
}