Documentation ¶
Index ¶
- Constants
- type Bitmap
- func Closest(target Bitmap, bitmaps ...Bitmap) Bitmap
- func FromBigP(b *big.Int) Bitmap
- func FromBytes(data []byte) (Bitmap, error)
- func FromBytesP(data []byte) Bitmap
- func FromHex(hexStr string) (Bitmap, error)
- func FromHexP(hexStr string) Bitmap
- func FromShortHex(hexStr string) (Bitmap, error)
- func FromShortHexP(hexStr string) Bitmap
- func FromString(data string) (Bitmap, error)
- func FromStringP(data string) Bitmap
- func MaxP() Bitmap
- func Rand() Bitmap
- func RandInRangeP(low, high Bitmap) Bitmap
- func (b Bitmap) Add(other Bitmap) Bitmap
- func (b Bitmap) And(other Bitmap) Bitmap
- func (b Bitmap) BString() string
- func (b Bitmap) Big() *big.Int
- func (b Bitmap) Closer(x, y Bitmap) bool
- func (b Bitmap) Cmp(other Bitmap) int
- func (b Bitmap) Copy() Bitmap
- func (b Bitmap) Equals(other Bitmap) bool
- func (b Bitmap) Get(n int) bool
- func (b Bitmap) Hex() string
- func (b Bitmap) HexShort() string
- func (b Bitmap) HexSimplified() string
- func (b Bitmap) MarshalBencode() ([]byte, error)
- func (b Bitmap) Not() Bitmap
- func (b Bitmap) Or(other Bitmap) Bitmap
- func (b Bitmap) Prefix(n int, one bool) Bitmap
- func (b Bitmap) PrefixLen() int
- func (b Bitmap) RawString() string
- func (b Bitmap) Set(n int, one bool) Bitmap
- func (b Bitmap) String() string
- func (b Bitmap) Sub(other Bitmap) Bitmap
- func (b Bitmap) Suffix(n int, one bool) Bitmap
- func (b *Bitmap) UnmarshalBencode(encoded []byte) error
- func (b Bitmap) Xor(other Bitmap) Bitmap
- type Range
Constants ¶
const ( NumBytes = 48 // bytes NumBits = NumBytes * 8 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bitmap ¶
Bitmap is a generalized representation of an identifier or data that can be sorted, compared fast. Used by the DHT package as a way to handle the unique identifiers of a DHT node.
func Closest ¶
Closest returns the closest bitmap to target. if no bitmaps are provided, target itself is returned
func FromBytes ¶
FromBytes returns a bitmap as long as the byte array is of a specific length specified in the parameters.
func FromBytesP ¶
FromBytesP returns a bitmap as long as the byte array is of a specific length specified in the parameters otherwise it wil panic.
func FromHex ¶
FromHex returns a bitmap by converting the hex string to bytes and creating from bytes as long as the byte array is of a specific length specified in the parameters
func FromHexP ¶
FromHexP returns a bitmap by converting the hex string to bytes and creating from bytes as long as the byte array is of a specific length specified in the parameters otherwise it wil panic.
func FromShortHex ¶
FromShortHex returns a bitmap by converting the hex string to bytes, adding the leading zeros prefix to the hex string and creating from bytes as long as the byte array is of a specific length specified in the parameters
func FromShortHexP ¶
FromShortHexP returns a bitmap by converting the hex string to bytes, adding the leading zeros prefix to the hex string and creating from bytes as long as the byte array is of a specific length specified in the parameters otherwise it wil panic.
func FromString ¶
FromString returns a bitmap by converting the string to bytes and creating from bytes as long as the byte array is of a specific length specified in the parameters
func FromStringP ¶
FromStringP returns a bitmap by converting the string to bytes and creating from bytes as long as the byte array is of a specific length specified in the parameters otherwise it wil panic.
func Rand ¶
func Rand() Bitmap
Rand generates a cryptographically random bitmap with the confines of the parameters specified.
func RandInRangeP ¶
RandInRangeP generates a cryptographically random bitmap and while it is greater than the high threshold bitmap will subtract the diff between high and low until it is no longer greater that the high.
func (Bitmap) Add ¶
Add returns a bitmap that treats both bitmaps as numbers and adding them together. Since the size of a bitmap is limited, an overflow is possible when adding bitmaps.
func (Bitmap) And ¶
And returns a comparison bitmap, that for each byte returns the AND true table result
func (Bitmap) Cmp ¶
Cmp compares b and other and returns:
-1 if b < other 0 if b == other +1 if b > other
func (Bitmap) HexSimplified ¶
HexSimplified returns the hexadecimal representation with all leading 0's removed
func (Bitmap) MarshalBencode ¶
MarshalBencode implements the Marshaller(bencode)/Message interface.
func (Bitmap) Or ¶
Or returns a comparison bitmap, that for each byte returns the OR true table result
func (Bitmap) Prefix ¶
Prefix returns a copy of b with the first n bits set to 1 (if `one` is true) or 0 (if `one` is false) https://stackoverflow.com/a/23192263/182709
func (Bitmap) Sub ¶
Sub returns a bitmap that treats both bitmaps as numbers and subtracts then via the inverse of the other and adding then together a + (-b). Negative bitmaps are not supported so other must be greater than this.
func (Bitmap) Suffix ¶
Suffix returns a copy of b with the last n bits set to 1 (if `one` is true) or 0 (if `one` is false) https://stackoverflow.com/a/23192263/182709
func (*Bitmap) UnmarshalBencode ¶
UnmarshalBencode implements the Marshaller(bencode)/Message interface.
type Range ¶
Range has a start and end
func (Range) IntervalP ¶
IntervalP divides the range into `num` intervals and returns the `n`th one intervals are approximately the same size, but may not be exact because of rounding issues the first interval always starts at the beginning of the range, and the last interval always ends at the end