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