Skip to content

Conversation

@CoreyKaylor
Copy link
Owner

Adds 12 built-in, allocation-free IComparer implementations for custom key sorting and duplicate comparison.

New comparers in LightningDB.Comparers namespace:

Comparer Description
BitwiseComparer Lexicographic byte comparison (memcmp-style)
ReverseBitwiseComparer Lexicographic descending
SignedIntegerComparer int/long with proper negative ordering
ReverseSignedIntegerComparer Signed integer descending
UnsignedIntegerComparer uint/ulong (matches MDB_INTEGERKEY)
ReverseUnsignedIntegerComparer Unsigned integer descending
Utf8StringComparer Ordinal UTF-8 comparison
ReverseUtf8StringComparer UTF-8 descending
LengthComparer Length first, then content
ReverseLengthComparer Reverse length, then content
LengthOnlyComparer Size only, ignores content
HashCodeComparer Hash-based for fast large value comparison

Usage:
var config = new DatabaseConfiguration { Flags = DatabaseOpenFlags.Create };
config.CompareWith(SignedIntegerComparer.Instance);

Design:

  • Singleton pattern via Instance property
  • Zero allocations in comparison hot path using Span and MemoryMarshal
  • Works with existing CompareWith() / FindDuplicatesWith() API
  • No new dependencies

@CoreyKaylor CoreyKaylor merged commit 8ebf7f8 into main Dec 12, 2025
3 checks passed
@CoreyKaylor CoreyKaylor deleted the sorting branch December 12, 2025 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants