func (s *Float64Set) findNodeRemove(value float64, preds *[maxLevel]*float64Node, succs *[maxLevel]*float64Node) int {
	lFound, x := -1, s.header
	for i := int(atomic.LoadInt64(&s.highestLevel)) - 1; i >= 0; i-- {
		succ := x.atomicLoadNext(i)
		for succ != nil && succ.lessthan(value) {
			x = succ
			succ = x.atomicLoadNext(i)
		}
		preds[i] = x
		succs[i] = succ
		if lFound == -1 && succ != nil && succ.equal(value) {
			lFound = i
		}
	}
	return lFound
}
findNodeRemove takes a value and two maximal-height arrays then searches exactly as in a sequential skip-list.
The returned preds and succs always satisfy preds[i] > value >= succs[i].
package skipset
import (
	"sync"
	"sync/atomic"
	"unsafe"
)
type Float32Set struct {
	header       *float32Node
	length       int64
	highestLevel int64  
}
type float32Node struct {
	value float32
	next  optionalArray  
	mu    sync.Mutex
	flags bitflag
	level uint32
}
func newFloat32Node(value float32, level int) *float32Node {
	node := &float32Node{
		value: value,
		level: uint32(level),
	}
	if level > op1 {
		node.next.extra = new([op2]unsafe.Pointer)
	}
	return node
}
func (n *float32Node) loadNext(i int) *float32Node {
	return (*float32Node)(n.next.load(i))
}
func (n *float32Node) storeNext(i int, node *float32Node) {
	n.next.store(i, unsafe.Pointer(node))
}
func (n *float32Node) atomicLoadNext(i int) *float32Node {
	return (*float32Node)(n.next.atomicLoad(i))
}
func (n *float32Node) atomicStoreNext(i int, node *float32Node) {
	n.next.atomicStore(i, unsafe.Pointer(node))
}
func (n *float32Node) lessthan(value float32) bool {
	return n.value < value
}
func (n *float32Node) equal(value float32) bool {
	return n.value == value
}
func NewFloat32() *Float32Set {
	h := newFloat32Node(0, maxLevel)
	h.flags.SetTrue(fullyLinked)
	return &Float32Set{
		header:       h,
		highestLevel: defaultHighestLevel,
	}
}
func (s *Float32Set) findNodeRemove(value float32, preds *[maxLevel]*float32Node, succs *[maxLevel]*float32Node) int {
	lFound, x := -1, s.header
	for i := int(atomic.LoadInt64(&s.highestLevel)) - 1; i >= 0; i-- {
		succ := x.atomicLoadNext(i)
		for succ != nil && succ.lessthan(value) {
			x = succ
			succ = x.atomicLoadNext(i)
		}
		preds[i] = x
		succs[i] = succ
		if lFound == -1 && succ != nil && succ.equal(value) {
			lFound = i
		}
	}
	return lFound
}
func (s *Float32Set) findNodeAdd(value float32, preds *[maxLevel]*float32Node, succs *[maxLevel]*float32Node) int {
	x := s.header
	for i := int(atomic.LoadInt64(&s.highestLevel)) - 1; i >= 0; i-- {
		succ := x.atomicLoadNext(i)
		for succ != nil && succ.lessthan(value) {
			x = succ
			succ = x.atomicLoadNext(i)
		}
		preds[i] = x
		succs[i] = succ
		if succ != nil && succ.equal(value) {
			return i
		}
	}
	return -1
}
func unlockFloat32(preds [maxLevel]*float32Node, highestLevel int) {
	var prevPred *float32Node
	for i := highestLevel; i >= 0; i-- {
		if preds[i] != prevPred {  
			preds[i].mu.Unlock()
			prevPred = preds[i]
		}
	}
}
func (s *Float32Set) Add(value float32) bool {
	level := s.randomlevel()
	var preds, succs [maxLevel]*float32Node
	for {
		lFound := s.findNodeAdd(value, &preds, &succs)
		if lFound != -1 {  
			nodeFound := succs[lFound]
			if !nodeFound.flags.Get(marked) {
				for !nodeFound.flags.Get(fullyLinked) {
				}
				return false
			}
			continue
		}
		var (
			highestLocked        = -1  
			valid                = true
			pred, succ, prevPred *float32Node
		)
		for layer := 0; valid && layer < level; layer++ {
			pred = preds[layer]    
			succ = succs[layer]    
			if pred != prevPred {  
				pred.mu.Lock()
				highestLocked = layer
				prevPred = pred
			}
			valid = !pred.flags.Get(marked) && (succ == nil || !succ.flags.Get(marked)) && pred.loadNext(layer) == succ
		}
		if !valid {
			unlockFloat32(preds, highestLocked)
			continue
		}
		nn := newFloat32Node(value, level)
		for layer := 0; layer < level; layer++ {
			nn.storeNext(layer, succs[layer])
			preds[layer].atomicStoreNext(layer, nn)
		}
		nn.flags.SetTrue(fullyLinked)
		unlockFloat32(preds, highestLocked)
		atomic.AddInt64(&s.length, 1)
		return true
	}
}
func (s *Float32Set) randomlevel() int {
	level := randomLevel()
	for {
		hl := atomic.LoadInt64(&s.highestLevel)
		if int64(level) <= hl {
			break
		}
		if atomic.CompareAndSwapInt64(&s.highestLevel, hl, int64(level)) {
			break
		}
	}
	return level
}
func (s *Float32Set) Contains(value float32) bool {
	x := s.header
	for i := int(atomic.LoadInt64(&s.highestLevel)) - 1; i >= 0; i-- {
		nex := x.atomicLoadNext(i)
		for nex != nil && nex.lessthan(value) {
			x = nex
			nex = x.atomicLoadNext(i)
		}
		if nex != nil && nex.equal(value) {
			return nex.flags.MGet(fullyLinked|marked, fullyLinked)
		}
	}
	return false
}
func (s *Float32Set) Remove(value float32) bool {
	var (
		nodeToRemove *float32Node
		isMarked     bool  
		topLayer     = -1
		preds, succs [maxLevel]*float32Node
	)
	for {
		lFound := s.findNodeRemove(value, &preds, &succs)
		if isMarked ||  
			lFound != -1 && succs[lFound].flags.MGet(fullyLinked|marked, fullyLinked) && (int(succs[lFound].level)-1) == lFound {
			if !isMarked {  
				nodeToRemove = succs[lFound]
				topLayer = lFound
				nodeToRemove.mu.Lock()
				if nodeToRemove.flags.Get(marked) {
					nodeToRemove.mu.Unlock()
					return false
				}
				nodeToRemove.flags.SetTrue(marked)
				isMarked = true
			}
			var (
				highestLocked        = -1  
				valid                = true
				pred, succ, prevPred *float32Node
			)
			for layer := 0; valid && (layer <= topLayer); layer++ {
				pred, succ = preds[layer], succs[layer]
				if pred != prevPred {  
					pred.mu.Lock()
					highestLocked = layer
					prevPred = pred
				}
				valid = !pred.flags.Get(marked) && pred.loadNext(layer) == succ
			}
			if !valid {
				unlockFloat32(preds, highestLocked)
				continue
			}
			for i := topLayer; i >= 0; i-- {
				preds[i].atomicStoreNext(i, nodeToRemove.loadNext(i))
			}
			nodeToRemove.mu.Unlock()
			unlockFloat32(preds, highestLocked)
			atomic.AddInt64(&s.length, -1)
			return true
		}
		return false
	}
}
func (s *Float32Set) Range(f func(value float32) bool) {
	x := s.header.atomicLoadNext(0)
	for x != nil {
		if !x.flags.MGet(fullyLinked|marked, fullyLinked) {
			x = x.atomicLoadNext(0)
			continue
		}
		if !f(x.value) {
			break
		}
		x = x.atomicLoadNext(0)
	}
}
func (s *Float32Set) Len() int {
	return int(atomic.LoadInt64(&s.length))
}
type Float32SetDesc struct {
	header       *float32NodeDesc
	length       int64
	highestLevel int64  
}
type float32NodeDesc struct {
	value float32
	next  optionalArray  
	mu    sync.Mutex
	flags bitflag
	level uint32
}
func newFloat32NodeDesc(value float32, level int) *float32NodeDesc {
	node := &float32NodeDesc{
		value: value,
		level: uint32(level),
	}
	if level > op1 {
		node.next.extra = new([op2]unsafe.Pointer)
	}
	return node
}
func (n *float32NodeDesc) loadNext(i int) *float32NodeDesc {
	return (*float32NodeDesc)(n.next.load(i))
}
func (n *float32NodeDesc) storeNext(i int, node *float32NodeDesc) {
	n.next.store(i, unsafe.Pointer(node))
}
func (n *float32NodeDesc) atomicLoadNext(i int) *float32NodeDesc {
	return (*float32NodeDesc)(n.next.atomicLoad(i))
}
func (n *float32NodeDesc) atomicStoreNext(i int, node *float32NodeDesc) {
	n.next.atomicStore(i, unsafe.Pointer(node))
}
func (n *float32NodeDesc) lessthan(value float32) bool {
	return n.value > value
}
func (n *float32NodeDesc) equal(value float32) bool {
	return n.value == value
}
func NewFloat32Desc() *Float32SetDesc {
	h := newFloat32NodeDesc(0, maxLevel)
	h.flags.SetTrue(fullyLinked)
	return &Float32SetDesc{
		header:       h,
		highestLevel: defaultHighestLevel,
	}
}
func (s *Float32SetDesc) findNodeRemove(value float32, preds *[maxLevel]*float32NodeDesc, succs *[maxLevel]*float32NodeDesc) int {
	lFound, x := -1, s.header
	for i := int(atomic.LoadInt64(&s.highestLevel)) - 1; i >= 0; i-- {
		succ := x.atomicLoadNext(i)
		for succ != nil && succ.lessthan(value) {
			x = succ
			succ = x.atomicLoadNext(i)
		}
		preds[i] = x
		succs[i] = succ
		if lFound == -1 && succ != nil && succ.equal(value) {
			lFound = i
		}
	}
	return lFound
}
func (s *Float32SetDesc) findNodeAdd(value float32, preds *[maxLevel]*float32NodeDesc, succs *[maxLevel]*float32NodeDesc) int {
	x := s.header
	for i := int(atomic.LoadInt64(&s.highestLevel)) - 1; i >= 0; i-- {
		succ := x.atomicLoadNext(i)
		for succ != nil && succ.lessthan(value) {
			x = succ
			succ = x.atomicLoadNext(i)
		}
		preds[i] = x
		succs[i] = succ
		if succ != nil && succ.equal(value) {
			return i
		}
	}
	return -1
}
func unlockFloat32Desc(preds [maxLevel]*float32NodeDesc, highestLevel int) {
	var prevPred *float32NodeDesc
	for i := highestLevel; i >= 0; i-- {
		if preds[i] != prevPred {  
			preds[i].mu.Unlock()
			prevPred = preds[i]
		}
	}
}
func (s *Float32SetDesc) Add(value float32) bool {
	level := s.randomlevel()
	var preds, succs [maxLevel]*float32NodeDesc
	for {
		lFound := s.findNodeAdd(value, &preds, &succs)
		if lFound != -1 {  
			nodeFound := succs[lFound]
			if !nodeFound.flags.Get(marked) {
				for !nodeFound.flags.Get(fullyLinked) {
				}
				return false
			}
			continue
		}
		var (
			highestLocked        = -1  
			valid                = true
			pred, succ, prevPred *float32NodeDesc
		)
		for layer := 0; valid && layer < level; layer++ {
			pred = preds[layer]    
			succ = succs[layer]    
			if pred != prevPred {  
				pred.mu.Lock()
				highestLocked = layer
				prevPred = pred
			}
			valid = !pred.flags.Get(marked) && (succ == nil || !succ.flags.Get(marked)) && pred.loadNext(layer) == succ
		}
		if !valid {
			unlockFloat32Desc(preds, highestLocked)
			continue
		}
		nn := newFloat32NodeDesc(value, level)
		for layer := 0; layer < level; layer++ {
			nn.storeNext(layer, succs[layer])
			preds[layer].atomicStoreNext(layer, nn)
		}
		nn.flags.SetTrue(fullyLinked)
		unlockFloat32Desc(preds, highestLocked)
		atomic.AddInt64(&s.length, 1)
		return true
	}
}
func (s *Float32SetDesc) randomlevel() int {
	level := randomLevel()
	for {
		hl := atomic.LoadInt64(&s.highestLevel)
		if int64(level) <= hl {
			break
		}
		if atomic.CompareAndSwapInt64(&s.highestLevel, hl, int64(level)) {
			break
		}
	}
	return level
}
func (s *Float32SetDesc) Contains(value float32) bool {
	x := s.header
	for i := int(atomic.LoadInt64(&s.highestLevel)) - 1; i >= 0; i-- {
		nex := x.atomicLoadNext(i)
		for nex != nil && nex.lessthan(value) {
			x = nex
			nex = x.atomicLoadNext(i)
		}
		if nex != nil && nex.equal(value) {
			return nex.flags.MGet(fullyLinked|marked, fullyLinked)
		}
	}
	return false
}
func (s *Float32SetDesc) Remove(value float32) bool {
	var (
		nodeToRemove *float32NodeDesc
		isMarked     bool  
		topLayer     = -1
		preds, succs [maxLevel]*float32NodeDesc
	)
	for {
		lFound := s.findNodeRemove(value, &preds, &succs)
		if isMarked ||  
			lFound != -1 && succs[lFound].flags.MGet(fullyLinked|marked, fullyLinked) && (int(succs[lFound].level)-1) == lFound {
			if !isMarked {  
				nodeToRemove = succs[lFound]
				topLayer = lFound
				nodeToRemove.mu.Lock()
				if nodeToRemove.flags.Get(marked) {
					nodeToRemove.mu.Unlock()
					return false
				}
				nodeToRemove.flags.SetTrue(marked)
				isMarked = true
			}
			var (
				highestLocked        = -1  
				valid                = true
				pred, succ, prevPred *float32NodeDesc
			)
			for layer := 0; valid && (layer <= topLayer); layer++ {
				pred, succ = preds[layer], succs[layer]
				if pred != prevPred {  
					pred.mu.Lock()
					highestLocked = layer
					prevPred = pred
				}
				valid = !pred.flags.Get(marked) && pred.loadNext(layer) == succ
			}
			if !valid {
				unlockFloat32Desc(preds, highestLocked)
				continue
			}
			for i := topLayer; i >= 0; i-- {
				preds[i].atomicStoreNext(i, nodeToRemove.loadNext(i))
			}
			nodeToRemove.mu.Unlock()
			unlockFloat32Desc(preds, highestLocked)
			atomic.AddInt64(&s.length, -1)
			return true
		}
		return false
	}
}
func (s *Float32SetDesc) Range(f func(value float32) bool) {
	x := s.header.atomicLoadNext(0)
	for x != nil {
		if !x.flags.MGet(fullyLinked|marked, fullyLinked) {
			x = x.atomicLoadNext(0)
			continue
		}
		if !f(x.value) {
			break
		}
		x = x.atomicLoadNext(0)
	}
}
func (s *Float32SetDesc) Len() int {
	return int(atomic.LoadInt64(&s.length))
}
type Float64Set struct {
	header       *float64Node
	length       int64
	highestLevel int64  
}
type float64Node struct {
	value float64
	next  optionalArray  
	mu    sync.Mutex
	flags bitflag
	level uint32
}
func newFloat64Node(value float64, level int) *float64Node {
	node := &float64Node{
		value: value,
		level: uint32(level),
	}
	if level > op1 {
		node.next.extra = new([op2]unsafe.Pointer)
	}
	return node
}
func (n *float64Node) loadNext(i int) *float64Node {
	return (*float64Node)(n.next.load(i))
}
func (n *float64Node) storeNext(i int, node *float64Node) {
	n.next.store(i, unsafe.Pointer(node))
}
func (n *float64Node) atomicLoadNext(i int) *float64Node {
	return (*float64Node)(n.next.atomicLoad(i))
}
func (n *float64Node) atomicStoreNext(i int, node *float64Node) {
	n.next.atomicStore(i, unsafe.Pointer(node))
}
func (n *float64Node) lessthan(value float64) bool {
	return n.value < value
}
func (n *float64Node) equal(value float64) bool {
	return n.value == value
}
func NewFloat64() *Float64Set {
	h := newFloat64Node(0, maxLevel)
	h.flags.SetTrue(fullyLinked)
	return &Float64Set{
		header:       h,
		highestLevel: defaultHighestLevel,
	}
}