退回最简单的优先链表
This commit is contained in:
parent
0403bebea4
commit
05bcac44ef
|
@ -72,84 +72,32 @@ func (pq *PriorityQueue) Push(v interface{}) {
|
|||
|
||||
node := new(Node)
|
||||
node.value = v
|
||||
pq.size++
|
||||
|
||||
if pq.node == nil {
|
||||
//创建索引
|
||||
index := new(Index)
|
||||
index.nlen = 1
|
||||
index.node = node
|
||||
|
||||
pq.index = index
|
||||
pq.node = node
|
||||
|
||||
return
|
||||
}
|
||||
// find the node of index to start
|
||||
idx := pq.index
|
||||
|
||||
for {
|
||||
|
||||
if idx.next == nil {
|
||||
break
|
||||
}
|
||||
|
||||
if pq.comparator(v, idx.next.node.value) > 0 {
|
||||
break
|
||||
}
|
||||
|
||||
idx = idx.next
|
||||
}
|
||||
|
||||
cur := idx.node
|
||||
cur := pq.node
|
||||
|
||||
//cur := pq.node
|
||||
if pq.comparator(v, pq.node.value) > 0 {
|
||||
pq.node = node
|
||||
node.next = cur
|
||||
|
||||
pq.index.node = pq.node
|
||||
pq.index.nlen++
|
||||
|
||||
// cur.prev = node
|
||||
return
|
||||
}
|
||||
|
||||
for i := 0; cur.next != nil; i++ {
|
||||
|
||||
if i >= pq.indexlimit {
|
||||
|
||||
if idx.next != nil && idx.next.nlen < pq.indexlimit {
|
||||
idx.next.nlen += idx.nlen - pq.indexlimit
|
||||
idx.nlen = pq.indexlimit
|
||||
idx.next.node = cur
|
||||
} else {
|
||||
index := new(Index)
|
||||
index.node = cur
|
||||
index.nlen = idx.nlen - pq.indexlimit
|
||||
index.next = idx.next
|
||||
|
||||
idx.next = index
|
||||
idx.nlen = pq.indexlimit
|
||||
idx = index
|
||||
i = 0
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if pq.comparator(v, cur.next.value) > 0 {
|
||||
temp := cur.next
|
||||
cur.next = node
|
||||
node.next = temp
|
||||
// node.prev = cur
|
||||
// temp.prev = node
|
||||
|
||||
idx.nlen++
|
||||
|
||||
// if pq.index.nlen >= pq.indexlimit {
|
||||
// // 分裂
|
||||
|
||||
// }
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -160,8 +108,6 @@ func (pq *PriorityQueue) Push(v interface{}) {
|
|||
cur.next = node
|
||||
|
||||
// node.prev = cur
|
||||
pq.size++
|
||||
idx.nlen++
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user