lsh

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hash64

func Hash64(s string) uint64

Hash64 computes a 64-bit FNV-1a hash for a string.

func MinInt

func MinInt(a, b int) int

MinInt returns the smaller of two ints.

Types

type LSHIndex

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

LSHIndex implements MinHash LSH with banding.

func NewLSHIndex

func NewLSHIndex(bands, rows int) *LSHIndex

NewLSHIndex creates an index with banding parameters.

func (*LSHIndex) AddFragment

func (idx *LSHIndex) AddFragment(id string, signature *MinHashSignature) error

AddFragment inserts a fragment signature into the index.

func (*LSHIndex) Bands

func (idx *LSHIndex) Bands() int

Bands returns the number of bands.

func (*LSHIndex) BuildIndex

func (idx *LSHIndex) BuildIndex() error

BuildIndex is a no-op for incremental building (kept for API symmetry).

func (*LSHIndex) FindCandidates

func (idx *LSHIndex) FindCandidates(signature *MinHashSignature) []string

FindCandidates retrieves candidate fragment IDs that share at least one band bucket.

func (*LSHIndex) FindCandidatesLimit added in v0.2.2

func (idx *LSHIndex) FindCandidatesLimit(signature *MinHashSignature, maxCandidates int) []string

FindCandidatesLimit retrieves candidate fragment IDs that share at least one band bucket, stopping as soon as maxCandidates distinct IDs have been collected so dense buckets never materialize in full. maxCandidates <= 0 disables the cap. Traversal order is deterministic — band order, then bucket insertion order — so capped queries keep the earliest-encountered candidates rather than an arbitrary subset.

func (*LSHIndex) GetSignature

func (idx *LSHIndex) GetSignature(id string) *MinHashSignature

GetSignature returns the stored signature for a fragment ID.

func (*LSHIndex) Rows

func (idx *LSHIndex) Rows() int

Rows returns the number of rows per band.

func (*LSHIndex) Size

func (idx *LSHIndex) Size() int

Size returns the number of fragments in the index.

type MinHashSignature

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

MinHashSignature holds the signature vector.

func (*MinHashSignature) NumHashes

func (s *MinHashSignature) NumHashes() int

NumHashes returns the number of hash functions used.

func (*MinHashSignature) Signatures

func (s *MinHashSignature) Signatures() []uint64

Signatures returns the signature slice.

type MinHasher

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

MinHasher computes MinHash signatures for feature sets.

The hash family is stored as coefficient pairs rather than closures: signing one fragment evaluates numHashes × |features| hashes, so an indirect call per evaluation is the difference between a few and a few dozen instructions.

func NewMinHasher

func NewMinHasher(numHashes int) *MinHasher

NewMinHasher creates a MinHasher with numHashes functions (default 128 if invalid).

func (*MinHasher) ComputeSignature

func (m *MinHasher) ComputeSignature(features []string) *MinHashSignature

ComputeSignature computes the MinHash signature for a set of features.

func (*MinHasher) EstimateJaccardSimilarity

func (m *MinHasher) EstimateJaccardSimilarity(sig1, sig2 *MinHashSignature) float64

EstimateJaccardSimilarity estimates Jaccard similarity via signature agreement ratio.

func (*MinHasher) NumHashes

func (m *MinHasher) NumHashes() int

NumHashes returns the number of hash functions.

Jump to

Keyboard shortcuts

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