

HnswSearchScratch
- Namespace
- Rowles.LeanLucene.Codecs.Hnsw
- Assembly
- Rowles.LeanLucene.dll
Reusable scratch buffers for one HNSW SearchLayer traversal. Borrow via
Borrow(), dispose to return. A single instance per thread is held in
System.ThreadStaticAttribute storage so steady-state queries avoid
repeated System.Collections.Generic.HashSet`1 and System.Collections.Generic.PriorityQueue`2
allocations. Concurrent searches on the same thread (e.g. nested calls) fall back
to a fresh allocation; only the outermost borrow uses the cached instance.
internal sealed class HnswSearchScratch : IDisposable
Fields
Properties
Frontier
Min-heap of frontier candidates by distance ascending.
Results
Max-heap of result candidates by distance descending, capped at ef.
Visited
Visited node set, cleared on borrow.
Methods
Borrow()
Borrow the per-thread scratch. If it is already in use (a nested search on the same thread), a fresh instance is returned that bypasses the cache slot.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.