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

Golang gotype.Compare函数代码示例

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

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



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

示例1: delet

//  delete the key-value pair with the given key rooted at h
func (st *RedBlackBST) delet(h *RBNode, key interface{}) *RBNode {
	if gotype.Compare(key, h.key) < 0 {
		if !st.isRed(h.left) && !st.isRed(h.left.left) {
			h = st.moveRedLeft(h)
		}
		h.left = st.delet(h.left, key)
	} else {
		if st.isRed(h.left) {
			h = st.rotateRight(h)
		}
		if gotype.Compare(key, h.key) == 0 && h.right == nil {
			return nil
		}
		if !st.isRed(h.right) && !st.isRed(h.right.left) {
			h = st.moveRedRight(h)
		}
		if gotype.Compare(key, h.key) == 0 {
			x := st.min(h.right)
			h.key = x.key
			h.val = x.val
			h.right = st.deleteMin(h.right)
		} else {
			h.right = st.delet(h.right, key)
		}
	}
	return st.balance(h)
}
开发者ID:samuelyao314,项目名称:mygo,代码行数:28,代码来源:RedBlackBST.go


示例2: sink

func (self *MaxPQ) sink(k int) {
	for 2*k <= self.n {
		j := 2 * k
		if j < self.n && gotype.Compare(self.pq[j], self.pq[j+1]) < 0 {
			j++
		}
		if gotype.Compare(self.pq[k], self.pq[j]) >= 0 {
			break
		}
		self.pq[k], self.pq[j] = self.pq[j], self.pq[k]
		k = j
	}
}
开发者ID:samuelyao314,项目名称:mygo,代码行数:13,代码来源:Maxpq.go


示例3: put

//  insert the key-value pair in the subtree rooted at h
func (st *RedBlackBST) put(h *RBNode, key interface{}, val interface{}) *RBNode {
	if h == nil {
		return NewRBNode(key, val, RED)
	}
	cmp := gotype.Compare(key, h.key)
	if cmp < 0 {
		h.left = st.put(h.left, key, val)
	} else if cmp > 0 {
		h.right = st.put(h.right, key, val)
	} else {
		h.val = val
	}
	// fix-up any right-leaning links
	if st.isRed(h.right) && !st.isRed(h.left) {
		h = st.rotateLeft(h)
	}
	if st.isRed(h.left) && st.isRed(h.left.left) {
		h = st.rotateRight(h)
	}
	if st.isRed(h.left) && st.isRed(h.right) {
		st.flipColors(h)
	}
	h.n = st.size(h.left) + st.size(h.right) + 1
	return h
}
开发者ID:samuelyao314,项目名称:mygo,代码行数:26,代码来源:RedBlackBST.go


示例4: Get

//  return the value associated with the key, or null if the key is not present
func (st *SequentialSearchST) Get(key interface{}) interface{} {
	for x := st.first; x != nil; x = x.next {
		if cmp := gotype.Compare(key, x.key); cmp == 0 {
			return x.val
		}
	}
	return nil
}
开发者ID:samuelyao314,项目名称:mygo,代码行数:9,代码来源:SequentialSearchST.go


示例5: Floor

func (st *BinarySearchST) Floor(key interface{}) interface{} {
	i := st.Rank(key)
	if i < st.n && gotype.Compare(key, st.keys[i]) == 0 {
		return st.keys[i]
	}
	if i == 0 {
		return nil
	}
	return st.keys[i-1]
}
开发者ID:samuelyao314,项目名称:mygo,代码行数:10,代码来源:BinarySearchST.go


示例6: RangeSize

// Range search
func (st *BST) RangeSize(lo interface{}, hi interface{}) int {
	if gotype.Compare(lo, hi) > 0 {
		return 0
	}
	if st.Contains(hi) {
		return st.Rank(hi) - st.Rank(lo) + 1
	} else {
		return st.Rank(hi) - st.Rank(lo)
	}
}
开发者ID:samuelyao314,项目名称:mygo,代码行数:11,代码来源:BST.go


示例7: Get

