• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang errors.BpTreeError函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/timtadh/data-structures/errors.BpTreeError函数的典型用法代码示例。如果您正苦于以下问题:Golang BpTreeError函数的具体用法?Golang BpTreeError怎么用?Golang BpTreeError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了BpTreeError函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: put_value_at

func (self *BpNode) put_value_at(i int, value interface{}) error {
	if len(self.values) == cap(self.values) {
		return errors.BpTreeError("Block is full.")
	}
	if self.Internal() {
		return errors.BpTreeError("Expected a leaf node")
	}
	self.values = self.values[:len(self.values)+1]
	for j := len(self.values) - 1; j > i; j-- {
		self.values[j] = self.values[j-1]
	}
	self.values[i] = value
	return nil
}
开发者ID:roger2000hk,项目名称:data-structures,代码行数:14,代码来源:bptree_node.go


示例2: put_pointer_at

func (self *BpNode) put_pointer_at(i int, pointer *BpNode) error {
	if len(self.pointers) == cap(self.pointers) {
		return errors.BpTreeError("Block is full.")
	}
	if !self.Internal() {
		return errors.BpTreeError("Expected a internal node")
	}
	self.pointers = self.pointers[:len(self.pointers)+1]
	for j := len(self.pointers) - 1; j > i; j-- {
		self.pointers[j] = self.pointers[j-1]
	}
	self.pointers[i] = pointer
	return nil
}
开发者ID:roger2000hk,项目名称:data-structures,代码行数:14,代码来源:bptree_node.go


示例3: leaf_remove

func (self *BpNode) leaf_remove(key, stop types.Sortable, where types.WhereFunc) (a *BpNode, err error) {
	if self.Internal() {
		return nil, errors.BpTreeError("Expected a leaf node")
	}
	a = self
	for j, l, next := self.forward(key, key)(); next != nil; j, l, next = next() {
		if where(l.values[j]) {
			if err := l.remove_key_at(j); err != nil {
				return nil, err
			}
			if err := l.remove_value_at(j); err != nil {
				return nil, err
			}
		}
		if len(l.keys) == 0 {
			remove_linked_list_node(l)
			if l.next == nil {
				a = nil
			} else if stop == nil {
				a = nil
			} else if !l.next.keys[0].Equals(stop) {
				a = l.next
			} else {
				a = nil
			}
		}
	}
	return a, nil
}
开发者ID:roger2000hk,项目名称:data-structures,代码行数:29,代码来源:bptree_node.go


示例4: pure_leaf_split

/* a pure leaf split has two cases:
 *  1) the inserted key is less than the current pure block.
 *     - a new block should be created before the current block
 *     - the key should be put in it
 *  2) the inserted key is greater than or equal to the pure block.
 *     - the end of run of pure blocks should be found
 *     - if the key is equal to pure block and the last block is not full insert
 *       the new kv
 *     - else split by making a new block after the last block in the run
 *       and putting the new key there.
 *     - always return the current block as "a" and the new block as "b"
 */
func (self *BpNode) pure_leaf_split(key types.Sortable, value interface{}) (a, b *BpNode, err error) {
	if self.Internal() || !self.Pure() {
		return nil, nil, errors.BpTreeError("Expected a pure leaf node")
	}
	if key.Less(self.keys[0]) {
		a = NewLeaf(self.NodeSize(), self.no_dup)
		b = self
		if err := a.put_kv(key, value); err != nil {
			return nil, nil, err
		}
		insert_linked_list_node(a, b.prev, b)
		return a, b, nil
	} else {
		a = self
		e := self.find_end_of_pure_run()
		if e.keys[0].Equals(key) && !e.Full() {
			if err := e.put_kv(key, value); err != nil {
				return nil, nil, err
			}
			return a, nil, nil
		} else {
			b = NewLeaf(self.NodeSize(), self.no_dup)
			if err := b.put_kv(key, value); err != nil {
				return nil, nil, err
			}
			insert_linked_list_node(b, e, e.next)
			if e.keys[0].Equals(key) {
				return a, nil, nil
			}
			return a, b, nil
		}
	}
}
开发者ID:roger2000hk,项目名称:data-structures,代码行数:45,代码来源:bptree_node.go


示例5: internal_insert

