func (sl *NeighborList) Len() uint32 {
	var length uint32
	sl.nodes.Range(func(key, value interface{}) bool {
		length++
		return true
	})
	return length
}
Len returns the number of remote nodes stored in NeighborList
package chord
import (
	"errors"
	"fmt"
	"math/big"
	"math/rand"
	"sort"
	"sync"
	"github.com/nknorg/nnet/log"
	"github.com/nknorg/nnet/node"
	"github.com/nknorg/nnet/protobuf"
)
const (
	randomQueryProbability = 0.5
)
type NeighborList struct {
	startID         []byte
	endID           []byte
	reversed        bool
	nodeIDBits      uint32
	maxNumNodes     uint32
	maxNumNodesLock sync.RWMutex
	nodes           sync.Map
}
func NewNeighborList(startID, endID []byte, nodeIDBits, maxNumNodes uint32, reversed bool) (*NeighborList, error) {
	if uint32(len(startID)) > nodeIDBits || uint32(len(endID)) > nodeIDBits {
		return nil, fmt.Errorf("key has more than %d bits", nodeIDBits)
	}
	sl := &NeighborList{
		startID:     startID,
		endID:       endID,
		nodeIDBits:  nodeIDBits,
		maxNumNodes: maxNumNodes,
		reversed:    reversed,
	}
	return sl, nil
}
func (sl *NeighborList) cmp(node1, node2 *protobuf.Node) int {
	res := Distance(sl.startID, node1.Id, sl.nodeIDBits).Cmp(Distance(sl.startID, node2.Id, sl.nodeIDBits))
	if sl.reversed {
		return -res
	}
	return res
}
func (sl *NeighborList) IsIDInRange(id []byte) bool {
	if sl.reversed {
		return BetweenIncl(sl.endID, sl.startID, id)
	}
	return BetweenIncl(sl.startID, sl.endID, id)
}
func (sl *NeighborList) IsEmpty() bool {
	isEmpty := true
	sl.nodes.Range(func(key, value interface{}) bool {
		isEmpty = false
		return false
	})
	return isEmpty
}