Documentation ¶
Index ¶
- Constants
- Variables
- func EqualSubset(start, stop int, id1, id2 ID) bool
- func Equals(a, b []ID) bool
- func FirstDifferenceSubset(start, stop int, id1, id2 ID) (int, bool)
- func IsSortedAndUniqueIDs(ids []ID) bool
- func IsSortedAndUniqueShortIDs(ids []ShortID) bool
- func IsUniqueShortIDs(ids []ShortID) bool
- func SortIDs(ids []ID)
- func SortShortIDs(ids []ShortID)
- func UnsortedEquals(a, b []ID) bool
- type Aliaser
- 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) SetThreshold(threshold int)
- func (b *Bag) Split(index uint) [2]Bag
- func (b *Bag) String() string
- func (b *Bag) Threshold() Set
- type BitSet
- func (bs *BitSet) Add(i uint)
- func (bs *BitSet) Clear()
- func (bs BitSet) Contains(i uint) bool
- func (bs *BitSet) Difference(s BitSet)
- func (bs *BitSet) Intersection(s BitSet)
- func (bs BitSet) Len() int
- func (bs *BitSet) Remove(i uint)
- func (bs BitSet) String() string
- func (bs *BitSet) Union(s BitSet)
- type ID
- func (id ID) Bit(i uint) int
- func (id ID) Bytes() []byte
- func (id ID) Equals(oID ID) bool
- func (id ID) Hex() string
- func (id ID) IsZero() bool
- func (id ID) Key() [32]byte
- func (id ID) MarshalJSON() ([]byte, error)
- func (id ID) Prefix(prefixes ...uint64) ID
- func (id ID) String() string
- func (id *ID) UnmarshalJSON(b []byte) error
- type QueueSet
- type Set
- func (ids *Set) Add(idList ...ID)
- func (ids Set) CappedList(size int) []ID
- func (ids *Set) Clear()
- func (ids *Set) Contains(id ID) bool
- func (ids Set) Equals(oIDs Set) bool
- func (ids Set) Len() int
- func (ids Set) List() []ID
- func (ids *Set) Overlaps(big Set) bool
- func (ids *Set) Remove(idList ...ID)
- func (ids Set) String() string
- func (ids *Set) Union(set Set)
- type ShortBag
- func (b *ShortBag) Add(ids ...ShortID)
- func (b *ShortBag) AddCount(id ShortID, count int)
- func (b *ShortBag) Count(id ShortID) int
- func (b *ShortBag) Equals(oIDs ShortBag) bool
- func (b *ShortBag) Len() int
- func (b *ShortBag) List() []ShortID
- func (b *ShortBag) PrefixedString(prefix string) string
- func (b *ShortBag) Remove(id ShortID)
- func (b *ShortBag) String() string
- type ShortID
- func (id ShortID) Bytes() []byte
- func (id ShortID) Equals(oID ShortID) bool
- func (id ShortID) Hex() string
- func (id ShortID) IsZero() bool
- func (id ShortID) Key() [20]byte
- func (id ShortID) LongID() ID
- func (id ShortID) MarshalJSON() ([]byte, error)
- func (id ShortID) PrefixedString(prefix string) string
- func (id ShortID) String() string
- func (id *ShortID) UnmarshalJSON(b []byte) error
- type ShortSet
- func (ids *ShortSet) Add(idList ...ShortID)
- func (ids ShortSet) CappedList(size int) []ShortID
- func (ids *ShortSet) Clear()
- func (ids *ShortSet) Contains(id ShortID) bool
- func (ids ShortSet) Equals(oIDs ShortSet) bool
- func (ids ShortSet) Len() int
- func (ids ShortSet) List() []ShortID
- func (ids *ShortSet) Remove(idList ...ShortID)
- func (ids ShortSet) String() string
- func (ids *ShortSet) Union(idSet ShortSet)
- type UniqueBag
- func (b *UniqueBag) Add(setID uint, idSet ...ID)
- func (b *UniqueBag) Bag(alpha int) Bag
- func (b *UniqueBag) Difference(diff *UniqueBag)
- func (b *UniqueBag) DifferenceSet(id ID, set BitSet)
- func (b *UniqueBag) GetSet(id ID) BitSet
- func (b *UniqueBag) List() []ID
- func (b *UniqueBag) RemoveSet(id ID)
- func (b *UniqueBag) String() string
- func (b *UniqueBag) UnionSet(id ID, set BitSet)
Constants ¶
const BitsPerByte = 8
BitsPerByte is the number of bits per byte
const NumBits = 256
NumBits is the number of bits this patricia tree manages
Variables ¶
var Empty = ID{ID: &[32]byte{}}
Empty is a useful all zero value
var ShortEmpty = ShortID{ID: &[20]byte{}}
ShortEmpty is a useful all zero value
Functions ¶
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 IsSortedAndUniqueIDs ¶
IsSortedAndUniqueIDs returns true if the ids are sorted and unique
func IsSortedAndUniqueShortIDs ¶
IsSortedAndUniqueShortIDs returns true if the ids are sorted and unique
func IsUniqueShortIDs ¶ added in v0.6.1
IsUniqueShortIDs returns true iff ids are unique
func UnsortedEquals ¶
UnsortedEquals returns true if the have the same number of each ID
Types ¶
type Aliaser ¶
type Aliaser struct {
// contains filtered or unexported fields
}
Aliaser allows one to give an ID aliases and lookup the aliases given to an ID. An ID can have arbitrarily many aliases; two IDs may not have the same alias.
func (*Aliaser) Initialize ¶
func (a *Aliaser) Initialize()
Initialize the aliaser to have no aliases
func (*Aliaser) PrimaryAlias ¶
PrimaryAlias returns the first alias of [id]
func (*Aliaser) RemoveAliases ¶ added in v0.6.1
RemoveAliases of the provided ID
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 it's bits for ease of use for binary voting.
func (*Bag) AddCount ¶
AddCount increases the nubmer 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) SetThreshold ¶
SetThreshold sets the number of times an ID must be added to be contained in the threshold set.
type BitSet ¶
type BitSet uint64
BitSet 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 (*BitSet) Difference ¶
Difference removes all the elements in [s] from this set
func (*BitSet) Intersection ¶
Intersection takes the intersection of [s] with this set
type ID ¶
type ID struct {
ID *[32]byte `serialize:"true"`
}
ID wraps a 32 byte hash as an identifier Internal field ID should never be modified from outside ids package
func FromString ¶
FromString is the inverse of ID.String()
func GenerateTestID ¶ added in v0.6.1
func GenerateTestID() ID
GenerateTestID returns a new ID that should only be used for testing
func (ID) Bytes ¶
Bytes returns the 32 byte hash as a slice. It is assumed this slice is not modified.
func (ID) Key ¶
Key returns a 32 byte hash that this id represents. This is useful to allow for this id to be used as keys in maps.
type QueueSet ¶
type QueueSet struct {
// contains filtered or unexported fields
}
QueueSet is a set of IDs stored in fifo order
type Set ¶
Set is a set of IDs
func (Set) CappedList ¶ added in v0.5.7
CappedList returns a list of length at most [size]. Size should be >= 0. If size < 0, returns nil.
type ShortBag ¶ added in v0.6.1
type ShortBag struct {
// contains filtered or unexported fields
}
ShortBag is a multiset of ShortIDs.
func (*ShortBag) Add ¶ added in v0.6.1
Add increases the number of times each id has been seen by one.
func (*ShortBag) AddCount ¶ added in v0.6.1
AddCount increases the nubmer of times the id has been seen by count.
count must be >= 0
func (*ShortBag) PrefixedString ¶ added in v0.6.1
PrefixedString ...
type ShortID ¶
type ShortID struct {
ID *[20]byte `serialize:"true"`
}
ShortID wraps a 20 byte hash as an identifier
func GenerateTestShortID ¶ added in v0.6.1
func GenerateTestShortID() ShortID
GenerateTestShortID returns a new ID that should only be used for testing
func NewShortID ¶
NewShortID creates an identifer from a 20 byte hash
func ShortFromPrefixedString ¶ added in v0.6.1
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) Key ¶
Key returns a 20 byte hash that this id represents. This is useful to allow for this id to be used as keys in maps.
func (ShortID) PrefixedString ¶ added in v0.6.1
PrefixedString returns the String representation with a prefix added
type ShortSet ¶
ShortSet is a set of ShortIDs
func (*ShortSet) Add ¶
Add all the ids to this set, if the id is already in the set, nothing happens
func (ShortSet) CappedList ¶
CappedList returns a list of length at most [size]. Size should be >= 0. If size < 0, returns nil.
func (*ShortSet) Remove ¶
Remove all the id from this set, if the id isn't in the set, nothing happens