pub mod bijective;
pub mod bloom_filter;
pub mod char_unit;
pub mod dawg_core;
pub mod node_signature;
pub mod sync_compat;
pub mod dat_core;
pub mod difference_zipper;
pub mod double_array_trie;
pub mod double_array_trie_char;
pub mod double_array_trie_char_zipper;
pub mod double_array_trie_zipper;
pub mod dynamic_dawg;
pub mod dynamic_dawg_char;
pub mod dynamic_dawg_char_zipper;
pub mod dynamic_dawg_u64;
pub mod dynamic_dawg_u64_zipper;
pub mod dynamic_dawg_zipper;
pub mod excluding_prefix_zipper;
pub mod factory;
pub mod intersection_zipper;
pub mod iterator;
#[cfg(feature = "pathmap-backend")]
pub mod pathmap;
#[cfg(feature = "pathmap-backend")]
pub mod pathmap_char;
#[cfg(feature = "pathmap-backend")]
pub mod pathmap_zipper;
#[cfg(feature = "persistent-artrie")]
pub mod artrie_trait;
#[cfg(feature = "persistent-artrie")]
pub mod persistent_artrie;
#[cfg(feature = "persistent-artrie")]
pub mod persistent_artrie_char;
#[cfg(feature = "persistent-artrie")]
pub mod persistent_artrie_core;
#[cfg(feature = "persistent-artrie")]
pub mod persistent_vocab_artrie;
pub mod prefix_zipper;
pub mod scdawg;
pub mod scdawg_char;
pub mod scdawg_core;
pub mod substring;
pub mod suffix_automaton;
pub mod suffix_automaton_char;
pub mod suffix_automaton_char_zipper;
pub mod suffix_automaton_core;
pub mod suffix_automaton_zipper;
pub mod symmetric_difference_zipper;
pub mod union_zipper;
pub mod value;
pub mod value_diff_zipper;
pub mod zipper;
#[cfg(feature = "serialization")]
pub mod serialization;
pub use bijective::{BijectiveDictionary, BijectiveMap, InsertError};
pub use bloom_filter::BloomFilter;
pub use char_unit::CharUnit;
pub use dawg_core::{DawgCore, DawgNode};
pub use iterator::{DictionaryIterator, DictionaryTermIterator};
pub use node_signature::NodeSignature;
pub use substring::{
BidirectionalDictionaryNode, ExtensionResult, SubstringDictionary, SubstringMatch,
};
pub use value::DictionaryValue;
pub use zipper::{DictZipper, ValuedDictZipper};
#[cfg(feature = "persistent-artrie")]
pub use artrie_trait::{ARTrie, EvictableARTrie};
#[cfg(feature = "persistent-artrie")]
#[allow(deprecated)]
pub use artrie_trait::ARTrieAtomicOps;
#[cfg(feature = "persistent-artrie")]
pub use persistent_artrie::wal::Lsn;
#[cfg(feature = "persistent-artrie")]
pub use persistent_artrie::{
PersistentARTrie, PersistentARTrieZipper, RecoveryMode, RecoveryReport, WalConfig,
};
#[cfg(feature = "persistent-artrie")]
pub use persistent_artrie_char::{
PersistentARTrieChar, PersistentARTrieCharNode, PersistentARTrieCharZipper,
};
#[cfg(feature = "persistent-artrie")]
pub use persistent_vocab_artrie::{IndexedVocabularyPersistent, PersistentVocabARTrie};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SyncStrategy {
ExternalSync,
InternalSync,
Persistent,
}
pub trait Dictionary {
type Node: DictionaryNode;
fn root(&self) -> Self::Node;
fn contains(&self, term: &str) -> bool {
let mut node = self.root();
for unit in <Self::Node as DictionaryNode>::Unit::iter_str(term) {
match node.transition(unit) {
Some(next) => node = next,
None => return false,
}
}
node.is_final()
}
fn len(&self) -> Option<usize>;
fn is_empty(&self) -> bool {
self.len().map(|n| n == 0).unwrap_or(false)
}
fn sync_strategy(&self) -> SyncStrategy {
SyncStrategy::ExternalSync
}
fn is_suffix_based(&self) -> bool {
false
}
}
pub trait DictionaryNode: Clone + Send + Sync {
type Unit: CharUnit;
fn is_final(&self) -> bool;
fn transition(&self, label: Self::Unit) -> Option<Self>;
fn edges(&self) -> Box<dyn Iterator<Item = (Self::Unit, Self)> + '_>;
fn has_edge(&self, label: Self::Unit) -> bool {
self.transition(label).is_some()
}
fn edge_count(&self) -> Option<usize> {
None
}
}
pub trait MappedDictionary: Dictionary {
type Value: DictionaryValue;
fn get_value(&self, term: &str) -> Option<Self::Value>;
fn contains_with_value<F>(&self, term: &str, predicate: F) -> bool
where
F: Fn(&Self::Value) -> bool,
{
self.get_value(term).is_some_and(|v| predicate(&v))
}
}
pub trait MappedDictionaryNode: DictionaryNode {
type Value: DictionaryValue;
fn value(&self) -> Option<Self::Value>;
}
pub trait MutableDictionary: Dictionary {
fn insert(&self, term: &str) -> bool;
fn remove(&self, term: &str) -> bool;
fn extend<I, S>(&self, terms: I) -> usize
where
I: IntoIterator<Item = S>,
S: AsRef<str>,
{
terms
.into_iter()
.filter(|term| self.insert(term.as_ref()))
.count()
}
fn remove_many<I, S>(&self, terms: I) -> usize
where
I: IntoIterator<Item = S>,
S: AsRef<str>,
{
terms
.into_iter()
.filter(|term| self.remove(term.as_ref()))
.count()
}
}
pub trait CompactableDictionary: MutableDictionary {
fn needs_compaction(&self) -> bool;
fn compact(&self) -> usize;
fn minimize(&self) -> usize {
self.compact()
}
}
pub trait MutableMappedDictionary: MappedDictionary {
fn insert_with_value(&self, term: &str, value: Self::Value) -> bool;
fn union_with<F>(&self, other: &Self, merge_fn: F) -> usize
where
F: Fn(&Self::Value, &Self::Value) -> Self::Value,
Self::Value: Clone;
fn union_replace(&self, other: &Self) -> usize
where
Self::Value: Clone,
{
self.union_with(other, |_, right| right.clone())
}
fn update_or_insert<F>(&self, term: &str, default_value: Self::Value, update_fn: F) -> bool
where
F: FnOnce(&mut Self::Value);
}
pub mod prelude {
pub use crate::{
BijectiveDictionary, BijectiveMap, CharUnit, CompactableDictionary, DictZipper, Dictionary,
DictionaryNode, DictionaryValue, InsertError, MappedDictionary, MappedDictionaryNode,
MutableDictionary, MutableMappedDictionary, SyncStrategy, ValuedDictZipper,
};
pub use crate::double_array_trie::DoubleArrayTrie;
pub use crate::double_array_trie_char::DoubleArrayTrieChar;
pub use crate::dynamic_dawg::DynamicDawg;
pub use crate::dynamic_dawg_char::DynamicDawgChar;
pub use crate::dynamic_dawg_u64::DynamicDawgU64;
pub use crate::scdawg::Scdawg;
pub use crate::scdawg_char::ScdawgChar;
pub use crate::suffix_automaton::SuffixAutomaton;
pub use crate::suffix_automaton_char::SuffixAutomatonChar;
}