Documentation ¶
Index ¶
- Constants
- Variables
- func AliaserAliasClashTest(require *require.Assertions, _ AliaserReader, w AliaserWriter)
- func AliaserAliasesEmptyTest(require *require.Assertions, r AliaserReader, _ AliaserWriter)
- func AliaserAliasesTest(require *require.Assertions, r AliaserReader, w AliaserWriter)
- func AliaserLookupErrorTest(require *require.Assertions, r AliaserReader, _ AliaserWriter)
- func AliaserLookupTest(require *require.Assertions, r AliaserReader, w AliaserWriter)
- func AliaserPrimaryAliasTest(require *require.Assertions, r AliaserReader, w AliaserWriter)
- func AliaserRemoveAliasTest(require *require.Assertions, r AliaserReader, w AliaserWriter)
- func EqualSubset(start, stop int, id1, id2 ID) bool
- func FirstDifferenceSubset(start, stop int, id1, id2 ID) (int, bool)
- func GetRelevantAliases(aliaser Aliaser, ids []ID) (map[ID][]string, error)
- func ShortIDsToStrings(ids []ShortID) []string
- type Aliaser
- type AliaserReader
- type AliaserWriter
- type Bag
- func (b *Bag) Add(ids ...ID)
- func (b *Bag) AddCount(id ID, count int)
- func (b *Bag) Count(id ID) int
- func (b *Bag) Equals(oIDs Bag) bool
- func (b *Bag) Filter(start, end int, id ID) Bag
- func (b *Bag) Len() int
- func (b *Bag) List() []ID
- func (b *Bag) Mode() (ID, int)
- func (b *Bag) PrefixedString(prefix string) string
- func (b *Bag) SetThreshold(threshold int)
- func (b *Bag) Split(index uint) [2]Bag
- func (b *Bag) String() string
- func (b *Bag) Threshold() set.Set[ID]
- type BigBitSet
- func (b BigBitSet) Add(i int)
- func (b BigBitSet) Clear()
- func (b BigBitSet) Contains(i int) bool
- func (b BigBitSet) Difference(other BigBitSet)
- func (b BigBitSet) HammingWeight() int
- func (b BigBitSet) Intersection(other BigBitSet)
- func (b BigBitSet) Len() int
- func (b BigBitSet) Remove(i int)
- func (b BigBitSet) String() string
- func (b BigBitSet) Union(other BigBitSet)
- type BitSet64
- func (bs *BitSet64) Add(i uint)
- func (bs *BitSet64) Clear()
- func (bs BitSet64) Contains(i uint) bool
- func (bs *BitSet64) Difference(s BitSet64)
- func (bs *BitSet64) Intersection(s BitSet64)
- func (bs BitSet64) Len() int
- func (bs *BitSet64) Remove(i uint)
- func (bs BitSet64) String() string
- func (bs *BitSet64) Union(s BitSet64)
- type ID
- func (id ID) Bit(i uint) int
- func (id ID) Hex() string
- func (id ID) Less(other ID) bool
- func (id ID) MarshalJSON() ([]byte, error)
- func (id ID) MarshalText() ([]byte, error)
- func (id ID) Prefix(prefixes ...uint64) ID
- func (id ID) String() string
- func (id *ID) UnmarshalJSON(b []byte) error
- func (id *ID) UnmarshalText(text []byte) error
- type NodeID
- type NodeIDBag
- func (b *NodeIDBag) Add(ids ...NodeID)
- func (b *NodeIDBag) AddCount(id NodeID, count int)
- func (b *NodeIDBag) Count(id NodeID) int
- func (b *NodeIDBag) Equals(oIDs NodeIDBag) bool
- func (b *NodeIDBag) Len() int
- func (b *NodeIDBag) List() []NodeID
- func (b *NodeIDBag) PrefixedString(prefix string) string
- func (b *NodeIDBag) Remove(id NodeID)
- func (b *NodeIDBag) String() string
- type RequestID
- type ShortID
- func (id ShortID) Bytes() []byte
- func (id ShortID) Hex() string
- func (id ShortID) Less(other ShortID) bool
- func (id ShortID) MarshalJSON() ([]byte, error)
- func (id ShortID) MarshalText() ([]byte, error)
- func (id ShortID) PrefixedString(prefix string) string
- func (id ShortID) String() string
- func (id *ShortID) UnmarshalJSON(b []byte) error
- func (id *ShortID) UnmarshalText(text []byte) error
- type SliceStringer
- type UniqueBag
- func (b *UniqueBag) Add(setID uint, idSet ...ID)
- func (b *UniqueBag) Bag(alpha int) Bag
- func (b *UniqueBag) Clear()
- func (b *UniqueBag) Difference(diff *UniqueBag)
- func (b *UniqueBag) DifferenceSet(id ID, set BitSet64)
- func (b *UniqueBag) GetSet(id ID) BitSet64
- func (b *UniqueBag) List() []ID
- func (b *UniqueBag) PrefixedString(prefix string) string
- func (b *UniqueBag) RemoveSet(id ID)
- func (b *UniqueBag) String() string
- func (b *UniqueBag) UnionSet(id ID, set BitSet64)
Constants ¶
const BitsPerByte = 8
BitsPerByte is the number of bits per byte
const NodeIDPrefix = "NodeID-"
const NumBits = 256
NumBits is the number of bits this patricia tree manages
Variables ¶
var AliasTests = []func(require *require.Assertions, r AliaserReader, w AliaserWriter){ AliaserLookupErrorTest, AliaserLookupTest, AliaserAliasesEmptyTest, AliaserAliasesTest, AliaserPrimaryAliasTest, AliaserAliasClashTest, AliaserRemoveAliasTest, }
var ( // Empty is a useful all zero value Empty = ID{} )
var (
EmptyNodeID = NodeID{}
)
var (
ShortEmpty = ShortID{}
)
ShortEmpty is a useful all zero value
Functions ¶
func AliaserAliasClashTest ¶
func AliaserAliasClashTest(require *require.Assertions, _ AliaserReader, w AliaserWriter)
func AliaserAliasesEmptyTest ¶
func AliaserAliasesEmptyTest(require *require.Assertions, r AliaserReader, _ AliaserWriter)
func AliaserAliasesTest ¶
func AliaserAliasesTest(require *require.Assertions, r AliaserReader, w AliaserWriter)
func AliaserLookupErrorTest ¶
func AliaserLookupErrorTest(require *require.Assertions, r AliaserReader, _ AliaserWriter)
func AliaserLookupTest ¶
func AliaserLookupTest(require *require.Assertions, r AliaserReader, w AliaserWriter)
func AliaserPrimaryAliasTest ¶
func AliaserPrimaryAliasTest(require *require.Assertions, r AliaserReader, w AliaserWriter)
func AliaserRemoveAliasTest ¶
func AliaserRemoveAliasTest(require *require.Assertions, r AliaserReader, w AliaserWriter)
func EqualSubset ¶
EqualSubset takes in two indices and two ids and returns if the ids are equal from bit start to bit end (non-inclusive). Bit indices are defined as: [7 6 5 4 3 2 1 0] [15 14 13 12 11 10 9 8] ... [255 254 253 252 251 250 249 248] Where index 7 is the MSB of byte 0.
func FirstDifferenceSubset ¶
FirstDifferenceSubset takes in two indices and two ids and returns the index of the first difference between the ids inside bit start to bit end (non-inclusive). Bit indices are defined above
func GetRelevantAliases ¶
GetRelevantAliases returns the aliases with the redundant identity alias removed (each id is aliased to at least itself).
func ShortIDsToStrings ¶
ShortIDsToStrings converts an array of shortIDs to an array of their string representations
Types ¶
type Aliaser ¶
type Aliaser interface { AliaserReader AliaserWriter PrimaryAliasOrDefault(id ID) string }
Aliaser allows one to give an ID aliases and lookup the aliases given to an ID.
func NewAliaser ¶
func NewAliaser() Aliaser
type AliaserReader ¶
type AliaserReader interface { Lookup(alias string) (ID, error) PrimaryAlias(id ID) (string, error) Aliases(id ID) ([]string, error) }
AliaserReader allows one to lookup the aliases given to an ID.
type AliaserWriter ¶
Aliaser allows one to give an ID aliases. An ID can have arbitrarily many aliases; two IDs may not have the same alias.
type Bag ¶
type Bag struct {
// contains filtered or unexported fields
}
Bag is a multiset of IDs.
A bag has the ability to split and filter on its bits for ease of use for binary voting.
func (*Bag) AddCount ¶
AddCount increases the number of times the id has been seen by count.
count must be >= 0
func (*Bag) Filter ¶
Filter returns the bag of ids with the same counts as this bag, except all the ids in the returned bag must have the same bits in the range [start, end) as id.
func (*Bag) Mode ¶
Mode returns the id that has been seen the most and the number of times it has been seen. Ties are broken by the first id to be seen the reported number of times.
func (*Bag) PrefixedString ¶
func (*Bag) SetThreshold ¶
SetThreshold sets the number of times an ID must be added to be contained in the threshold set.
type BigBitSet ¶ added in v1.8.7
type BigBitSet struct {
// contains filtered or unexported fields
}
BigBitSet is a bit-set backed by a big.Int Holds values ranging from [0, INT_MAX] (arch-dependent) Trying to use negative values will result in a panic. This implementation is NOT thread-safe.
func NewBigBitSet ¶ added in v1.8.7
NewBigBitSet returns a new instance of BigBitSet with bits set to 1.
Invariants: 1. Negative bits will cause a panic. 2. Duplicate bits are allowed but will cause a no-op.
func (BigBitSet) Contains ¶ added in v1.8.7
Contains returns true if the [i]'th bit is 1, and false otherwise
func (BigBitSet) Difference ¶ added in v1.8.7
Difference removes all the elements in [other] from this set
func (BigBitSet) HammingWeight ¶ added in v1.8.7
HammingWeight returns the amount of 1's in the bitset
func (BigBitSet) Intersection ¶ added in v1.8.7
Intersection performs the set intersection with another set This sets [b] to include only elements in both [b] and [other]
type BitSet64 ¶
type BitSet64 uint64
BitSet64 is a set that can contain uints in the range [0, 64). All functions are O(1). The zero value is the empty set.
func (*BitSet64) Difference ¶
Difference removes all the elements in [s] from this set
func (*BitSet64) Intersection ¶
Intersection takes the intersection of [s] with this set
type ID ¶
type ID [32]byte
ID wraps a 32 byte hash used as an identifier
func FromString ¶
FromString is the inverse of ID.String()
func GenerateTestID ¶
func GenerateTestID() ID
GenerateTestID returns a new ID that should only be used for testing
func (ID) MarshalJSON ¶
func (ID) MarshalText ¶
func (ID) Prefix ¶
Prefix this id to create a more selective id. This can be used to store multiple values under the same key. For example: prefix1(id) -> confidence prefix2(id) -> vertex This will return a new id and not modify the original id.
func (*ID) UnmarshalJSON ¶
func (*ID) UnmarshalText ¶
type NodeID ¶
type NodeID ShortID
func GenerateTestNodeID ¶
func GenerateTestNodeID() NodeID
GenerateTestNodeID returns a new ID that should only be used for testing
func NodeIDFromCert ¶
func NodeIDFromCert(cert *x509.Certificate) NodeID
func NodeIDFromString ¶
NodeIDFromString is the inverse of NodeID.String()
func (NodeID) MarshalJSON ¶
func (NodeID) MarshalText ¶
func (*NodeID) UnmarshalJSON ¶
func (*NodeID) UnmarshalText ¶
type NodeIDBag ¶
type NodeIDBag struct {
// contains filtered or unexported fields
}
NodeIDBag is a multiset of NodeIDs.
func (*NodeIDBag) AddCount ¶
AddCount increases the nubmer of times the id has been seen by count.
count must be >= 0
func (*NodeIDBag) List ¶
List returns a list of all IDs that have been added, without duplicates. e.g. a bag with {ID1, ID1, ID2} returns ids.ShortID[]{ID1, ID2}
func (*NodeIDBag) PrefixedString ¶
type RequestID ¶ added in v1.8.7
type RequestID struct { // The node this request came from NodeID NodeID // The chain this request came from SourceChainID ID // The chain the expected response should come from DestinationChainID ID // The unique identifier for this request RequestID uint32 // The message opcode Op byte }
RequestID is a unique identifier for an in-flight request pending a response.
type ShortID ¶
type ShortID [20]byte
ShortID wraps a 20 byte hash as an identifier
func GenerateTestShortID ¶
func GenerateTestShortID() ShortID
GenerateTestShortID returns a new ID that should only be used for testing
func ShortFromPrefixedString ¶
ShortFromPrefixedString returns a ShortID assuming the cb58 format is prefixed
func ShortFromString ¶
ShortFromString is the inverse of ShortID.String()
func (ShortID) Bytes ¶
Bytes returns the 20 byte hash as a slice. It is assumed this slice is not modified.
func (ShortID) MarshalJSON ¶
func (ShortID) MarshalText ¶
func (ShortID) PrefixedString ¶
PrefixedString returns the String representation with a prefix added
func (*ShortID) UnmarshalJSON ¶
func (*ShortID) UnmarshalText ¶
type SliceStringer ¶
type SliceStringer []ID
func (SliceStringer) String ¶
func (s SliceStringer) String() string