bitid

package
v0.0.0-...-ff61ee7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2020 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

In order to describe which nodes have signed a multi-signature, the indecies of the sorted list of consensus participants public keys are encoded into binary objects called BitIDs, this is still in development.

Index

Constants

This section is empty.

Variables

Functions

func AddBitIDType

func AddBitIDType(dst BitIDInterface, src BitIDInterface, allowDup bool)

func CheckIntersectionHelper

func CheckIntersectionHelper(b1, b2 NewBitIDInterface) sort.IntSlice

CheckIntersectionHelper returns the items in both bitid (allows duplicates)

func GetBitIDFuncs

func GetBitIDFuncs(id types.BitIDType) (FromIntFunc, NewBitIDFunc)

func HasIntersectionCountHelper

func HasIntersectionCountHelper(b1, b2 NewBitIDInterface) int

IntersectionCountHelper returns the number of intersecting items (allows duplicates).

func HasIntersectionHelper

func HasIntersectionHelper(b1, b2 NewBitIDInterface) bool

HasIntersectionHelper returns true if there is at least one item commit to both bitids

func HasNewItemsBothHelper

func HasNewItemsBothHelper(b1, b2, b3 NewBitIDInterface) bool

HasNewItemsBothHelper returns true if b3 has at least one item not in b1 and not in b2

func HasNewItemsHelper

func HasNewItemsHelper(b1, b2 NewBitIDInterface) bool

HasNewItemsHelper returns true if b2 has at least one item not in b1. Duplicates are only checked once.

Types

type BIDIter

type BIDIter interface {
	NextID() (nxt int, err error) // For iterating through the bitid, an iterator is created using NewBitIDIterator(), returns an error if the iterator has traversed all items
	Done()                        // Done is called when the iterator is no longer needed
}

type BitID

type BitID struct {
	Buff []byte // This are the encoded indecies
	// contains filtered or unexported fields
}

A BitID stores a set of indecies as an array of bytes

func CreateBitIDFromBytes

func CreateBitIDFromBytes(arr []byte) (*BitID, error)

CreateBitIDFromBytes does not copy the byte slice and may modify it when adding new items

func CreateBitIDFromInts

func CreateBitIDFromInts(items sort.IntSlice) (*BitID, error)

CreateBitIDFromInts does not clopy the int slice and may modify it when adding new items

func DecodeBitID

func DecodeBitID(buff []byte) (*BitID, error)

func MergeBitID

func MergeBitID(bid1 *BitID, bid2 *BitID) *BitID

func MergeBitIDList

func MergeBitIDList(bList ...BitIDInterface) *BitID

func SubBitID

func SubBitID(bid1 *BitID, bid2 *BitID) *BitID

SubBitID assumes bid1 and bid2 are already valid to subtract bid 2 is the smaller one

func (*BitID) AddBitID

func (bid *BitID) AddBitID(ID int, allowDup bool, _ *BitIDIterator) bool

func (*BitID) AllowsDuplicates

func (bid *BitID) AllowsDuplicates() bool

AllowDuplicates returns false.

func (*BitID) AppendItem

func (bid *BitID) AppendItem(v int)

Append an item at the end of the bitID (must be bigger than all existing items)

func (*BitID) CheckBitID

func (bid *BitID) CheckBitID(ID int) bool

func (*BitID) CheckIntersection

func (bid *BitID) CheckIntersection(otherint BitIDInterface) sort.IntSlice

func (*BitID) Decode

func (bid *BitID) Decode(reader io.Reader) (n int, err error)

func (*BitID) Deserialize

func (bid *BitID) Deserialize(msg *messages.Message) (n int, err error)

func (*BitID) DoEncode

func (bid *BitID) DoEncode() []byte

func (*BitID) DoMakeCopy

func (bid *BitID) DoMakeCopy() NewBitIDInterface

func (*BitID) Done

func (bid *BitID) Done()

Done is called when this item is no longer needed

func (*BitID) Encode

func (bid *BitID) Encode(writer io.Writer) (n int, err error)

func (*BitID) GetBasicInfo