/* - first find the child to insert into
 * - do the child insert
 * - if there was a split:
 *    - if the block is full, split this block
 *    - else insert the new key/pointer into this block
 */
func (self *BpNode) internal_insert(key types.Sortable, value interface{}) (a, b *BpNode, err error) {
	if !self.Internal() {
		return nil, nil, errors.BpTreeError("Expected a internal node")
	}
	i, has := self.find(key)
	if !has && i > 0 {
		// if it doesn't have it and the index > 0 then we have the next block
		// so we have to subtract one from the index.
		i--
	}
	child := self.pointers[i]
	p, q, err := child.insert(key, value)
	if err != nil {
		return nil, nil, err
	}
	self.keys[i] = p.keys[0]
	self.pointers[i] = p
	if q != nil {
		// we had a split
		if self.Full() {
			return self.internal_split(q.keys[0], q)
		} else {
			if err := self.put_kp(q.keys[0], q); err != nil {
				return nil, nil, err
			}
			return self, nil, nil
		}
	}
	return self, nil, nil
}
开发者ID:roger2000hk,项目名称:data-structures,代码行数:36,代码来源:bptree_node.go


示例6: Height

func (self *BpNode) Height() int {
	if !self.Internal() {
		return 1
	} else if len(self.pointers) == 0 {
		panic(errors.BpTreeError("Internal node has no pointers but asked for height"))
	}
	return self.pointers[0].Height() + 1
}
开发者ID:roger2000hk,项目名称:data-structures,代码行数:8,代码来源:bptree_node.go


示例7: remove_key_at

func (self *BpNode) remove_key_at(i int) error {
	if i >= len(self.keys) || i < 0 {
		return errors.BpTreeError("i, %v, is out of bounds, %v, %v %v.", i, len(self.keys), len(self.values), self)
	}
	for j := i; j < len(self.keys)-1; j++ {
		self.keys[j] = self.keys[j+1]
	}
	self.keys = self.keys[:len(self.keys)-1]
	return nil
}
开发者ID:roger2000hk,项目名称:data-structures,代码行数:10,代码来源:bptree_node.go


示例8: remove_ptr_at

func (self *BpNode) remove_ptr_at(i int) error {
	if i >= len(self.pointers) || i < 0 {
		return errors.BpTreeError("i, %v, is out of bounds, %v.", i, len(self.pointers))
	}
	for j := i; j < len(self.pointers)-1; j++ {
		self.pointers[j] = self.pointers[j+1]
	}
	self.pointers = self.pointers[:len(self.pointers)-1]
	return nil
}
开发者ID:roger2000hk,项目名称:data-structures,代码行数:10,代码来源:bptree_node.go


示例9: balance_nodes

/* a must be full and b must be empty else there will be a panic
 */
func balance_nodes(a, b *BpNode) {
	if len(b.keys) != 0 {
		panic(errors.BpTreeError("b was not empty"))
	}
	if !a.Full() {
		panic(errors.BpTreeError("a was not full", a))
	}
	if cap(a.keys) != cap(b.keys) {
		panic(errors.BpTreeError("cap(a.keys) != cap(b.keys)"))
	}
	if cap(a.values) != cap(b.values) {
		panic(errors.BpTreeError("cap(a.values) != cap(b.values)"))
	}
	if cap(a.pointers) != cap(b.pointers) {
		panic(errors.BpTreeError("cap(a.pointers) != cap(b.pointers)"))
	}
	m := len(a.keys) / 2
	for m < len(a.keys) && a.keys[m-1].Equals(a.keys[m]) {
		m++
	}
	if m == len(a.keys) {
		m--
		for m > 0 && a.keys[m-1].Equals(a.keys[m]) {
			m--
		}
	}
	var lim int = len(a.keys) - m
	b.keys = b.keys[:lim]
	if cap(a.values) > 0 {
		if cap(a.values) != cap(a.keys) {
			panic(errors.BpTreeError("cap(a.values) != cap(a.keys)"))
		}
		b.values = b.values[:lim]
	}
	if cap(a.pointers) > 0 {
		if cap(a.pointers) != cap(a.keys) {
			panic(errors.BpTreeError("cap(a.pointers) != cap(a.keys)"))
		}
		b.pointers = b.pointers[:lim]
	}
	for i := 0; i < lim; i++ {
		j := m + i
		b.keys[i] = a.keys[j]
		if cap(a.values) > 0 {
			b.values[i] = a.values[j]
		}
		if cap(a.pointers) > 0 {
			b.pointers[i] = a.pointers[j]
		}
	}
	a.keys = a.keys[:m]
	if cap(a.values) > 0 {
		a.values = a.values[:m]
	}
	if cap(a.pointers) > 0 {
		a.pointers = a.pointers[:m]
	}
}
开发者ID:jmptrader,项目名称:data-structures,代码行数:60,代码来源:bptree_node.go


