Skip to main content

Crate fst_incremental

Crate fst_incremental 

Source
Expand description

An updatable finite state set.

fst::Set is compact and fast to query but immutable once built. IncrementalFstSet keeps one of those as its persisted component and puts a sorted in-memory mutation buffer in front of it. Inserts and removes land in the buffer; reads merge the two, so a query always reflects the current logical state. When the buffer grows past a configured threshold the two are merged into a fresh FST and the buffer is cleared.

Removal from the persisted component is a tombstone rather than an erasure, which is why deletions have their own rebuild threshold.

§Persistence

This crate performs no file I/O on its own behalf. A set’s full state is two pieces, and writing them is the caller’s job:

Every mutating call returns an FstMutationResult saying which of the two changed, so a caller can skip rewriting the FST when only the buffer moved.

use fst_incremental::{IncrementalFstSet, FstChangeType};

let set = IncrementalFstSet::new(None)?;
set.insert(b"apple".to_vec())?;
set.insert(b"apricot".to_vec())?;
assert!(set.contains(b"apple")?);

set.remove(b"apple")?;
assert!(!set.contains(b"apple")?);

assert_eq!(set.force_rebuild()?.change_type, FstChangeType::FstRebuilt);

§Features

Re-exports§

pub use fst;

Structs§

CompactArenaSet
A memory-efficient, sorted set of byte vectors acting as a unified mutation buffer.
FstConfigOptions
Rebuild thresholds and the initial buffer contents, passed to every constructor.
FstMetricsSnapshot
Cumulative rebuild counters, read via crate::IncrementalFstSet::get_metrics.
FstMutationResult
Returned by every mutating call so the caller can decide what needs persisting.
IncrementalFstSet
A thread-safe set of byte strings that supports insertion and removal.
MergedSetStreamOwner
The self-referencing struct.
SerializableFstBuffers
A point-in-time copy of the mutation buffer, for the caller to serialize.

Enums§

FstChangeType
What a mutation actually did to the set.
IncrementalFstError
Every fallible operation in this crate returns one of these.

Type Aliases§

Result
Shorthand for a result carrying IncrementalFstError.