func (it *Iterator) Set(val []byte, meta uint16) error {
	new, err := it.list.allocVal(val, meta)
	if err != nil {
		return err
	}
	return it.trySetValue(new)
}
Set updates the value of the current iteration record if it has not been
updated or deleted since iterating or seeking to it. If the record has been
updated, then Set positions the iterator on the most current value and
returns ErrRecordUpdated. If the record has been deleted, then Set keeps
the iterator positioned on the current record with the current value and
returns ErrRecordDeleted.
package arenaskl
import (
	"runtime"
	"sync/atomic"
	"unsafe"
)
type splice struct {
	prev *node
	next *node
}
func (s *splice) init(prev, next *node) {
	s.prev = prev
	s.next = next
}
type Iterator struct {
	list  *Skiplist
	arena *Arena
	nd    *node
	value uint64
}
func (it *Iterator) Init(list *Skiplist) {
	it.list = list
	it.arena = list.arena
	it.nd = nil
	it.value = 0
}
func (it *Iterator) Valid() bool { return it.nd != nil }
func (it *Iterator) Key() []byte {
	return it.nd.getKey(it.arena)
}
func (it *Iterator) Value() []byte {
	valOffset, valSize := decodeValue(it.value)
	return it.arena.GetBytes(valOffset, uint32(valSize))
}
func (it *Iterator) Meta() uint16 {
	return decodeMeta(it.value)
}
func (it *Iterator) Next() {
	next := it.list.getNext(it.nd, 0)
	it.setNode(next, false)
}
func (it *Iterator) Prev() {
	prev := it.list.getPrev(it.nd, 0)
	it.setNode(prev, true)
}
func (it *Iterator) Seek(key []byte) (found bool) {
	var next *node
	_, next, found = it.seekForBaseSplice(key)
	present := it.setNode(next, false)
	return found && present
}
func (it *Iterator) SeekForPrev(key []byte) (found bool) {
	var prev, next *node
	prev, next, found = it.seekForBaseSplice(key)
	var present bool
	if found {
		present = it.setNode(next, true)
	} else {
		present = it.setNode(prev, true)
	}
	return found && present
}
func (it *Iterator) Add(key []byte, val []byte, meta uint16) error {
	var spl [maxHeight]splice
	if it.seekForSplice(key, &spl) {
		return it.setValueIfDeleted(spl[0].next, val, meta)
	}
	if it.list.testing {
		runtime.Gosched()
	}
	nd, height, err := it.list.newNode(key, val, meta)
	if err != nil {
		return err
	}
	value := nd.value
	ndOffset := it.arena.GetPointerOffset(unsafe.Pointer(nd))
	var found bool
	for i := 0; i < int(height); i++ {
		prev := spl[i].prev
		next := spl[i].next
		if prev == nil {
			if next != nil {
				panic("next is expected to be nil, since prev is nil")
			}
			prev = it.list.head
			next = it.list.tail
		}
		for {
			prevOffset := it.arena.GetPointerOffset(unsafe.Pointer(prev))
			nextOffset := it.arena.GetPointerOffset(unsafe.Pointer(next))
			nd.tower[i].init(prevOffset, nextOffset)
			nextPrevOffset := next.prevOffset(i)
			if nextPrevOffset != prevOffset {
				prevNextOffset := prev.nextOffset(i)
				if prevNextOffset == nextOffset {
					next.casPrevOffset(i, nextPrevOffset, prevOffset)
				}
			}
			if prev.casNextOffset(i, nextOffset, ndOffset) {
				if it.list.testing {
					runtime.Gosched()
				}
				next.casPrevOffset(i, prevOffset, ndOffset)
				break
			}
			prev, next, found = it.list.findSpliceForLevel(key, i, prev)
			if found {
				if i != 0 {
					panic("how can another thread have inserted a node at a non-base level?")
				}
				return it.setValueIfDeleted(next, val, meta)
			}
		}
	}
	it.value = value
	it.nd = nd
	return nil
}