func (s *SkipList) SeekToFirst() Iterator {
	if s.length == 0 {
		return nil
	}
	current := s.header.next()
	return &iter{
		current: current,
		key:     current.key,
		list:    s,
		value:   current.value,
	}
}
SeekToFirst returns a bidirectional iterator starting from the first element
in the list if the list is populated; otherwise, a nil iterator is returned.
package skiplist
import (
	"math/rand"
)
const p = 0.25
const DefaultMaxLevel = 32
type node struct {
	forward    []*node
	backward   *node
	key, value interface{}
}
func (n *node) next() *node {
	if len(n.forward) == 0 {
		return nil
	}
	return n.forward[0]
}
func (n *node) previous() *node {
	return n.backward
}
func (n *node) hasNext() bool {
	return n.next() != nil
}
func (n *node) hasPrevious() bool {
	return n.previous() != nil
}
type SkipList struct {
	lessThan func(l, r interface{}) bool
	header   *node
	footer   *node
	length   int
	MaxLevel int
}
func (s *SkipList) Len() int {
	return s.length
}
type Iterator interface {
	Next() (ok bool)
	Previous() (ok bool)
	Key() interface{}
	Value() interface{}
	Seek(key interface{}) (ok bool)
	Close()
}
type iter struct {
	current *node
	key     interface{}
	list    *SkipList
	value   interface{}
}
func (i iter) Key() interface{} {
	return i.key
}
func (i iter) Value() interface{} {
	return i.value
}
func (i *iter) Next() bool {
	if !i.current.hasNext() {
		return false
	}
	i.current = i.current.next()
	i.key = i.current.key
	i.value = i.current.value
	return true
}
func (i *iter) Previous() bool {
	if !i.current.hasPrevious() {
		return false
	}
	i.current = i.current.previous()
	i.key = i.current.key
	i.value = i.current.value
	return true
}
func (i *iter) Seek(key interface{}) (ok bool) {
	current := i.current
	list := i.list
	if current == nil {
		current = list.header
	}
	if current.key != nil && list.lessThan(key, current.key) {
		current = list.header
	}
	if current.backward == nil {
		current = list.header
	} else {
		current = current.backward
	}
	current = list.getPath(current, nil, key)
	if current == nil {
		return
	}
	i.current = current
	i.key = current.key
	i.value = current.value
	return true
}
func (i *iter) Close() {
	i.key = nil
	i.value = nil
	i.current = nil
	i.list = nil
}
type rangeIterator struct {
	iter
	upperLimit interface{}
	lowerLimit interface{}
}
func (i *rangeIterator) Next() bool {
	if !i.current.hasNext() {
		return false
	}
	next := i.current.next()
	if !i.list.lessThan(next.key, i.upperLimit) {
		return false
	}
	i.current = i.current.next()
	i.key = i.current.key
	i.value = i.current.value
	return true
}
func (i *rangeIterator) Previous() bool {
	if !i.current.hasPrevious() {
		return false
	}
	previous := i.current.previous()
	if i.list.lessThan(previous.key, i.lowerLimit) {
		return false
	}
	i.current = i.current.previous()
	i.key = i.current.key
	i.value = i.current.value
	return true
}
func (i *rangeIterator) Seek(key interface{}) (ok bool) {
	if i.list.lessThan(key, i.lowerLimit) {
		return
	} else if !i.list.lessThan(key, i.upperLimit) {
		return
	}
	return i.iter.Seek(key)
}
func (i *rangeIterator) Close() {
	i.iter.Close()
	i.upperLimit = nil
	i.lowerLimit = nil
}
func (s *SkipList) Iterator() Iterator {
	return &iter{
		current: s.header,
		list:    s,
	}
}
func (s *SkipList) Seek(key interface{}) Iterator {
	current := s.getPath(s.header, nil, key)
	if current == nil {
		return nil
	}
	return &iter{
		current: current,
		key:     current.key,
		list:    s,
		value:   current.value,
	}
}