Feature: Introduce k-mer distance and SIMD LCS logic

Introduces k-mer distance structures and SIMD implementation for LCS simulation.

Adds support for concurrent, read-only k-mer partners, implements data preparation for SIMD alignment, and adds comprehensive testing and benchmarking capabilities.
This commit is contained in:
Eric Coissac committed 2026-11-03 09:24:00 +11:00
1 parent a0d8187fd6
commit f76e7f03c6
6 files changed
+190 -144

No files matched your search

+32
View File
@@ -97,6 +97,38 @@ func KmerLCSBatch(query uint64, partners []uint64, k int, out []KmerLCSResult) b
return true
}
// KmerLCSPartners is a fixed set of k-mers prepared once to be aligned against
// many queries with KmerLCSBatch-like speed, without redoing the per-call
// reorganisation of the partners. It is read-only after creation and can be
// shared between goroutines.
type KmerLCSPartners struct {
prepared kmerLCSPrepared
n int
}
// NewKmerLCSPartners prepares partners for repeated alignment.
// It returns nil if k is not between 1 and 31. The slice is not copied when
// built without GOEXPERIMENT=simd, so it must not be modified afterwards.
func NewKmerLCSPartners(partners []uint64, k int) *KmerLCSPartners {
if k < 1 || k > 31 {
return nil
}
return &KmerLCSPartners{prepared: prepareKmerLCS(partners, k), n: len(partners)}
}
// Len returns the number of prepared partners.
func (p *KmerLCSPartners) Len() int { return p.n }
// Align computes the alignment of query against every prepared partner and
// stores it in out. It returns false if out is shorter than Len().
func (p *KmerLCSPartners) Align(query uint64, out []KmerLCSResult) bool {
if len(out) < p.n {
return false
}
p.prepared.align(query, out[:p.n])
return true
}
func kmerLCSBatchScalar(query uint64, partners []uint64, k int, out []KmerLCSResult) {
for i, p := range partners {
out[i] = KmerLCS(query, p, k)