TODO: level find

This commit is contained in:
huangsimin 2019-01-27 18:42:08 +08:00
parent 741a685e16
commit ad18004bc2

View File

@ -27,8 +27,9 @@ type LevelSize struct {
// LevelNode 层级列表
type LevelNode struct {
head *LevelNode
tail *LevelNode
node *Node
prev *LevelNode
next *LevelNode
sub interface{}
lsize *LevelSize
level int
@ -39,9 +40,14 @@ func New() *PriorityList {
p := new(PriorityList)
p.level = new(LevelNode)
p.level.lsize = new(LevelSize)
p.level.lsize.size = 1
lnode := new(LevelNode)
lnode.lsize = new(LevelSize)
p.level.sub = lnode
node := new(Node)
p.level.sub = node
lnode.sub = node
return p
}
@ -57,12 +63,22 @@ func (pl *PriorityList) String() string {
// InsertValues 插入值
func (pl *PriorityList) InsertValues(values ...interface{}) {
ll := pl.level
for _, value := range values {
node := new(Node)
node.IValue = value
ll := pl.level
// 寻找 适合的level
for ll.level != 0 {
if pl.compare(node, ll.node) > 0 {
temp := ll.prev
}
}
// 找到数据后
if ll.level == 0 {
if ll.sub == nil {
@ -71,40 +87,37 @@ func (pl *PriorityList) InsertValues(values ...interface{}) {
}
cur := ll.sub.(*Node)
cur.
}
if level.tail == nil {
level.head.lsize
node.prev = level.head
level.tail = node
continue
}
isTail := false
cur := level.head
for cur != nil {
for i := 0; i < ll.lsize.size; i++ {
if pl.compare(node, cur) > 0 {
if pl.compare(cur, node) < 0 {
if cur.sub != nil {
cur = cur.sub
continue
} else {
temp := cur.next
cur.next = node
temp := cur.prev
cur.prev = node
if temp != nil {
node.next = temp
temp.prev = node
node.prev = temp
temp.next = node
}
ll.lsize.size++
pl.size++
break
isTail = true
}
} else {
cur = cur.next
}
if isTail {
temp := cur.next
cur.next = node
if temp != nil {
node.next = temp
temp.prev = node
}
ll.lsize.size++
pl.size++
}
cur = cur.next
}
}
}