Documentation ¶
Overview ¶
Package hashcounter provides an efficient way to count the number of occurences of unique integers. The exposed functions are not thread-safe.
Do not use this package if you cannot tolerate any collisions. By default the key will be determined by calling xxhash.Sum64. You can provide your own hash function as long as it returns a uint64 (like crc64, murmur3, etc). Since there is some hashing involved, there might be collisions. You've been warned. If your byte slices can safely fit in a uint64 without losing any bits then feel free to send a custom hash function using something like binary.Uvarint.
You can initialize a new C using New or just using new(hashcounter.C).
Index ¶
- type C
- func (m *C) Add(b []byte, v uint16)
- func (m *C) Get(b []byte) (uint16, bool)
- func (m *C) GetKey(k uint64) (uint16, bool)
- func (m *C) Key(k []byte) uint64
- func (m *C) Len() int
- func (m *C) MarshalBinary() ([]byte, error)
- func (m *C) Merge(n *C)
- func (m *C) Range(f func(key uint64, value uint16) bool)
- func (m *C) Reset()
- func (m *C) UnmarshalBinary(b []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type C ¶
type C struct {
// contains filtered or unexported fields
}
C holds an array of unique values and an associative count
func NewWithHash ¶
NewWithHash returns a new instance of C with the provided hash function
func (*C) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (*C) Merge ¶
Merge adds every key from the sent C to the called on C. This assumes the hash functions are the same.
func (*C) Range ¶
Range calls the given function for every value in the map and continues looping until the given bool. The returned key is going to be the result of Key(bytes). If you want the key to be reversable, you must pass a hash function to NewWithHash that allows you to reverse the operation.
func (*C) Reset ¶
func (m *C) Reset()
Reset removes all of the keys and returns C to it's empty state
func (*C) UnmarshalBinary ¶
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.