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:
- the FST bytes, from
IncrementalFstSet::persisted_fst_as_bytes - the pending mutations, from
IncrementalFstSet::buffers_snapshot
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
serde(default): derivesSerializeandDeserializeonSerializableFstBuffersandCompactArenaSetso the buffer can be persisted with a format of your choosing.
Re-exports§
pub use fst;
Structs§
- Compact
Arena Set - A memory-efficient, sorted set of byte vectors acting as a unified mutation buffer.
- FstConfig
Options - Rebuild thresholds and the initial buffer contents, passed to every constructor.
- FstMetrics
Snapshot - Cumulative rebuild counters, read via
crate::IncrementalFstSet::get_metrics. - FstMutation
Result - Returned by every mutating call so the caller can decide what needs persisting.
- Incremental
FstSet - A thread-safe set of byte strings that supports insertion and removal.
- Merged
SetStream Owner - The self-referencing struct.
- Serializable
FstBuffers - A point-in-time copy of the mutation buffer, for the caller to serialize.
Enums§
- FstChange
Type - What a mutation actually did to the set.
- Incremental
FstError - Every fallible operation in this crate returns one of these.
Type Aliases§
- Result
- Shorthand for a result carrying
IncrementalFstError.