func (nh *Neighborhood) Add(toAdd peer.PeerDistance) bool {
	nh.mu.Lock()
	defer nh.mu.Unlock()
	if len(nh.neighbors) >= nh.size {
		return false
	}
	nh.neighbors = append(nh.neighbors, toAdd)
	return true
}
Add tries to add a new peer with distance to the neighborhood.
It returns true, if the peer was added, or false if the neighborhood was full.
package selection
import (
	"fmt"
	"sync"
	"github.com/iotaledger/hive.go/autopeering/distance"
	"github.com/iotaledger/hive.go/autopeering/peer"
	"github.com/iotaledger/hive.go/identity"
)
type Neighborhood struct {
	neighbors []peer.PeerDistance
	size      int
	mu        sync.RWMutex
}
func NewNeighborhood(size int) *Neighborhood {
	return &Neighborhood{
		neighbors: []peer.PeerDistance{},
		size:      size,
	}
}
func (nh *Neighborhood) String() string {
	return fmt.Sprintf("%d/%d", nh.GetNumPeers(), nh.size)
}
func (nh *Neighborhood) getFurthest() (peer.PeerDistance, int) {
	nh.mu.RLock()
	defer nh.mu.RUnlock()
	if len(nh.neighbors) < nh.size {
		return peer.PeerDistance{
			Remote:   nil,
			Distance: distance.Max,
		}, len(nh.neighbors)
	}
	index := 0
	furthest := nh.neighbors[index]
	for i, n := range nh.neighbors {
		if n.Distance > furthest.Distance {
			furthest = n
			index = i
		}
	}
	return furthest, index
}
func (nh *Neighborhood) Select(candidates []peer.PeerDistance) peer.PeerDistance {
	if len(candidates) > 0 {
		target, _ := nh.getFurthest()
		for _, candidate := range candidates {
			if candidate.Distance < target.Distance {
				return candidate
			}
		}
	}
	return peer.PeerDistance{}
}