示例10: put_key_at

func (self *BpNode) put_key_at(i int, key types.Sortable) error {
	if self.Full() {
		return errors.BpTreeError("Block is full.")
	}
	self.keys = self.keys[:len(self.keys)+1]
	for j := len(self.keys) - 1; j > i; j-- {
		self.keys[j] = self.keys[j-1]
	}
	self.keys[i] = key
	return nil
}
开发者ID:roger2000hk,项目名称:data-structures,代码行数:11,代码来源:bptree_node.go


示例11: put_kv

func (self *BpNode) put_kv(key types.Sortable, value interface{}) error {
	if self.Full() {
		return errors.BpTreeError("Block is full.")
	}
	if self.Internal() {
		return errors.BpTreeError("Expected a leaf node")
	}
	i, _ := self.find(key)
	if i < 0 {
		panic(errors.BpTreeError("find returned a negative int"))
	} else if i >= cap(self.keys) {
		panic(errors.BpTreeError("find returned a int > than cap(keys)"))
	}
	if err := self.put_key_at(i, key); err != nil {
		return err
	}
	if err := self.put_value_at(i, value); err != nil {
		return err
	}
	return nil
}
开发者ID:roger2000hk,项目名称:data-structures,代码行数:21,代码来源:bptree_node.go


示例12: internal_split

/* On split
 * - first assert that the key to be inserted is not already in the block.
 * - Make a new block
 * - balance the two blocks.
 * - insert the new key/pointer combo into the correct block
 */
func (self *BpNode) internal_split(key types.Sortable, ptr *BpNode) (a, b *BpNode, err error) {
	if !self.Internal() {
		return nil, nil, errors.BpTreeError("Expected a internal node")
	}
	if self.has(key) {
		return nil, nil, errors.BpTreeError("Tried to split an internal block on duplicate key")
	}
	a = self
	b = NewInternal(self.NodeSize())
	balance_nodes(a, b)
	if key.Less(b.keys[0]) {
		if err := a.put_kp(key, ptr); err != nil {
			return nil, nil, err
		}
	} else {
		if err := b.put_kp(key, ptr); err != nil {
			return nil, nil, err
		}
	}
	return a, b, nil
}
开发者ID:roger2000hk,项目名称:data-structures,代码行数:27,代码来源:bptree_node.go


示例13: insert_linked_list_node

func insert_linked_list_node(n, prev, next *BpNode) {
	if (prev != nil && prev.next != next) || (next != nil && next.prev != prev) {
		panic(errors.BpTreeError("prev and next not hooked up"))
	}
	n.prev = prev
	n.next = next
	if prev != nil {
		prev.next = n
	}
	if next != nil {
		next.prev = n
	}
}
开发者ID:roger2000hk,项目名称:data-structures,代码行数:13,代码来源:bptree_node.go


示例14: internal_get_start

func (self *BpNode) internal_get_start(key types.Sortable) (i int, leaf *BpNode) {
	if !self.Internal() {
		panic(errors.BpTreeError("Expected a internal node"))
	}
	i, has := self.find(key)
	if !has && i > 0 {
		// if it doesn't have it and the index > 0 then we have the next block
		// so we have to subtract one from the index.
		i--
	}
	child := self.pointers[i]
	return child.get_start(key)
}
开发者ID:roger2000hk,项目名称:data-structures,代码行数:13,代码来源:bptree_node.go


示例15: put_kp