func (bid *BitID) GetBasicInfo() (min, max, count, uniqueCount int)

Returns the smallest element, the largest element, and the total number of elements

func (*BitID) GetItemList

func (bid *BitID) GetItemList() sort.IntSlice

func (*BitID) GetNewItems

func (bid *BitID) GetNewItems(otherBid BitIDInterface) BitIDInterface

func (*BitID) GetNumItems

func (bid *BitID) GetNumItems() int

func (*BitID) GetStr

func (bid *BitID) GetStr() string

func (*BitID) HasIntersection

func (bid *BitID) HasIntersection(otherint BitIDInterface) bool

func (*BitID) HasNewItems

func (bid *BitID) HasNewItems(otherint BitIDInterface) bool

func (*BitID) MakeCopy

func (bid *BitID) MakeCopy() BitIDInterface

func (*BitID) New

func (bid *BitID) New() NewBitIDInterface

func (*BitID) NewIterator

func (bid *BitID) NewIterator() BIDIter

func (*BitID) NextID

func (bid *BitID) NextID(iter *BitIDIterator) (nxt int, err error)

func (*BitID) SetInitialSize

func (bid *BitID) SetInitialSize(v int)

Allocate the expected initial size

type BitIDInterface

type BitIDInterface interface {
	MakeCopy() BitIDInterface
	DoEncode() []byte
	GetNumItems() int                                         // Returns the number of items in the bitID
	GetNewItems(BitIDInterface) BitIDInterface                // Returns a bitID of all the items in the agrument bitid and not in the bitid calling the function (does not return duplicates)
	HasNewItems(BitIDInterface) bool                          // Returns true if the argument bitid has at least one item not in the bitid calling the function
	CheckIntersection(BitIDInterface) sort.IntSlice           // Return the items in both bitid (allows duplicates)
	CheckBitID(int) bool                                      // Returns true if the argument is in the bid
	AddBitID(id int, allowDup bool, iter *BitIDIterator) bool // Adds the argument to the bid and returns if successful (if allowDup is true then always returns true)
	GetItemList() sort.IntSlice                               // Returns the list of items of the bitid
	GetStr() string                                           // Gets the string representation of the bitid
	HasIntersection(BitIDInterface) bool                      // Returns true if there is at least one item commit to both bitids

	// For iteration
	NextID(iter *BitIDIterator) (nxt int, err error) // For iterating through the bitid, an iterator is created using NewBitIDIterator(), returns an error if the iterator has traversed all items
}

func CreateBitIDTypeFromInts

func CreateBitIDTypeFromInts(items sort.IntSlice) (BitIDInterface, error)

func DecodeBitIDType

func DecodeBitIDType(buff []byte) (BitIDInterface, error)

func MergeBitIDListType

func MergeBitIDListType(allowDuplicates bool, bList ...BitIDInterface) BitIDInterface

func MergeBitIDType

func MergeBitIDType(b1 BitIDInterface, b2 BitIDInterface, allowDuplicates bool) BitIDInterface

type BitIDIterator

type BitIDIterator struct {
	// contains filtered or unexported fields
}

func NewBitIDIterator

func NewBitIDIterator() *BitIDIterator

func (*BitIDIterator) Done

func (iter *BitIDIterator) Done()

Done is called when the iterator is no longer needed

func (*BitIDIterator) NextID

func (iter *BitIDIterator) NextID() (nxt int, err error)

For iterating through the bitid, an iterator is created using NewBitIDIterator(), returns an error if the iterator has traversed all items

type BitIDPool

type BitIDPool struct {
	// contains filtered or unexported fields
}

func (*BitIDPool) Done

func (bp *BitIDPool) Done(bid NewBitIDInterface)

func (*BitIDPool) Get

func (bp *BitIDPool) Get() NewBitIDInterface

type BitIDPoolInterface

type BitIDPoolInterface interface {
	Done(NewBitIDInterface)
	Get() NewBitIDInterface
}

func NewBitIDPool

func NewBitIDPool(idFunc NewBitIDFunc, allowConcurrency bool) BitIDPoolInterface

type ChooseBid

type ChooseBid struct {
	NewBitIDInterface
	// contains filtered or unexported fields
}

func (*ChooseBid) AllowsDuplicates

func (bid *ChooseBid) AllowsDuplicates() bool

AllowDuplicates returns true.

func (*ChooseBid) AppendItem

func (bid *ChooseBid) AppendItem(v int)

Append an item at the end of the bitID (must be bigger than all existing items)

func (*ChooseBid) Decode

func (bid *ChooseBid) Decode(reader io.Reader) (n int, err error)

func (*ChooseBid) Deserialize

func (bid *ChooseBid) Deserialize(msg *messages.Message) (n int, err error)

func (*ChooseBid) DoMakeCopy

func (bid *ChooseBid) DoMakeCopy() NewBitIDInterface

DoMakeCopy returns a copy of the bit id.

func (*ChooseBid) Done

func (bid *ChooseBid) Done()

Done is called when this item is no longer needed

func (*ChooseBid) Encode

func (bid *ChooseBid) Encode(writer io.Writer) (n int, err error)

func (*ChooseBid) GetBasicInfo

func (bid *ChooseBid) GetBasicInfo() (min, max, count, uniqueCount int)

Returns the smallest element, the largest element, and the total number of elements

func (*ChooseBid) GetItemList

func (bid *ChooseBid) GetItemList() sort.IntSlice

Returns the list of items of the bitid

func (*ChooseBid) GetStr

func (bid *ChooseBid) GetStr() string

Gets the string representation of the bitid

func (*ChooseBid) New

func (bid *ChooseBid) New() NewBitIDInterface

New allocates a new bit id.

func (*ChooseBid) NewIterator

func (bid *ChooseBid) NewIterator() BIDIter

Returns a new iterator of the bit id

func (*ChooseBid) SetInitialSize

func (bid *ChooseBid) SetInitialSize(int)

Allocate the expected initial size

type ConcurrentBitIDPool

type ConcurrentBitIDPool struct {
	// contains filtered or unexported fields
}

func (*ConcurrentBitIDPool) Done

func (bp *ConcurrentBitIDPool) Done(bid NewBitIDInterface)

func (*ConcurrentBitIDPool) Get

type DoneFunc

type DoneFunc func(NewBitIDInterface) // Called when the input is finished.

type FromIntFunc

type FromIntFunc func(slice sort.IntSlice) NewBitIDInterface

type MultiBitID

type MultiBitID struct {
	// contains filtered or unexported fields
}

func CreateMultiBitIDFromInts

func CreateMultiBitIDFromInts(items sort.IntSlice) (*MultiBitID, error)

CreateMultiBitIDFromInts does not clopy the int slice and may modify it when adding new items

func DecodeMultiBitID

func DecodeMultiBitID(buff []byte) (*MultiBitID, error)

func MergeMultiBitID

func MergeMultiBitID(bid1 *MultiBitID, bid2 *MultiBitID) *MultiBitID

func MergeMultiBitIDList

func MergeMultiBitIDList(bidList ...BitIDInterface) *MultiBitID

func MergeMultiBitIDNoDup

func MergeMultiBitIDNoDup(bid1 *MultiBitID, bid2 *MultiBitID) *MultiBitID

func SubMultiBitID

func SubMultiBitID(bid1 *MultiBitID, bid2 *MultiBitID) *MultiBitID

SubMultiBitID assumes bid1 and bid2 are already valid to subtract bid 2 is the smaller one

func (*MultiBitID) AddBitID

func (bid *MultiBitID) AddBitID(ID int, allowDup bool, iter *BitIDIterator) bool

func (*MultiBitID) AllowsDuplicates

func (bid *MultiBitID) AllowsDuplicates() bool

AllowDuplicates returns true.

func (*MultiBitID) AppendItem

func (bid *MultiBitID) AppendItem(v int)

AppendItem appends an item at the end of the bitID (must be bigger than all existing items)

func (*MultiBitID) CheckBitID

func (bid *MultiBitID) CheckBitID(ID int) bool

func (*MultiBitID) CheckIntersection

func (bid *MultiBitID) CheckIntersection(otherint BitIDInterface) sort.IntSlice

func (*MultiBitID) Decode

func (bid *MultiBitID) Decode(reader io.Reader) (n int, err error)

func (*MultiBitID) Deserialize

func (bid *MultiBitID) Deserialize(msg *messages.Message) (n int, err error)

func (*MultiBitID) DoEncode

func (bid *MultiBitID) DoEncode() []byte

func (*MultiBitID) DoMakeCopy

func (bid *MultiBitID) DoMakeCopy() NewBitIDInterface

func (*MultiBitID) Done

func (bid *MultiBitID) Done()

Done is called when this item is no longer needed

func (*MultiBitID) Encode

func (bid *MultiBitID) Encode(writer io.Writer) (n int, err error)

func (*MultiBitID) GetBasicInfo

func (bid *MultiBitID) GetBasicInfo() (min, max, count, uniqueCount int)

GetBasicInfo returns the smallest element, the largest element, and the total number of elements

func (*MultiBitID) GetItemList

func (bid *MultiBitID) GetItemList() sort.IntSlice

func (*MultiBitID) GetNewItems

func (bid *MultiBitID) GetNewItems(otherint BitIDInterface) BitIDInterface

GetNewItems does not return duplicates

func (*MultiBitID) GetNumItems

func (bid *MultiBitID) GetNumItems() int

func (*MultiBitID) GetStr

func (bid *MultiBitID) GetStr() string

func (*MultiBitID) HasIntersection

func (bid *MultiBitID) HasIntersection(otherint BitIDInterface) bool

func (*MultiBitID) HasNewItems

func (bid *MultiBitID) HasNewItems(otherint BitIDInterface) bool

func (*MultiBitID) MakeCopy

func (bid *MultiBitID) MakeCopy() BitIDInterface

func (*MultiBitID) New

func (bid *MultiBitID) New() NewBitIDInterface

func (*MultiBitID) NewIterator

func (bid *MultiBitID) NewIterator() BIDIter

func (*MultiBitID) NextID

func (bid *MultiBitID) NextID(iter *BitIDIterator) (nxt int, err error)

func (*MultiBitID) SetInitialSize

func (bid *MultiBitID) SetInitialSize(v int)

SetInitialSize allocates the expected initial size

type NewBitIDFunc

type NewBitIDFunc func() NewBitIDInterface

type NewBitIDInterface

type NewBitIDInterface interface {
	New() NewBitIDInterface        // New allocates a new bit id.
	DoMakeCopy() NewBitIDInterface // DoMakeCopy returns a copy of the bit id.
	// GetNumItems() int                                         // Returns the number of items in the bitID
	// CheckBitID(int) bool                              // Returns true if the argument is in the bid
	GetItemList() sort.IntSlice                       // Returns the list of items of the bitid
	GetStr() string                                   // Gets the string representation of the bitid
	NewIterator() BIDIter                             // Returns a new iterator of the bit id
	GetBasicInfo() (min, max, count, uniqueCount int) // Returns the smallest element, the largest element, and the total number of elements
	SetInitialSize(int)                               // Allocate the expected initial size
	AppendItem(int)                                   // Append an item at the end of the bitID (must be bigger than all existing items)
	AllowsDuplicates() bool                           // AllowDuplicates returns true if the bit ID allows duplicate elements
	Done()                                            // Done is called when this item is no longer needed

	Encode(writer io.Writer) (n int, err error)
	Decode(reader io.Reader) (n int, err error)
	Deserialize(msg *messages.Message) (n int, err error)
}

func AddHelper

func AddHelper(b1, b2 NewBitIDInterface, allowDuplicates, errorOnDuplicate bool,
	newFunc NewBitIDFunc, freeB1 DoneFunc) (NewBitIDInterface, error)

AddHelper adds the items in b2 to b1. If allowsDuplicates is false then duplicates will only be counted once. If errorOnDuplicate it true then an error will be returned if a duplicate is found. If freeB1 is non-nil, then it will be called on b1.

