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


Golang gotype.Compare函数代码示例

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


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


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