func (st *BinarySearchST) Get(key interface{}) interface{} {
	if st.IsEmpty() {
		return nil
	}
	i := st.Rank(key)
	if i < st.n && gotype.Compare(st.keys[i], key) == 0 {
		return st.vals[i]
	}
	return nil
}
开发者ID:samuelyao314,项目名称:mygo,代码行数:10,代码来源:BinarySearchST.go


示例8: Put

// add a key-value pair, replacing old key-value pair if key is already present
func (st *SequentialSearchST) Put(key interface{}, val interface{}) {
	for x := st.first; x != nil; x = x.next {
		if cmp := gotype.Compare(key, x.key); cmp == 0 {
			x.val = val
			return
		}
	}
	st.first = &STNode{key, val, st.first}
	st.n++
}
开发者ID:samuelyao314,项目名称:mygo,代码行数:11,代码来源:SequentialSearchST.go


示例9: delete

func (st *SequentialSearchST) delete(x *STNode, key interface{}) *STNode {
	if x == nil {
		return nil
	}
	if cmp := gotype.Compare(key, x.key); cmp == 0 {
		st.n--
		return x.next
	}
	x.next = st.delete(x.next, key)
	return x
}
开发者ID:samuelyao314,项目名称:mygo,代码行数:11,代码来源:SequentialSearchST.go


示例10: get

func (st *BST) get(x *BstNode, key interface{}) interface{} {
	if x == nil {
		return nil
	}
	cmp := gotype.Compare(key, x.key)
	if cmp < 0 {
		return st.get(x.left, key)
	} else if cmp > 0 {
		return st.get(x.right, key)
	}
	return x.val
}
开发者ID:samuelyao314,项目名称:mygo,代码行数:12,代码来源:BST.go


示例11: RangeKeys

// Range search
func (st *BST) RangeKeys(lo interface{}, hi interface{}) []interface{} {
	queue := make([]interface{}, 0)
	var keys func(*BstNode, interface{}, interface{})
	keys = func(x *BstNode, lo interface{}, hi interface{}) {
		if x == nil {
			return
		}
		cmplo := gotype.Compare(lo, x.key)
		cmphi := gotype.Compare(hi, x.key)
		if cmplo < 0 {
			keys(x.left, lo, hi)
		}
		if cmplo <= 0 && cmphi >= 0 {
			queue = append(queue, x.key)
		}
		if cmphi > 0 {
			keys(x.right, lo, hi)
		}
	}
	keys(st.root, lo, hi)
	return queue
}
开发者ID:samuelyao314,项目名称:mygo,代码行数:23,代码来源:BST.go


示例12: rank

//  Number of keys in the subtree less than x.key.
func (st *BST) rank(key interface{}, x *BstNode) int {
	if x == nil {
		return 0
	}
	cmp := gotype.Compare(key, x.key)
	if cmp < 0 {
		return st.rank(key, x.left)
	} else if cmp > 0 {
		return 1 + st.size(x.left) + st.rank(key, x.right)
	} else {
		return st.size(x.left)
	}
}
开发者ID:samuelyao314,项目名称:mygo,代码行数:14,代码来源:BST.go


示例13: get

// value associated with the given key in subtree rooted at x; null if no such key
func (st *RedBlackBST) get(x *RBNode, key interface{}) interface{} {
	var cmp int
	for x != nil {
		cmp = gotype.Compare(key, x.key)
		if cmp < 0 {
			x = x.left
		} else if cmp > 0 {
			x = x.right
		} else {
			return x.val
		}
	}
	return nil
}
开发者ID:samuelyao314,项目名称:mygo,代码行数:15,代码来源:RedBlackBST.go


示例14: put

func (st *BST) put(x *BstNode, key interface{}, val interface{}) *BstNode {
	if x == nil {
		return NewBstNode(key, val)
	}
	cmp := gotype.Compare(key, x.key)
	if cmp < 0 {
		x.left = st.put(x.left, key, val)
	} else if cmp > 0 {
		x.right = st.put(x.right, key, val)
	} else {
		x.val = val
	}
	x.n = 1 + st.size(x.left) + st.size(x.right)
	return x
}
开发者ID:samuelyao314,项目名称:mygo,代码行数:15,代码来源:BST.go