func AddHelperSet

func AddHelperSet(allowDuplicates, errorOnDuplicate bool,
	newFunc NewBitIDFunc, bids ...NewBitIDInterface) (NewBitIDInterface, error)

AddHelper adds the items in the bitids together. If allowsDuplicates is false then duplicates will only be counted once. If errorOnDuplicate it true then an error will be returned if a duplicate is found. If freeB1 is non-nil, then it will be called on b1.

func GetNewItemsHelper

func GetNewItemsHelper(b1, b2 NewBitIDInterface, newFunc NewBitIDFunc) NewBitIDInterface

GetNewItemsHelper returns a bitID of all the items in b2 and not in b1 (does not return duplicates)

func NewBitIDFromInts

func NewBitIDFromInts(items sort.IntSlice) NewBitIDInterface

func NewChooseBIDFromInts

func NewChooseBIDFromInts(items sort.IntSlice) NewBitIDInterface

func NewMultiBitIDFromInts

func NewMultiBitIDFromInts(items sort.IntSlice) NewBitIDInterface

func NewPbitidFromInts

func NewPbitidFromInts(items sort.IntSlice) NewBitIDInterface

func NewSliceBitIDFromInts

func NewSliceBitIDFromInts(from sort.IntSlice) NewBitIDInterface

NewSliceBitIDFromInts allocates a SliceBitID from the int slice

func NewUvarintBitIDFromInts

func NewUvarintBitIDFromInts(items sort.IntSlice) NewBitIDInterface

func SubHelper

func SubHelper(b1, b2 NewBitIDInterface, safeSub SafeSubType, newFunc NewBitIDFunc, freeB1 DoneFunc) (NewBitIDInterface, error)

SubHelper subtracts b2 from b1 (allows duplicates). If safeSub is true then all b1 must contain all items in b2. If freeB1 is non nil, then it will be called on b1.

type Pbitid

type Pbitid struct {
	// contains filtered or unexported fields
}

func (*Pbitid) AllowsDuplicates

func (bid *Pbitid) AllowsDuplicates() bool

AllowDuplicates returns true.

func (*Pbitid) AppendItem

func (bid *Pbitid) AppendItem(nxt int)

func (*Pbitid) CheckBitID

func (bid *Pbitid) CheckBitID(int) bool

CheckBitID returns true if the argument is in the bid

func (*Pbitid) Decode

func (bid *Pbitid) Decode(reader io.Reader) (n int, err error)

func (*Pbitid) Deserialize

func (bid *Pbitid) Deserialize(msg *messages.Message) (n int, err error)

func (*Pbitid) DoEncode

func (bid *Pbitid) DoEncode() []byte

func (*Pbitid) DoMakeCopy

func (bid *Pbitid) DoMakeCopy() NewBitIDInterface

DoMakeCopy returns a copy of the bit id.

func (*Pbitid) Done

func (bid *Pbitid) Done()

Done is called when this item is no longer needed

func (*Pbitid) Encode

func (bid *Pbitid) Encode(writer io.Writer) (n int, err error)

func (*Pbitid) GetBasicInfo

func (bid *Pbitid) GetBasicInfo() (min, max, count, uniqueCount int)

GetBasicInfo returns the smallest element, the largest element, and the total number of elements

func (*Pbitid) GetItemList

func (bid *Pbitid) GetItemList() sort.IntSlice

func (*Pbitid) GetStr

func (bid *Pbitid) GetStr() string

func (*Pbitid) New

func (bid *Pbitid) New() NewBitIDInterface

func (*Pbitid) NewIterator

func (bid *Pbitid) NewIterator() BIDIter

NewIterator Returns a new iterator of the bit id.

func (*Pbitid) SetInitialSize

func (bid *Pbitid) SetInitialSize(int)

SetInitialSize is unused.

type SafeSubType

type SafeSubType int
const (
	NotSafe                 SafeSubType = iota // subtract any two bit ids
	NonIntersecting                            // fail if the one being subtracted is not contained in the outter one
	NonIntersectingAndEmpty                    // also fail is the resulting bid id would be empty
)

type SliceBitID

type SliceBitID struct {
	// contains filtered or unexported fields
}

func (*SliceBitID) AllowsDuplicates

func (bid *SliceBitID) AllowsDuplicates() bool

AllowDuplicates returns true.

func (*SliceBitID) AppendItem

func (bid *SliceBitID) AppendItem(v int)

Append an item at the end of the bitID (must be bigger than all existing items)

func (*SliceBitID) CheckBitID

func (bid *SliceBitID) CheckBitID(v int) bool

Returns true if the argument is in the bid

func (*SliceBitID) Decode

func (bid *SliceBitID) Decode(reader io.Reader) (n int, err error)

func (*SliceBitID) Deserialize

func (bid *SliceBitID) Deserialize(msg *messages.Message) (n int, err error)

func (*SliceBitID) DoMakeCopy

func (bid *SliceBitID) DoMakeCopy() NewBitIDInterface

DoMakeCopy returns a copy of the bit id.

func (*SliceBitID) Done

func (bid *SliceBitID) Done()

Done is called when this item is no longer needed

func (*SliceBitID) Encode

func (bid *SliceBitID) Encode(writer io.Writer) (n int, err error)

func (*SliceBitID) GetBasicInfo

func (bid *SliceBitID) GetBasicInfo() (min, max, count, uniqueItemCount int)

Returns the smallest element, the largest element, and the total number of elements

func (*SliceBitID) GetItemList

func (bid *SliceBitID) GetItemList() sort.IntSlice

Returns the list of items of the bitid

func (*SliceBitID) GetStr

func (bid *SliceBitID) GetStr() string

Gets the string representation of the bitid

func (*SliceBitID) New

func (bid *SliceBitID) New() NewBitIDInterface

New allocates a new empty bit id.

func (*SliceBitID) NewIterator

func (bid *SliceBitID) NewIterator() BIDIter

func (*SliceBitID) SetInitialSize

func (bid *SliceBitID) SetInitialSize(v int)

Allocate the expected initial size

type UvarintBitID

type UvarintBitID struct {
	// contains filtered or unexported fields
}

func (*UvarintBitID) AllowsDuplicates

func (bid *UvarintBitID) AllowsDuplicates() bool

AllowDuplicates returns true.

func (*UvarintBitID) AppendItem

func (bid *UvarintBitID) AppendItem(v int)

Append an item at the end of the bitID (must be bigger than all existing items)

func (*UvarintBitID) CheckBitID

func (bid *UvarintBitID) CheckBitID(v int) bool

Returns true if the argument is in the bid

func (*UvarintBitID) Decode

func (bid *UvarintBitID) Decode(reader io.Reader) (n int, err error)

func (*UvarintBitID) Deserialize

func (bid *UvarintBitID) Deserialize(msg *messages.Message) (n int, err error)

func (*UvarintBitID) DoMakeCopy

func (bid *UvarintBitID) DoMakeCopy() NewBitIDInterface

func (*UvarintBitID) Done

func (bid *UvarintBitID) Done()

Done is called when this item is no longer needed

func (*UvarintBitID) Encode

func (bid *UvarintBitID) Encode(writer io.Writer) (n int, err error)

func (*UvarintBitID) GetBasicInfo

func (bid *UvarintBitID) GetBasicInfo() (min, max, count, uniqueCount int)

Returns the smallest element, the largest element, and the total number of elements

func (*UvarintBitID) GetItemList

func (bid *UvarintBitID) GetItemList() sort.IntSlice

Returns the list of items of the bitid

func (*UvarintBitID) GetStr

func (bid *UvarintBitID) GetStr() string

Gets the string representation of the bitid

func (*UvarintBitID) New

func (bid *UvarintBitID) New() NewBitIDInterface

func (*UvarintBitID) NewIterator

func (bid *UvarintBitID) NewIterator() BIDIter

func (*UvarintBitID) SetInitialSize

func (bid *UvarintBitID) SetInitialSize(v int)

Allocate the expected initial size

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL