alg

package
v0.0.0-...-ffc4fba Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: Apache-2.0, Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package alg provides generic algorithm utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectN

func CollectN[T any](iter Iterator[T], limit int) ([]T, error)

CollectN drains up to limit items from iter into a slice. A limit of 0 means unlimited — all items are collected. Returns (nil, nil) when the iterator is already exhausted. Non-EOF errors are returned immediately with a nil slice.

func ForEachPair

func ForEachPair(n int, visit func(i, j int))

ForEachPair calls visit for every unique pair (i, j) where 0 <= i < j < n. The total number of calls is C(n, 2) = n*(n-1)/2. Does nothing when n < 2.

func TraverseTree

func TraverseTree[T any](root T, children func(T) []T, visit func(node T, depth int))

TraverseTree performs an iterative pre-order DFS over a tree. children returns the children of a node; visit is called for each node with its depth (root depth is 0). An empty children slice terminates the branch.

Types

type Iterator

type Iterator[T any] interface {
	Next() (T, error)
	Close()
}

Iterator is a pull-based sequence of T values. Next returns (value, nil) for each item and (zero, io.EOF) when exhausted. Close releases any resources held by the iterator.

type Range

type Range struct {
	Start int // Inclusive index.
	End   int // Exclusive index.
}

Range represents a half-open interval [Start, End).

func Chunk

func Chunk(total, size int) []Range

Chunk splits the range [0, total) into chunks of the given size. The last chunk may be smaller than size. Returns nil when total or size is non-positive.

Directories

Path Synopsis
Package bloom provides a space-efficient probabilistic set membership filter.
Package bloom provides a space-efficient probabilistic set membership filter.
Package cms provides a Count-Min Sketch for frequency estimation.
Package cms provides a Count-Min Sketch for frequency estimation.
Package hll provides a HyperLogLog cardinality estimator.
Package hll provides a HyperLogLog cardinality estimator.
internal
hashutil
Package hashutil provides shared hash mixing constants and functions for probabilistic data structures (Count-Min Sketch, HyperLogLog, MinHash).
Package hashutil provides shared hash mixing constants and functions for probabilistic data structures (Count-Min Sketch, HyperLogLog, MinHash).
Package interval provides an augmented interval tree for efficient range-overlap queries.
Package interval provides an augmented interval tree for efficient range-overlap queries.
Package levenshtein calculates the Levenshtein edit distance between strings.
Package levenshtein calculates the Levenshtein edit distance between strings.
Package lru provides a generic thread-safe LRU cache with optional Bloom pre-filtering, size-based eviction, and cost-aware eviction sampling.
Package lru provides a generic thread-safe LRU cache with optional Bloom pre-filtering, size-based eviction, and cost-aware eviction sampling.
Package lsh provides a Locality-Sensitive Hashing index for fast approximate nearest-neighbor retrieval of MinHash signatures.
Package lsh provides a Locality-Sensitive Hashing index for fast approximate nearest-neighbor retrieval of MinHash signatures.
Package mapx provides generic map operations: clone, merge, and sorted-key extraction.
Package mapx provides generic map operations: clone, merge, and sorted-key extraction.
Package minhash provides MinHash signature generation for set similarity estimation.
Package minhash provides MinHash signature generation for set similarity estimation.
Package stats provides core statistical functions for numerical analysis.
Package stats provides core statistical functions for numerical analysis.

Jump to

Keyboard shortcuts

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