func (self *BpNode) put_kp(key types.Sortable, ptr *BpNode) error {
	if self.Full() {
		return errors.BpTreeError("Block is full.")
	}
	if !self.Internal() {
		return errors.BpTreeError("Expected a internal node")
	}
	i, has := self.find(key)
	if has {
		return errors.BpTreeError("Tried to insert a duplicate key into an internal node")
	} else if i < 0 {
		panic(errors.BpTreeError("find returned a negative int"))
	} else if i >= cap(self.keys) {
		panic(errors.BpTreeError("find returned a int > than cap(keys)"))
	}
	if err := self.put_key_at(i, key); err != nil {
		return err
	}
	if err := self.put_pointer_at(i, ptr); err != nil {
		return err
	}
	return nil
}
开发者ID:roger2000hk,项目名称:data-structures,代码行数:23,代码来源:bptree_node.go


示例16: internal_remove

func (self *BpNode) internal_remove(key types.Sortable, sibling *BpNode, where types.WhereFunc) (a *BpNode, err error) {
	if !self.Internal() {
		panic(errors.BpTreeError("Expected a internal node"))
	}
	i, has := self.find(key)
	if !has && i > 0 {
		// if it doesn't have it and the index > 0 then we have the next block
		// so we have to subtract one from the index.
		i--
	}
	if i+1 < len(self.keys) {
		sibling = self.pointers[i+1]
	} else if sibling != nil {
		sibling = sibling.left_most_leaf()
	}
	child := self.pointers[i]
	if child.Internal() {
		child, err = child.internal_remove(key, sibling, where)
	} else {
		if sibling == nil {
			child, err = child.leaf_remove(key, nil, where)
		} else {
			child, err = child.leaf_remove(key, sibling.keys[0], where)
		}
	}
	if err != nil {
		return nil, err
	}
	if child == nil {
		if err := self.remove_key_at(i); err != nil {
			return nil, err
		}
		if err := self.remove_ptr_at(i); err != nil {
			return nil, err
		}
	} else {
		self.keys[i] = child.keys[0]
		self.pointers[i] = child
	}
	if len(self.keys) == 0 {
		return nil, nil
	}
	return self, nil
}
开发者ID:roger2000hk,项目名称:data-structures,代码行数:44,代码来源:bptree_node.go


示例17: leaf_insert

/* if the leaf is full then it will defer to a leaf_split
 *    (but in one case that will not actually split in the case of a insert into
 *    a pure block with a matching key)
 * else this leaf will get a new entry.
 */
func (self *BpNode) leaf_insert(key types.Sortable, value interface{}) (a, b *BpNode, err error) {
	if self.Internal() {
		return nil, nil, errors.BpTreeError("Expected a leaf node")
	}
	if self.no_dup {
		i, has := self.find(key)
		if has {
			self.values[i] = value
			return self, nil, nil
		}
	}
	if self.Full() {
		return self.leaf_split(key, value)
	} else {
		if err := self.put_kv(key, value); err != nil {
			return nil, nil, err
		}
		return self, nil, nil
	}
}
开发者ID:roger2000hk,项目名称:data-structures,代码行数:25,代码来源:bptree_node.go


示例18: leaf_split

/* on leaf split if the block is pure then it will defer to pure_leaf_split
 * else
 *    - a new block will be made and inserted after this one
 *    - the two blocks will be balanced with balanced_nodes
 *    - if the key is less than b.keys[0] it will go in a else b
 */
func (self *BpNode) leaf_split(key types.Sortable, value interface{}) (a, b *BpNode, err error) {
	if self.Internal() {
		return nil, nil, errors.BpTreeError("Expected a leaf node")
	}
	if self.Pure() {
		return self.pure_leaf_split(key, value)
	}
	a = self
	b = NewLeaf(self.NodeSize(), self.no_dup)
	insert_linked_list_node(b, a, a.next)
	balance_nodes(a, b)
	if key.Less(b.keys[0]) {
		if err := a.put_kv(key, value); err != nil {
			return nil, nil, err
		}
	} else {
		if err := b.put_kv(key, value); err != nil {
			return nil, nil, err
		}
	}
	return a, b, nil
}
开发者ID:roger2000hk,项目名称:data-structures,代码行数:28,代码来源:bptree_node.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang errors.Errorf函数代码示例发布时间:2022-05-28
下一篇:
Golang types.NewName函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap