mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-01-07 19:31:51 +08:00
[skip ci] Fix golint in indexcoord/priority_queue.go (#8848)
Signed-off-by: cai.zhang <cai.zhang@zilliz.com>
This commit is contained in:
parent
5c239cf15a
commit
0b6f792a69
@ -87,8 +87,8 @@ type IndexCoord struct {
|
||||
closeCallbacks []func()
|
||||
}
|
||||
|
||||
// UniqueID is an alias of int64, is used as a unique identifier for the request.
|
||||
type UniqueID = typeutil.UniqueID
|
||||
type Timestamp = typeutil.Timestamp
|
||||
|
||||
// NewIndexCoord creates a new IndexCoord component.
|
||||
func NewIndexCoord(ctx context.Context) (*IndexCoord, error) {
|
||||
|
||||
@ -16,7 +16,7 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// An Item is something we manage in a priority queue.
|
||||
// PQItem is something we manage in a priority queue.
|
||||
type PQItem struct {
|
||||
key UniqueID
|
||||
|
||||
@ -25,28 +25,32 @@ type PQItem struct {
|
||||
index int // The index of the item in the heap.
|
||||
}
|
||||
|
||||
// A PriorityQueue implements heap.Interface and holds Items.
|
||||
|
||||
// PriorityQueue implements heap.Interface and holds Items.
|
||||
type PriorityQueue struct {
|
||||
items []*PQItem
|
||||
lock sync.RWMutex
|
||||
}
|
||||
|
||||
// Len is the length of the priority queue.
|
||||
func (pq *PriorityQueue) Len() int {
|
||||
return len(pq.items)
|
||||
}
|
||||
|
||||
// Less reports whether the element with index i
|
||||
// must sort before the element with index j.
|
||||
func (pq *PriorityQueue) Less(i, j int) bool {
|
||||
// We want Pop to give us the highest, not lowest, priority so we use greater than here.
|
||||
return pq.items[i].priority < pq.items[j].priority
|
||||
}
|
||||
|
||||
// Swap swaps the elements with indexes i and j.
|
||||
func (pq *PriorityQueue) Swap(i, j int) {
|
||||
pq.items[i], pq.items[j] = pq.items[j], pq.items[i]
|
||||
pq.items[i].index = i
|
||||
pq.items[j].index = j
|
||||
}
|
||||
|
||||
// Push adds an element to the priority.
|
||||
func (pq *PriorityQueue) Push(x interface{}) {
|
||||
pq.lock.Lock()
|
||||
defer pq.lock.Unlock()
|
||||
@ -66,6 +70,7 @@ func (pq *PriorityQueue) Pop() interface{} {
|
||||
return item
|
||||
}
|
||||
|
||||
// CheckExist checks whether the nodeID is already in the priority.
|
||||
func (pq *PriorityQueue) CheckExist(nodeID UniqueID) bool {
|
||||
pq.lock.RLock()
|
||||
defer pq.lock.RUnlock()
|
||||
@ -111,6 +116,7 @@ func (pq *PriorityQueue) UpdatePriority(key UniqueID, priority int) {
|
||||
}
|
||||
}
|
||||
|
||||
// Remove deletes the corresponding item according to the key.
|
||||
func (pq *PriorityQueue) Remove(key UniqueID) {
|
||||
pq.lock.Lock()
|
||||
defer pq.lock.Unlock()
|
||||
@ -131,6 +137,7 @@ func (pq *PriorityQueue) Peek() UniqueID {
|
||||
return pq.items[0].key
|
||||
}
|
||||
|
||||
// PeekAll return the key of all the items.
|
||||
func (pq *PriorityQueue) PeekAll() []UniqueID {
|
||||
pq.lock.RLock()
|
||||
defer pq.lock.RUnlock()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user