Documentation
¶
Index ¶
- Variables
- type AGMConfig
- type AGMEdge
- type AGMInput
- type AGMOutput
- type AGMSketch
- func (a *AGMSketch) HealthCheck(ctx context.Context) error
- func (a *AGMSketch) InputType() reflect.Type
- func (a *AGMSketch) Metrics() []eval.MetricDefinition
- func (a *AGMSketch) Name() string
- func (a *AGMSketch) OutputType() reflect.Type
- func (a *AGMSketch) Process(ctx context.Context, snapshot crs.Snapshot, input any) (any, crs.Delta, error)
- func (a *AGMSketch) ProgressInterval() time.Duration
- func (a *AGMSketch) Properties() []eval.Property
- func (a *AGMSketch) SupportsPartialResults() bool
- func (a *AGMSketch) Timeout() time.Duration
- type AGMState
- type AlgorithmError
- type CountMin
- func (c *CountMin) HealthCheck(ctx context.Context) error
- func (c *CountMin) InputType() reflect.Type
- func (c *CountMin) Metrics() []eval.MetricDefinition
- func (c *CountMin) Name() string
- func (c *CountMin) OutputType() reflect.Type
- func (c *CountMin) Process(ctx context.Context, snapshot crs.Snapshot, input any) (any, crs.Delta, error)
- func (c *CountMin) ProgressInterval() time.Duration
- func (c *CountMin) Properties() []eval.Property
- func (c *CountMin) SupportsPartialResults() bool
- func (c *CountMin) Timeout() time.Duration
- type CountMinConfig
- type CountMinInput
- type CountMinItem
- type CountMinOutput
- type CountMinSketch
- type HLLState
- type HyperLogLog
- func (h *HyperLogLog) HealthCheck(ctx context.Context) error
- func (h *HyperLogLog) InputType() reflect.Type
- func (h *HyperLogLog) Metrics() []eval.MetricDefinition
- func (h *HyperLogLog) Name() string
- func (h *HyperLogLog) OutputType() reflect.Type
- func (h *HyperLogLog) Process(ctx context.Context, snapshot crs.Snapshot, input any) (any, crs.Delta, error)
- func (h *HyperLogLog) ProgressInterval() time.Duration
- func (h *HyperLogLog) Properties() []eval.Property
- func (h *HyperLogLog) SupportsPartialResults() bool
- func (h *HyperLogLog) Timeout() time.Duration
- type HyperLogLogConfig
- type HyperLogLogInput
- type HyperLogLogOutput
- type L0Config
- type L0Input
- type L0Level
- type L0Output
- type L0Sample
- type L0Sampling
- func (l *L0Sampling) HealthCheck(ctx context.Context) error
- func (l *L0Sampling) InputType() reflect.Type
- func (l *L0Sampling) Metrics() []eval.MetricDefinition
- func (l *L0Sampling) Name() string
- func (l *L0Sampling) OutputType() reflect.Type
- func (l *L0Sampling) Process(ctx context.Context, snapshot crs.Snapshot, input any) (any, crs.Delta, error)
- func (l *L0Sampling) ProgressInterval() time.Duration
- func (l *L0Sampling) Properties() []eval.Property
- func (l *L0Sampling) SupportsPartialResults() bool
- func (l *L0Sampling) Timeout() time.Duration
- type L0State
- type L0Update
- type LSH
- func (l *LSH) HealthCheck(ctx context.Context) error
- func (l *LSH) InputType() reflect.Type
- func (l *LSH) Metrics() []eval.MetricDefinition
- func (l *LSH) Name() string
- func (l *LSH) OutputType() reflect.Type
- func (l *LSH) Process(ctx context.Context, snapshot crs.Snapshot, input any) (any, crs.Delta, error)
- func (l *LSH) ProgressInterval() time.Duration
- func (l *LSH) Properties() []eval.Property
- func (l *LSH) SupportsPartialResults() bool
- func (l *LSH) Timeout() time.Duration
- type LSHConfig
- type LSHIndex
- type LSHInput
- type LSHOutput
- type MinHash
- func (m *MinHash) HealthCheck(ctx context.Context) error
- func (m *MinHash) InputType() reflect.Type
- func (m *MinHash) Metrics() []eval.MetricDefinition
- func (m *MinHash) Name() string
- func (m *MinHash) OutputType() reflect.Type
- func (m *MinHash) Process(ctx context.Context, snapshot crs.Snapshot, input any) (any, crs.Delta, error)
- func (m *MinHash) ProgressInterval() time.Duration
- func (m *MinHash) Properties() []eval.Property
- func (m *MinHash) SupportsPartialResults() bool
- func (m *MinHash) Timeout() time.Duration
- type MinHashConfig
- type MinHashInput
- type MinHashOutput
- type MinHashSignature
- type WLConfig
- type WLGraph
- type WLInput
- type WLOutput
- type WeisfeilerLeman
- func (w *WeisfeilerLeman) HealthCheck(ctx context.Context) error
- func (w *WeisfeilerLeman) InputType() reflect.Type
- func (w *WeisfeilerLeman) Metrics() []eval.MetricDefinition
- func (w *WeisfeilerLeman) Name() string
- func (w *WeisfeilerLeman) OutputType() reflect.Type
- func (w *WeisfeilerLeman) Process(ctx context.Context, snapshot crs.Snapshot, input any) (any, crs.Delta, error)
- func (w *WeisfeilerLeman) ProgressInterval() time.Duration
- func (w *WeisfeilerLeman) Properties() []eval.Property
- func (w *WeisfeilerLeman) SupportsPartialResults() bool
- func (w *WeisfeilerLeman) Timeout() time.Duration
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidInput = errors.New("invalid input") ErrInvalidConfig = errors.New("invalid config") )
Package-level error definitions.
Functions ¶
This section is empty.
Types ¶
type AGMConfig ¶
type AGMConfig struct {
// NumLevels is the number of sampling levels (log n).
NumLevels int
// Width is the width of the sketch at each level.
Width int
// MaxVertices is the maximum number of vertices supported.
MaxVertices int
// Timeout is the maximum execution time.
Timeout time.Duration
// ProgressInterval is how often to report progress.
ProgressInterval time.Duration
}
AGMConfig configures the AGM sketch algorithm.
func DefaultAGMConfig ¶
func DefaultAGMConfig() *AGMConfig
DefaultAGMConfig returns the default configuration.
type AGMInput ¶
type AGMInput struct {
// Operation specifies what to do: "add", "delete", "query", or "merge".
Operation string
// Edges are the edges to add or delete.
Edges []AGMEdge
// Sketch is an existing AGM sketch.
Sketch *AGMState
// OtherSketch is another sketch to merge with.
OtherSketch *AGMState
// Source indicates where the request originated.
Source crs.SignalSource
}
AGMInput is the input for AGM sketch operations.
type AGMOutput ¶
type AGMOutput struct {
// Sketch is the resulting AGM sketch state.
Sketch *AGMState
// Components is the estimated number of connected components.
Components int
// SpanningEdges are the recovered spanning forest edges.
SpanningEdges []AGMEdge
// EdgesProcessed is the number of edges processed.
EdgesProcessed int
}
AGMOutput is the output from AGM sketch operations.
type AGMSketch ¶
type AGMSketch struct {
// contains filtered or unexported fields
}
AGMSketch implements the AGM (Ahn-Guha-McGregor) sketch for graph connectivity.
Description:
AGM Sketch estimates graph connectivity properties (connected components, spanning forest) using linear sketching. It uses random projections to compress edge information while preserving connectivity. Key Properties: - Space: O(n polylog n) for n vertices - Supports edge insertions and deletions - Mergeable: Multiple sketches can be combined - Recovers spanning forest with high probability Use Cases: - Track code module connectivity - Detect isolated components - Monitor dependency graph changes - Streaming graph analysis
Thread Safety: Safe for concurrent use.
func NewAGMSketch ¶
NewAGMSketch creates a new AGM sketch algorithm.
func (*AGMSketch) HealthCheck ¶
HealthCheck verifies the algorithm is functioning.
func (*AGMSketch) Metrics ¶
func (a *AGMSketch) Metrics() []eval.MetricDefinition
Metrics returns the metrics this algorithm exposes.
func (*AGMSketch) OutputType ¶
OutputType returns the output type.
func (*AGMSketch) Process ¶
func (a *AGMSketch) Process(ctx context.Context, snapshot crs.Snapshot, input any) (any, crs.Delta, error)
Process executes the AGM sketch operation.
Description:
Supports four operations: - "add": Add edges to the sketch - "delete": Delete edges from the sketch - "query": Query connectivity information - "merge": Merge two sketches
Thread Safety: Safe for concurrent use.
func (*AGMSketch) ProgressInterval ¶
ProgressInterval returns how often to report progress.
func (*AGMSketch) Properties ¶
Properties returns the correctness properties.
func (*AGMSketch) SupportsPartialResults ¶
SupportsPartialResults returns true.
type AGMState ¶
type AGMState struct {
// Levels holds sketches at each sampling level.
// levels[i] is sampled with probability 2^(-i).
Levels [][]int64
// VertexMap maps vertex IDs to internal indices.
VertexMap map[string]int
// NextVertex is the next available vertex index.
NextVertex int
// NumLevels is the number of levels.
NumLevels int
// Width is the width at each level.
Width int
// EdgeCount is the number of edges added.
EdgeCount int64
// Seeds for hash functions.
Seeds []uint64
}
AGMState is the internal AGM sketch state.
type AlgorithmError ¶
AlgorithmError wraps algorithm-specific errors.
func (*AlgorithmError) Error ¶
func (e *AlgorithmError) Error() string
type CountMin ¶
type CountMin struct {
// contains filtered or unexported fields
}
CountMin implements the Count-Min Sketch for frequency estimation.
Description:
Count-Min Sketch is a probabilistic data structure that serves as a frequency table. It uses multiple hash functions and a 2D array to estimate the frequency of elements in a stream. Key Properties: - Space: O(w * d) where w = width, d = depth - Query time: O(d) - Never underestimates frequency - Overestimate bounded by epsilon with probability 1-delta Use Cases: - Track symbol access frequencies - Estimate code change hotspots - Identify frequently modified files - Stream-based statistics
Thread Safety: Safe for concurrent use.
func NewCountMin ¶
func NewCountMin(config *CountMinConfig) *CountMin
NewCountMin creates a new Count-Min sketch algorithm.
func (*CountMin) HealthCheck ¶
HealthCheck verifies the algorithm is functioning.
func (*CountMin) Metrics ¶
func (c *CountMin) Metrics() []eval.MetricDefinition
Metrics returns the metrics this algorithm exposes.
func (*CountMin) OutputType ¶
OutputType returns the output type.
func (*CountMin) Process ¶
func (c *CountMin) Process(ctx context.Context, snapshot crs.Snapshot, input any) (any, crs.Delta, error)
Process executes the Count-Min operation.
Description:
Supports three operations: - "add": Add items to the sketch - "query": Query frequencies of items - "merge": Merge another sketch into this one
Thread Safety: Safe for concurrent use.
func (*CountMin) ProgressInterval ¶
ProgressInterval returns how often to report progress.
func (*CountMin) Properties ¶
Properties returns the correctness properties.
func (*CountMin) SupportsPartialResults ¶
SupportsPartialResults returns true.
type CountMinConfig ¶
type CountMinConfig struct {
// Width is the number of buckets per row.
Width int
// Depth is the number of hash functions (rows).
Depth int
// Epsilon is the error bound (affects width: w = ceil(e/epsilon)).
Epsilon float64
// Delta is the failure probability (affects depth: d = ceil(ln(1/delta))).
Delta float64
// Timeout is the maximum execution time.
Timeout time.Duration
// ProgressInterval is how often to report progress.
ProgressInterval time.Duration
}
CountMinConfig configures the Count-Min sketch.
func DefaultCountMinConfig ¶
func DefaultCountMinConfig() *CountMinConfig
DefaultCountMinConfig returns the default configuration.
type CountMinInput ¶
type CountMinInput struct {
// Operation specifies what to do: "add", "query", or "merge".
Operation string
// Items are the elements to add (for "add" operation).
Items []CountMinItem
// Queries are the elements to query frequencies for (for "query" operation).
Queries []string
// Sketch is an existing sketch to merge (for "merge" operation).
Sketch *CountMinSketch
// Source indicates where the request originated.
Source crs.SignalSource
}
CountMinInput is the input for Count-Min operations.
type CountMinItem ¶
CountMinItem represents an item with a count.
type CountMinOutput ¶
type CountMinOutput struct {
// Sketch is the resulting sketch state.
Sketch *CountMinSketch
// Frequencies maps queried keys to their estimated frequencies.
Frequencies map[string]int64
// ItemsProcessed is the number of items processed.
ItemsProcessed int
// TotalCount is the sum of all counts in the sketch.
TotalCount int64
}
CountMinOutput is the output from Count-Min operations.
type CountMinSketch ¶
type CountMinSketch struct {
// Table is the 2D count matrix [depth][width].
Table [][]int64
// Width is the number of columns.
Width int
// Depth is the number of rows (hash functions).
Depth int
// Seeds are the hash function seeds.
Seeds []uint64
// Total is the sum of all added counts.
Total int64
}
CountMinSketch is the internal sketch data structure.
type HLLState ¶
type HLLState struct {
// Registers hold the max leading zeros for each bucket.
Registers []uint8
// Precision is the number of bits for indexing.
Precision int
// Count is the number of items added.
Count uint64
}
HLLState is the internal HyperLogLog state.
type HyperLogLog ¶
type HyperLogLog struct {
// contains filtered or unexported fields
}
HyperLogLog implements the HyperLogLog cardinality estimation algorithm.
Description:
HyperLogLog estimates the cardinality (number of distinct elements) of a multiset using a small, fixed amount of memory. It uses the harmonic mean of register values based on leading zero counts. Key Properties: - Space: O(m) where m = 2^precision - Standard error: 1.04/sqrt(m) - Mergeable: Multiple HLLs can be merged Use Cases: - Count unique symbols in codebase - Estimate number of unique callers - Track distinct file accesses - Approximate set cardinality
Thread Safety: Safe for concurrent use.
func NewHyperLogLog ¶
func NewHyperLogLog(config *HyperLogLogConfig) *HyperLogLog
NewHyperLogLog creates a new HyperLogLog algorithm.
func (*HyperLogLog) HealthCheck ¶
func (h *HyperLogLog) HealthCheck(ctx context.Context) error
HealthCheck verifies the algorithm is functioning.
func (*HyperLogLog) InputType ¶
func (h *HyperLogLog) InputType() reflect.Type
InputType returns the expected input type.
func (*HyperLogLog) Metrics ¶
func (h *HyperLogLog) Metrics() []eval.MetricDefinition
Metrics returns the metrics this algorithm exposes.
func (*HyperLogLog) OutputType ¶
func (h *HyperLogLog) OutputType() reflect.Type
OutputType returns the output type.
func (*HyperLogLog) Process ¶
func (h *HyperLogLog) Process(ctx context.Context, snapshot crs.Snapshot, input any) (any, crs.Delta, error)
Process executes the HyperLogLog operation.
Description:
Supports three operations: - "add": Add items to the HLL - "count": Estimate cardinality - "merge": Merge two HLLs
Thread Safety: Safe for concurrent use.
func (*HyperLogLog) ProgressInterval ¶
func (h *HyperLogLog) ProgressInterval() time.Duration
ProgressInterval returns how often to report progress.
func (*HyperLogLog) Properties ¶
func (h *HyperLogLog) Properties() []eval.Property
Properties returns the correctness properties.
func (*HyperLogLog) SupportsPartialResults ¶
func (h *HyperLogLog) SupportsPartialResults() bool
SupportsPartialResults returns true.
func (*HyperLogLog) Timeout ¶
func (h *HyperLogLog) Timeout() time.Duration
Timeout returns the maximum execution time.
type HyperLogLogConfig ¶
type HyperLogLogConfig struct {
// Precision is the number of bits for register indexing (4-18).
// Higher precision = more accuracy but more memory.
// Memory usage = 2^precision bytes.
Precision int
// Timeout is the maximum execution time.
Timeout time.Duration
// ProgressInterval is how often to report progress.
ProgressInterval time.Duration
}
HyperLogLogConfig configures the HyperLogLog algorithm.
func DefaultHyperLogLogConfig ¶
func DefaultHyperLogLogConfig() *HyperLogLogConfig
DefaultHyperLogLogConfig returns the default configuration.
type HyperLogLogInput ¶
type HyperLogLogInput struct {
// Operation specifies what to do: "add", "count", or "merge".
Operation string
// Items are the elements to add (for "add" operation).
Items []string
// HLL is an existing HyperLogLog state (for "count" or "merge").
HLL *HLLState
// OtherHLL is another HLL to merge with (for "merge").
OtherHLL *HLLState
// Source indicates where the request originated.
Source crs.SignalSource
}
HyperLogLogInput is the input for HyperLogLog operations.
type HyperLogLogOutput ¶
type HyperLogLogOutput struct {
// HLL is the resulting HyperLogLog state.
HLL *HLLState
// Cardinality is the estimated number of distinct elements.
Cardinality uint64
// ItemsProcessed is the number of items processed.
ItemsProcessed int
// StandardError is the estimated relative standard error.
StandardError float64
}
HyperLogLogOutput is the output from HyperLogLog operations.
type L0Config ¶
type L0Config struct {
// NumLevels is the number of sampling levels.
NumLevels int
// NumSamples is the number of samples to maintain.
NumSamples int
// MaxItems is the maximum number of distinct items.
MaxItems int
// Timeout is the maximum execution time.
Timeout time.Duration
// ProgressInterval is how often to report progress.
ProgressInterval time.Duration
}
L0Config configures the L0 sampling algorithm.
func DefaultL0Config ¶
func DefaultL0Config() *L0Config
DefaultL0Config returns the default configuration.
type L0Input ¶
type L0Input struct {
// Operation specifies what to do: "update", "sample", or "merge".
Operation string
// Updates are the items to update (for "update" operation).
Updates []L0Update
// State is an existing L0 sampling state.
State *L0State
// OtherState is another state to merge with.
OtherState *L0State
// Source indicates where the request originated.
Source crs.SignalSource
}
L0Input is the input for L0 sampling operations.
type L0Level ¶
type L0Level struct {
// Samples holds the current samples at this level.
Samples map[string]int64
// Count is the number of items that hashed to this level.
Count int64
}
L0Level is a single level of the L0 sampler.
type L0Output ¶
type L0Output struct {
// State is the resulting L0 sampling state.
State *L0State
// Samples are the sampled items.
Samples []L0Sample
// UpdatesProcessed is the number of updates processed.
UpdatesProcessed int
// NonZeroEstimate is the estimated number of non-zero entries.
NonZeroEstimate int64
}
L0Output is the output from L0 sampling operations.
type L0Sampling ¶
type L0Sampling struct {
// contains filtered or unexported fields
}
L0Sampling implements L0 sampling for sparse recovery.
Description:
L0 Sampling uniformly samples from the non-zero entries of a sparse vector in a streaming setting. It uses multiple levels of sampling with geometric probabilities to achieve uniform sampling. Key Properties: - Space: O(k log^2 n) for k samples from n possible entries - Supports updates (increment/decrement) - Returns uniform samples from non-zero entries - Works with turnstile streams (positive and negative updates) Use Cases: - Sample active code paths - Random symbol selection - Sparse feature recovery - Approximate distinct sampling
Thread Safety: Safe for concurrent use.
func NewL0Sampling ¶
func NewL0Sampling(config *L0Config) *L0Sampling
NewL0Sampling creates a new L0 sampling algorithm.
func (*L0Sampling) HealthCheck ¶
func (l *L0Sampling) HealthCheck(ctx context.Context) error
HealthCheck verifies the algorithm is functioning.
func (*L0Sampling) InputType ¶
func (l *L0Sampling) InputType() reflect.Type
InputType returns the expected input type.
func (*L0Sampling) Metrics ¶
func (l *L0Sampling) Metrics() []eval.MetricDefinition
Metrics returns the metrics this algorithm exposes.
func (*L0Sampling) OutputType ¶
func (l *L0Sampling) OutputType() reflect.Type
OutputType returns the output type.
func (*L0Sampling) Process ¶
func (l *L0Sampling) Process(ctx context.Context, snapshot crs.Snapshot, input any) (any, crs.Delta, error)
Process executes the L0 sampling operation.
Description:
Supports three operations: - "update": Apply updates to the sampler - "sample": Get current samples - "merge": Merge two samplers
Thread Safety: Safe for concurrent use.
func (*L0Sampling) ProgressInterval ¶
func (l *L0Sampling) ProgressInterval() time.Duration
ProgressInterval returns how often to report progress.
func (*L0Sampling) Properties ¶
func (l *L0Sampling) Properties() []eval.Property
Properties returns the correctness properties.
func (*L0Sampling) SupportsPartialResults ¶
func (l *L0Sampling) SupportsPartialResults() bool
SupportsPartialResults returns true.
func (*L0Sampling) Timeout ¶
func (l *L0Sampling) Timeout() time.Duration
Timeout returns the maximum execution time.
type L0State ¶
type L0State struct {
// Levels holds the sampling state at each level.
// Each level samples with probability 2^(-level).
Levels []L0Level
// NumLevels is the number of levels.
NumLevels int
// NumSamples is the number of samples to maintain.
NumSamples int
// Seeds for hash functions.
Seeds []uint64
// TotalUpdates is the total number of updates applied.
TotalUpdates int64
}
L0State is the internal L0 sampling state.
type LSH ¶
type LSH struct {
// contains filtered or unexported fields
}
LSH implements Locality-Sensitive Hashing for approximate nearest neighbor search.
Description:
LSH hashes similar items into the same buckets with high probability. It uses banding technique with MinHash signatures to find candidate pairs with similarity above a threshold. Key Properties: - Sublinear query time for approximate nearest neighbors - Tunable threshold via bands (b) and rows (r) parameters - Threshold ≈ (1/b)^(1/r) for b bands of r rows each Use Cases: - Find similar code snippets - Near-duplicate detection - Clustering similar symbols - Code search acceleration
Thread Safety: Safe for concurrent use.
func (*LSH) HealthCheck ¶
HealthCheck verifies the algorithm is functioning.
func (*LSH) Metrics ¶
func (l *LSH) Metrics() []eval.MetricDefinition
Metrics returns the metrics this algorithm exposes.
func (*LSH) OutputType ¶
OutputType returns the output type.
func (*LSH) Process ¶
func (l *LSH) Process(ctx context.Context, snapshot crs.Snapshot, input any) (any, crs.Delta, error)
Process executes the LSH operation.
Description:
Supports three operations: - "index": Add a signature to the index - "query": Find candidates similar to a signature - "candidates": Get all candidate pairs from the index
Thread Safety: Safe for concurrent use.
func (*LSH) ProgressInterval ¶
ProgressInterval returns how often to report progress.
func (*LSH) Properties ¶
Properties returns the correctness properties.
func (*LSH) SupportsPartialResults ¶
SupportsPartialResults returns true.
type LSHConfig ¶
type LSHConfig struct {
// NumBands is the number of bands to split the signature into.
NumBands int
// RowsPerBand is the number of rows per band.
RowsPerBand int
// SignatureSize is the total signature size (NumBands * RowsPerBand).
SignatureSize int
// Threshold is the similarity threshold for candidate pairs.
Threshold float64
// MaxCandidates limits the number of candidates returned.
MaxCandidates int
// Timeout is the maximum execution time.
Timeout time.Duration
// ProgressInterval is how often to report progress.
ProgressInterval time.Duration
}
LSHConfig configures the LSH algorithm.
func DefaultLSHConfig ¶
func DefaultLSHConfig() *LSHConfig
DefaultLSHConfig returns the default configuration.
type LSHIndex ¶
type LSHIndex struct {
// Buckets maps band hashes to item IDs.
// buckets[bandIdx][bandHash] = []itemID
Buckets []map[uint64][]string
// Signatures stores the full signatures for similarity verification.
Signatures map[string]*MinHashSignature
// NumBands is the number of bands.
NumBands int
// RowsPerBand is the rows per band.
RowsPerBand int
// ItemCount is the number of indexed items.
ItemCount int
}
LSHIndex is the LSH index structure.
type LSHInput ¶
type LSHInput struct {
// Operation specifies what to do: "index", "query", or "candidates".
Operation string
// ID is the identifier for the item being indexed.
ID string
// Signature is the MinHash signature to index or query.
Signature *MinHashSignature
// Index is an existing LSH index (for "query" or "index" operations).
Index *LSHIndex
// Source indicates where the request originated.
Source crs.SignalSource
}
LSHInput is the input for LSH operations.
type LSHOutput ¶
type LSHOutput struct {
// Index is the resulting LSH index.
Index *LSHIndex
// Candidates are the IDs of potential similar items.
Candidates []string
// CandidateCount is the number of candidates found.
CandidateCount int
// BucketsUsed is the number of buckets with items.
BucketsUsed int
}
LSHOutput is the output from LSH operations.
type MinHash ¶
type MinHash struct {
// contains filtered or unexported fields
}
MinHash implements the MinHash algorithm for set similarity estimation.
Description:
MinHash generates a compact signature for a set that can be used to estimate Jaccard similarity. The probability that two sets have the same MinHash value equals their Jaccard similarity. Key Properties: - Space: O(k) per signature where k = number of hash functions - Similarity estimate: fraction of matching MinHash values - Error bound: O(1/sqrt(k)) Use Cases: - Find similar code files - Detect near-duplicate functions - Cluster related symbols - Code clone detection
Thread Safety: Safe for concurrent use.
func NewMinHash ¶
func NewMinHash(config *MinHashConfig) *MinHash
NewMinHash creates a new MinHash algorithm.
func (*MinHash) HealthCheck ¶
HealthCheck verifies the algorithm is functioning.
func (*MinHash) Metrics ¶
func (m *MinHash) Metrics() []eval.MetricDefinition
Metrics returns the metrics this algorithm exposes.
func (*MinHash) OutputType ¶
OutputType returns the output type.
func (*MinHash) Process ¶
func (m *MinHash) Process(ctx context.Context, snapshot crs.Snapshot, input any) (any, crs.Delta, error)
Process executes the MinHash operation.
Description:
Supports three operations: - "signature": Compute MinHash signature for a set - "similarity": Estimate Jaccard similarity between two signatures - "merge": Merge two signatures (union of sets)
Thread Safety: Safe for concurrent use.
func (*MinHash) ProgressInterval ¶
ProgressInterval returns how often to report progress.
func (*MinHash) Properties ¶
Properties returns the correctness properties.
func (*MinHash) SupportsPartialResults ¶
SupportsPartialResults returns true.
type MinHashConfig ¶
type MinHashConfig struct {
// NumHashes is the number of hash functions (signature size).
NumHashes int
// Timeout is the maximum execution time.
Timeout time.Duration
// ProgressInterval is how often to report progress.
ProgressInterval time.Duration
}
MinHashConfig configures the MinHash algorithm.
func DefaultMinHashConfig ¶
func DefaultMinHashConfig() *MinHashConfig
DefaultMinHashConfig returns the default configuration.
type MinHashInput ¶
type MinHashInput struct {
// Operation specifies what to do: "signature", "similarity", or "merge".
Operation string
// Set is the set elements to compute signature for (for "signature").
Set []string
// Signature is an existing signature (for "similarity" or "merge").
Signature *MinHashSignature
// OtherSignature is another signature to compare/merge with.
OtherSignature *MinHashSignature
// Source indicates where the request originated.
Source crs.SignalSource
}
MinHashInput is the input for MinHash operations.
type MinHashOutput ¶
type MinHashOutput struct {
// Signature is the computed MinHash signature.
Signature *MinHashSignature
// Similarity is the estimated Jaccard similarity (for "similarity").
Similarity float64
// ItemsProcessed is the number of set elements processed.
ItemsProcessed int
}
MinHashOutput is the output from MinHash operations.
type MinHashSignature ¶
type MinHashSignature struct {
// Values are the minimum hash values for each hash function.
Values []uint64
// NumHashes is the number of hash functions used.
NumHashes int
// Coefficients are the hash function parameters (a, b pairs).
Coefficients []uint64
// SetSize is the original set size.
SetSize int
}
MinHashSignature is the MinHash signature for a set.
type WLConfig ¶
type WLConfig struct {
// MaxIterations is the maximum number of refinement iterations.
MaxIterations int
// EarlyStop enables stopping when coloring stabilizes.
EarlyStop bool
// MaxNodes limits the number of nodes to process.
MaxNodes int
// Timeout is the maximum execution time.
Timeout time.Duration
// ProgressInterval is how often to report progress.
ProgressInterval time.Duration
}
WLConfig configures the Weisfeiler-Leman algorithm.
func DefaultWLConfig ¶
func DefaultWLConfig() *WLConfig
DefaultWLConfig returns the default configuration.
type WLGraph ¶
type WLGraph struct {
// Nodes are the vertex IDs.
Nodes []string
// Edges maps each node to its neighbors.
Edges map[string][]string
// NodeLabels are optional vertex labels.
NodeLabels map[string]string
}
WLGraph represents a graph for WL processing.
type WLInput ¶
type WLInput struct {
// Operation specifies what to do: "color", "compare", or "fingerprint".
Operation string
// Graph is the graph to process.
Graph *WLGraph
// OtherGraph is another graph to compare with (for "compare").
OtherGraph *WLGraph
// InitialColors are optional initial vertex colors.
InitialColors map[string]uint64
// Source indicates where the request originated.
Source crs.SignalSource
}
WLInput is the input for Weisfeiler-Leman operations.
type WLOutput ¶
type WLOutput struct {
// Colors maps each vertex to its final color.
Colors map[string]uint64
// ColorHistogram counts vertices per color.
ColorHistogram map[uint64]int
// Fingerprint is a canonical fingerprint for the graph.
Fingerprint uint64
// IsIsomorphic is whether two graphs could be isomorphic (for "compare").
IsIsomorphic bool
// IterationsUsed is the number of refinement iterations.
IterationsUsed int
// ColorClasses is the number of distinct colors.
ColorClasses int
// Stabilized is true if coloring stabilized before max iterations.
Stabilized bool
}
WLOutput is the output from Weisfeiler-Leman operations.
type WeisfeilerLeman ¶
type WeisfeilerLeman struct {
// contains filtered or unexported fields
}
WeisfeilerLeman implements the Weisfeiler-Leman graph isomorphism test.
Description:
The Weisfeiler-Leman (WL) algorithm iteratively refines vertex colors based on neighborhood structure. After k iterations, vertices with the same color have isomorphic k-hop neighborhoods. Key Properties: - Time: O(k * (V + E) log V) for k iterations - Produces graph fingerprint (canonical coloring) - Can distinguish most non-isomorphic graphs - Fails only on pathological cases (e.g., certain regular graphs) Use Cases: - Detect structurally equivalent code patterns - Graph similarity via color histograms - Code structure canonicalization - Pattern matching in AST/CFG
Thread Safety: Safe for concurrent use.
func NewWeisfeilerLeman ¶
func NewWeisfeilerLeman(config *WLConfig) *WeisfeilerLeman
NewWeisfeilerLeman creates a new Weisfeiler-Leman algorithm.
func (*WeisfeilerLeman) HealthCheck ¶
func (w *WeisfeilerLeman) HealthCheck(ctx context.Context) error
HealthCheck verifies the algorithm is functioning.
func (*WeisfeilerLeman) InputType ¶
func (w *WeisfeilerLeman) InputType() reflect.Type
InputType returns the expected input type.
func (*WeisfeilerLeman) Metrics ¶
func (w *WeisfeilerLeman) Metrics() []eval.MetricDefinition
Metrics returns the metrics this algorithm exposes.
func (*WeisfeilerLeman) Name ¶
func (w *WeisfeilerLeman) Name() string
Name returns the algorithm name.
func (*WeisfeilerLeman) OutputType ¶
func (w *WeisfeilerLeman) OutputType() reflect.Type
OutputType returns the output type.
func (*WeisfeilerLeman) Process ¶
func (w *WeisfeilerLeman) Process(ctx context.Context, snapshot crs.Snapshot, input any) (any, crs.Delta, error)
Process executes the Weisfeiler-Leman operation.
Description:
Supports three operations: - "color": Compute stable vertex coloring - "compare": Compare two graphs for potential isomorphism - "fingerprint": Compute canonical graph fingerprint
Thread Safety: Safe for concurrent use.
func (*WeisfeilerLeman) ProgressInterval ¶
func (w *WeisfeilerLeman) ProgressInterval() time.Duration
ProgressInterval returns how often to report progress.
func (*WeisfeilerLeman) Properties ¶
func (w *WeisfeilerLeman) Properties() []eval.Property
Properties returns the correctness properties.
func (*WeisfeilerLeman) SupportsPartialResults ¶
func (w *WeisfeilerLeman) SupportsPartialResults() bool
SupportsPartialResults returns true.
func (*WeisfeilerLeman) Timeout ¶
func (w *WeisfeilerLeman) Timeout() time.Duration
Timeout returns the maximum execution time.