Skip to content

feat: add serialization accessors to BigramFilter#330

Merged
dmtrKovalenko merged 5 commits intodmtrKovalenko:mainfrom
magnusmalm:feat/bigram-filter-accessors
Apr 3, 2026
Merged

feat: add serialization accessors to BigramFilter#330
dmtrKovalenko merged 5 commits intodmtrKovalenko:mainfrom
magnusmalm:feat/bigram-filter-accessors

Conversation

@magnusmalm
Copy link
Copy Markdown
Contributor

Summary

Adds read-only accessors and a from_raw_parts constructor to BigramFilter, enabling external tools to serialize and deserialize the bigram index to/from disk without reaching into private fields.

New public methods:

  • lookup(), dense_data(), words(), dense_count(), populated() — field accessors
  • skip_index() -> Option<&BigramFilter> — sub-index reference
  • from_raw_parts(lookup, dense_data, ...) -> Self — reconstruction from serialized data

This is a purely additive, non-breaking change — no existing code is modified, no new dependencies. All 7 methods are simple one-line accessors/constructors.

Use case

fff-cli is a standalone CLI built on fff-core that persists the bigram index to disk (.fff/bigram.bin) for fast startup. It needs to read the filter's raw data for serialization and reconstruct it on load. Without these accessors, the only alternative is rebuilding the bigram index from scratch on every invocation (~200ms), negating the persistent index advantage.

Test plan

  • Existing tests pass (no code changed, only additions)
  • Verified via fff-cli: index → serialize → deserialize → grep produces correct results on buildroot (13k files)

Add read-only accessors and a from_raw_parts constructor to
BigramFilter, enabling external tools to serialize/deserialize
the bigram index to/from disk without reaching into private fields.

New public methods:
- lookup(), dense_data(), words(), dense_count(), populated()
- skip_index() -> Option<&BigramFilter>
- from_raw_parts(lookup, dense_data, ...) -> Self
Copy link
Copy Markdown
Owner

@dmtrKovalenko dmtrKovalenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice project, I have a few suggestions how to make it even better

Comment thread crates/fff-core/src/bigram_filter.rs Outdated
Comment thread crates/fff-core/src/bigram_filter.rs Outdated
@dmtrKovalenko dmtrKovalenko merged commit b1c4f8e into dmtrKovalenko:main Apr 3, 2026
39 of 40 checks passed
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