当前位置: 首页>>代码示例>>Golang>>正文


Golang tree.Key类代码示例

本文整理汇总了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)
}
开发者ID:taysom,项目名称:va,代码行数:9,代码来源:merge.go

示例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)
}
开发者ID:taysom,项目名称:va,代码行数:9,代码来源:bplus.go

示例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
}
开发者ID:taysom,项目名称:va,代码行数:11,代码来源:bsearch.go

示例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}
}
开发者ID:taysom,项目名称:va,代码行数:13,代码来源:merge.go

示例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
}
开发者ID:taysom,项目名称:va,代码行数:13,代码来源:binary.go

示例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)
}
开发者ID:taysom,项目名称:va,代码行数:15,代码来源:merge.go

示例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
}
开发者ID:taysom,项目名称:va,代码行数:15,代码来源:bsearch.go

示例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
}
开发者ID:taysom,项目名称:va,代码行数:21,代码来源:binary.go

示例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)
}
开发者ID:taysom,项目名称:va,代码行数:23,代码来源:bplus.go

示例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
		}
	}
}
开发者ID:taysom,项目名称:va,代码行数:24,代码来源:binary.go


注:本文中的tree.Key类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。