Documentation ¶
Overview ¶
Copyright (c) of parts are held by the various contributors Licensed under the MIT License. See LICENSE file in the project root for full license information.
Copyright (c) of parts are held by the various contributors Licensed under the MIT License. See LICENSE file in the project root for full license information.
Copyright (c) of parts are held by the various contributors Licensed under the MIT License. See LICENSE file in the project root for full license information.
Index ¶
- Constants
- func AbortSettings(target uint64) (abortByte int, abortVal uint8)
- func GetUserTablePath() (string, error)
- func Release(hash *LXRHash)
- type HashParallelItem
- type LXRHash
- func (lx LXRHash) BenchmarkFlatHash(ctx context.Context, duration time.Duration, goroutines uint) (uint64, time.Duration)
- func (lx LXRHash) BenchmarkHash(ctx context.Context, duration time.Duration, goroutines uint) (uint64, time.Duration)
- func (lx LXRHash) FlatHash(src []byte) []byte
- func (lx *LXRHash) GenerateTable()
- func (lx LXRHash) Hash(src []byte) []byte
- func (lx LXRHash) HashParallel(base []byte, batch [][]byte) [][]byte
- func (lx *LXRHash) Init(Seed, MapSizeBits, HashSize, Passes uint64)
- func (lx *LXRHash) InitFromPath(Seed, MapSizeBits, HashSize, Passes uint64, TablePath string) (string, error)
- func (lx *LXRHash) Log(msg string)
- func (lx *LXRHash) ReadTable()
- func (lx *LXRHash) Verbose(val bool)
- func (lx *LXRHash) WriteTable(filename string)
Constants ¶
const ( Seed = uint64(0xFAFAECECFAFAECEC) // The seed defines a "hash space". MapSizeBits = uint64(30) // Default table size Passes = uint64(5) // Default number of shuffles of the tables HashSize = uint64(256) // Default hash size. )
Default Seed
Variables ¶
This section is empty.
Functions ¶
func AbortSettings ¶
AbortSettings indicated the proper settings to abort if a hash is found to be less than the target. Aborting early can save a few hash table accesses
func GetUserTablePath ¶
Types ¶
type HashParallelItem ¶
type HashParallelItem struct {
// contains filtered or unexported fields
}
type LXRHash ¶
type LXRHash struct { ByteMap []byte // Integer Offsets MapSize uint64 // Size of the translation table MapSizeBits uint64 // Size of the ByteMap in Bits Passes uint64 // Passes to generate the rand table Seed uint64 // An arbitrary number used to create the tables. HashSize uint64 // Number of bytes in the hash // contains filtered or unexported fields }
LXRHash holds one instance of a hash function with a specific seed and map size
func Init ¶
Init provides access to shared instances of LXRHash without having to instantiate multiple bytemaps. Two separate calls to Init() will result in a reference to the same object.
func (LXRHash) BenchmarkFlatHash ¶
func (lx LXRHash) BenchmarkFlatHash(ctx context.Context, duration time.Duration, goroutines uint) (uint64, time.Duration)
BenchmarkHash will run a benchmark for the specified duration using the FlatHash function. Returns the number of hashes calculated and the real duration of the benchmark. If no goroutines are specified it will use the total number of available cores.
func (LXRHash) BenchmarkHash ¶
func (lx LXRHash) BenchmarkHash(ctx context.Context, duration time.Duration, goroutines uint) (uint64, time.Duration)
BenchmarkHash will run a benchmark for the specified duration using the regular Hash function. Returns the number of hashes calculated and the real duration of the benchmark. If no goroutines are specified it will use the total number of available cores.
func (LXRHash) FlatHash ¶
FlatHash takes the arbitrary input and returns the resulting hash of length HashSize Does not use anonymous functions
func (*LXRHash) GenerateTable ¶
func (lx *LXRHash) GenerateTable()
GenerateTable generates the bytemap. Initializes the map with an incremental sequence of bytes, then does P passes, shuffling each element in a deterministic manner.
func (LXRHash) Hash ¶
Hash takes the arbitrary input and returns the resulting hash of length HashSize
func (LXRHash) HashParallel ¶
HashParallel takes the arbitrary input and returns the resulting hash of length HashSize. The batch must have at least one entry. The base is prefixed to all items in the batch.
func (*LXRHash) Init ¶
Init initializes the hash with the given values
We use our own algorithm for initializing the map struct. This is an fairly large table of byte values we use to map bytes to other byte values to enhance the avalanche nature of the hash as well as increase the memory footprint of the hash.
Seed is a 64 bit starting point MapSizeBits is the number of bits to use for the MapSize, i.e. 10 = mapsize of 1024 HashSize is the number of bits in the hash; truncated to a byte bountry Passes is the number of shuffles of the ByteMap performed. Each pass shuffles all byte values in the map
Panics when MapSizeBits is < 8 and on other error conditions
func (*LXRHash) InitFromPath ¶
func (lx *LXRHash) InitFromPath(Seed, MapSizeBits, HashSize, Passes uint64, TablePath string) (string, error)
Initialize the hash with the given values, reading the hash table from the specified path
Seed - a 64-bit starting value MapSizeBits - size of the map as an exponent of 2, i.e., 10 -> map size of 2 ^ 10 = 1024; between 8 and 34 bits inclusive. HashSize - number of bits in the hash, truncated to a byte boundary Passes - number of shuffles of the ByteMap TablePath - the file system path of the directory which holds hash table files
Because hash table files can be large, sharing them between applications is desirable. Suggested shared hash table paths:
Windows: %ProgramData%/LXRHash macOS: /Library/Application\ Support/org.pegnet.LXRHash Linux: /var/lib/LXRHash BSD: /var/db/LXRHash
func (*LXRHash) Log ¶
Log is a wrapper function that only prints information when verbose is enabled
func (*LXRHash) ReadTable ¶
func (lx *LXRHash) ReadTable()
ReadTable attempts to load the ByteMap from disk. If that doesn't exist, a new one will be generated and saved.
func (*LXRHash) Verbose ¶
Verbose enables or disables the output of progress indicators to the console
func (*LXRHash) WriteTable ¶
WriteTable caches the bytemap to disk so it only has to be generated once