fst_incremental 1.0.0

A thread-safe, updatable finite state set: dynamic insertions, deletions and queries over an immutable fst::Set fronted by a compact mutation buffer with amortized rebuilds.
Documentation
//! 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);
//! # Ok::<(), fst_incremental::IncrementalFstError>(())
//! ```
//!
//! # Features
//!
//! - `serde` (default): derives `Serialize` and `Deserialize` on [`SerializableFstBuffers`]
//!   and [`CompactArenaSet`] so the buffer can be persisted with a format of your choosing.

#[cfg(doctest)]
#[doc = include_str!("../README.md")]
struct Readme;

#[cfg(all(doctest, feature = "serde"))]
#[doc = include_str!("../README.USAGE.md")]
struct UsageGuide;

pub use fst;

mod arena;
mod error;
mod inner;
mod metrics;
mod set;
mod stream;
mod types;

pub use arena::CompactArenaSet;
pub use error::{IncrementalFstError, Result};
pub use metrics::FstMetricsSnapshot;
pub use set::IncrementalFstSet;
pub use stream::MergedSetStreamOwner;
pub use types::{FstChangeType, FstConfigOptions, FstMutationResult, SerializableFstBuffers};