Documentation ¶
Index ¶
Constants ¶
View Source
const ( OPTION_ID = "id" OPTION_BUCKET_COUNT = "bucketCount" OPTION_MAX_BUCKET_SIZE = "maxBucketSize" OPTION_RAND_BYTES_READER = "randBytesReader" )
View Source
const ( BUCKET_COUNT = 256 MAX_BUCKET_SIZE = 8 )
View Source
const (
BYTE_WIDTH = 8
)
Variables ¶
View Source
var ( ErrIDNotInBucket = fmt.Errorf("id not in bucket") ErrOutOfBucketSize = fmt.Errorf("out of bucket size") )
View Source
var ( WithID = func(v ID) option.ApplyOption { return func(o option.Option) { o[OPTION_ID] = v } } GetID = func(o option.Option) (ID, error) { var x ID i := o.Get(OPTION_ID).Inter() if i == nil { return x, option.ErrOptionRequiredFn(OPTION_ID) } v, ok := i.(ID) if !ok { return x, option.ErrUnexpectedTypeFn(x, i) } return v, nil } WithBucketCount, GetBucketCount = option.New[int](OPTION_BUCKET_COUNT) WithMaxBucketSize, GetMaxBucketSize = option.New[int](OPTION_MAX_BUCKET_SIZE) WithRandBytesReader = func(rd io.Reader) option.ApplyOption { return func(o option.Option) { o[OPTION_RAND_BYTES_READER] = rd } } GetRandBytesReader = func(o option.Option) (io.Reader, error) { var x io.Reader i := o.Get(OPTION_RAND_BYTES_READER).Inter() if i == nil { return x, option.ErrOptionRequiredFn(OPTION_RAND_BYTES_READER) } v, ok := i.(io.Reader) if !ok { return x, option.ErrUnexpectedTypeFn(x, i) } return v, nil } )
Functions ¶
func NewComparableBucket ¶
func NewComparableBucket(x ID, b bucket) *comparableBucket
Types ¶
type RoutingTable ¶
type RoutingTable interface { LocalID() ID TableSize() int BucketSize(cpl int) int CommonPrefixLen(x ID) int GenRandIDWithCpl(cpl int) ID AddID(x ID) error RemoveID(x ID) error CloserIDs(x ID, count int, excludes []ID) (ys []ID, found bool) ClosestIDs(x ID, count int) (ys []ID, found bool) }
func NewRoutingTable ¶
func NewRoutingTable(opts ...option.ApplyOption) (RoutingTable, error)
Click to show internal directories.
Click to hide internal directories.