示例15: RangeKeys

func (st *BinarySearchST) RangeKeys(lo interface{}, hi interface{}) []interface{} {
	queue := make([]interface{}, 0, 100)
	if lo == nil || hi == nil {
		return nil
	}
	if gotype.Compare(lo, hi) > 0 {
		return nil
	}
	for i := st.Rank(lo); i < st.Rank(hi); i++ {
		queue = append(queue, st.keys[i])
	}
	if st.Contains(hi) {
		queue = append(queue, st.keys[st.Rank(hi)])
	}
	return queue
}
开发者ID:samuelyao314,项目名称:mygo,代码行数:16,代码来源:BinarySearchST.go


示例16: Rank

// return the number of keys in the table that are smaller than given key
func (st *BinarySearchST) Rank(key interface{}) int {
	var lo, hi, m, cmp int
	lo, hi = 0, st.n-1
	for lo <= hi { // <=, not <
		m = lo + (hi-lo)/2
		cmp = gotype.Compare(key, st.keys[m])
		if cmp < 0 {
			hi = m - 1
		} else if cmp > 0 {
			lo = m + 1
		} else {
			return m
		}
	}
	return lo
}
开发者ID:samuelyao314,项目名称:mygo,代码行数:17,代码来源:BinarySearchST.go


示例17: floor

func (st *BST) floor(x *BstNode, key interface{}) *BstNode {
	if x == nil {
		return nil
	}
	cmp := gotype.Compare(key, x.key)
	if cmp == 0 {
		return x
	}
	if cmp < 0 {
		return st.floor(x.left, key)
	}
	t := st.floor(x.right, key)
	if t != nil {
		return t
	}
	return x
}
开发者ID:samuelyao314,项目名称:mygo,代码行数:17,代码来源:BST.go


示例18: ceiling

//  the smallest key in the subtree rooted at x greater than or equal to the given key
func (st *RedBlackBST) ceiling(x *RBNode, key interface{}) *RBNode {
	if x == nil {
		return nil
	}
	cmp := gotype.Compare(key, x.key)
	if cmp == 0 {
		return x
	}
	if cmp > 0 {
		return st.ceiling(x.right, key)
	}
	t := st.ceiling(x.left, key)
	if t != nil {
		return t
	} else {
		return x
	}
}
开发者ID:samuelyao314,项目名称:mygo,代码行数:19,代码来源:RedBlackBST.go


示例19: ceiling

func (st *BST) ceiling(x *BstNode, key interface{}) *BstNode {
	if x == nil {
		return nil
	}
	cmp := gotype.Compare(key, x.key)
	if cmp == 0 {
		return x
	}
	if cmp < 0 {
		t := st.ceiling(x.left, key)
		if t != nil {
			return t
		} else {
			return x
		}
	}
	return st.ceiling(x.right, key)
}
开发者ID:samuelyao314,项目名称:mygo,代码行数:18,代码来源:BST.go


示例20: Delete

// Remove the key-value pair if present
func (st *BinarySearchST) Delete(key interface{}) {
	if st.IsEmpty() {
		return
	}
	i := st.Rank(key)
	if i == st.n || gotype.Compare(key, st.keys[i]) != 0 {
		return
	}
	for j := i; j < st.n-1; j++ {
		st.keys[j] = st.keys[j+1]
		st.vals[j] = st.vals[j+1]
	}
	st.n--
	st.keys[st.n], st.vals[st.n] = nil, nil

	// resize if 1/4 full
	if st.n > 0 && st.n == len(st.keys)/4 {
		st.resize(len(st.keys) / 2)
	}
}
开发者ID:samuelyao314,项目名称:mygo,代码行数:21,代码来源:BinarySearchST.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang wk.Data函数代码示例发布时间:2022-05-28
下一篇:
Golang Hbase.Text函数代码示例发布时间: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