package plist

import (
	"474420502.top/eson/structure"
)

type NodeList struct {
	head, tail *Node
}

// Node 节点结构
type Node struct {
	prev, next *Node
	structure.NValue
}

// PriorityList 跳表
type PriorityList struct {
	size    int
	compare func(v1, v2 interface{}) int
	level   *LevelNode
}

type LevelSize struct {
	size int
}

// LevelNode 层级列表
type LevelNode struct {
	head  *LevelNode
	tail  *LevelNode
	sub   interface{}
	lsize *LevelSize
	level int
}

// New a node
func New() *PriorityList {
	p := new(PriorityList)
	p.level = new(LevelNode)
	p.level.lsize = new(LevelSize)

	node := new(Node)
	p.level.sub = node

	return p
}

// String 展示需要的
func (pl *PriorityList) String() string {

	content := ""

	return content
}

// InsertValues 插入值
func (pl *PriorityList) InsertValues(values ...interface{}) {

	ll := pl.level

	for _, value := range values {
		node := new(Node)
		node.IValue = value

		if ll.level == 0 {

			if ll.sub == nil {
				ll.sub = node
				continue
			}

			cur := ll.sub.(*Node)
			cur.
		}

		if level.tail == nil {
			level.head.lsize
			node.prev = level.head
			level.tail = node
			continue
		}

		cur := level.head
		for cur != nil {

			if pl.compare(cur, node) < 0 {

				if cur.sub != nil {
					cur = cur.sub
					continue
				} else {
					temp := cur.next
					cur.next = node
					if temp != nil {
						node.next = temp
						temp.prev = node
					}
					pl.size++
					break
				}

			} else {

			}

			cur = cur.next
		}
	}
}

// Get 获取索引长度
// func (pl *PriorityList) Get(idx int) INode {

// 	if idx >= pl.size {
// 		return nil
// 	}
// 	cur := pl.head
// 	for i := 0; i < idx; i++ {
// 		cur = cur.GetNext()
// 	}
// 	return cur
// }

// Size 长度
func (pl *PriorityList) Size() int {
	return pl.size
}

// Clear 清空链表, 如果外部有引用其中一个节点 要把节点Prev Next值为nil, 三色标记
func (pl *PriorityList) Clear() {
	pl.level = nil
	pl.size = 0
}