Skip to content

feat(comparator): Support custom Comparator, defaults to bytewise#35

Merged
alexsnaps merged 2 commits into
mainfrom
comparator
Mar 21, 2026
Merged

feat(comparator): Support custom Comparator, defaults to bytewise#35
alexsnaps merged 2 commits into
mainfrom
comparator

Conversation

@alexsnaps

Copy link
Copy Markdown
Collaborator

Custom comparators are fully implemented and tested.

New file: src/comparator.rs — Comparator trait (compare, name, find_shortest_separator, find_short_successor) + BytewiseComparator default.

Threaded through ~40 sites across 14 files:

  • Options::comparator: Arc<dyn Comparator>
  • cmp_internal_keys — accepts &dyn Comparator
  • SkipList / Memtable — stores comparator, uses it for entry ordering and key lookups
  • Block / BlockIter — comparator for binary search in seek
  • Table — comparator for user-key equality in get
  • TableBuilderfind_shortest_separator for index block separators, find_short_successor for last entry
  • MergingIterator / DbIterator — comparator for merge ordering and direction switching
  • VersionSet — file sorting; VersionEdit encodes/decodes comparator name; recover rejects mismatches
  • TableCache — stores comparator for lazy Table::open
  • All lib.rs free functions — compaction, overlap detection, flush placement

3 new tests (272 total): reverse-bytewise in-memory, reverse-bytewise persistent with reopen, comparator mismatch rejection.

Signed-off-by: Alex Snaps <alex@wcgw.dev>
@alexsnaps alexsnaps merged commit 66046db into main Mar 21, 2026
1 check passed
@alexsnaps alexsnaps deleted the comparator branch March 21, 2026 11:22
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.

1 participant