https://github.com/BurntSushi/fst
Represent large sets and maps compactly with finite state transducers.
https://github.com/BurntSushi/fst
Last synced: 26 days ago
JSON representation
Represent large sets and maps compactly with finite state transducers.
- Host: GitHub
- URL: https://github.com/BurntSushi/fst
- Owner: BurntSushi
- License: unlicense
- Created: 2015-09-05T00:25:46.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-09-25T20:46:04.000Z (7 months ago)
- Last Synced: 2025-03-18T17:14:05.823Z (28 days ago)
- Language: Rust
- Homepage:
- Size: 2 MB
- Stars: 1,838
- Watchers: 30
- Forks: 130
- Open Issues: 40
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: COPYING
Awesome Lists containing this project
- awesome-rust-cn - BurntSushi/fst - ci.org/BurntSushi/fst.svg?branch=master">](https://travis-ci.org/BurntSushi/fst) (Libraries / Text search)
- awesome-rust - BurntSushi/fst - ci.org/BurntSushi/fst.svg?branch=master">](https://travis-ci.org/BurntSushi/fst) (Libraries / Text search)
- awesome-rust - BurntSushi/fst
- awesome-rust-cn - BurntSushi/fst
- awesome-rust-zh - BurntSushi/fst - [<img src="https://api.travis-ci.org/BurntSushi/fst.svg?branch=master">](https://travis-ci.org/BurntSushi/fst) (库 / 文本搜索)
README
fst
===
This crate provides a fast implementation of ordered sets and maps using finite
state machines. In particular, it makes use of finite state transducers to map
keys to values as the machine is executed. Using finite state machines as data
structures enables us to store keys in a compact format that is also easily
searchable. For example, this crate leverages memory maps to make range queries
very fast.Check out my blog post
[Index 1,600,000,000 Keys with Automata and
Rust](https://blog.burntsushi.net/transducers/)
for extensive background, examples and experiments.[](https://github.com/BurntSushi/fst/actions)
[](https://crates.io/crates/fst)Dual-licensed under MIT or the [UNLICENSE](https://unlicense.org/).
### Documentation
https://docs.rs/fst
The
[`regex-automata`](https://docs.rs/regex-automata)
crate provides implementations of the `fst::Automata` trait when its
`transducer` feature is enabled. This permits using DFAs compiled by
`regex-automata` to search finite state transducers produced by this crate.### Installation
Simply add a corresponding entry to your `Cargo.toml` dependency list:
```toml,ignore
[dependencies]
fst = "0.4"
```### Example
This example demonstrates building a set in memory and executing a fuzzy query
against it. You'll need `fst = "0.4"` with the `levenshtein` feature enabled in
your `Cargo.toml`.```rust
use fst::{IntoStreamer, Set};
use fst::automaton::Levenshtein;fn main() -> Result<(), Box> {
// A convenient way to create sets in memory.
let keys = vec!["fa", "fo", "fob", "focus", "foo", "food", "foul"];
let set = Set::from_iter(keys)?;// Build our fuzzy query.
let lev = Levenshtein::new("foo", 1)?;// Apply our fuzzy query to the set we built.
let stream = set.search(lev).into_stream();let keys = stream.into_strs()?;
assert_eq!(keys, vec!["fo", "fob", "foo", "food"]);
Ok(())
}
```Check out the documentation for a lot more examples!
### Cargo features
* `levenshtein` - **Disabled** by default. This adds the `Levenshtein`
automaton to the `automaton` sub-module. This includes an additional
dependency on `utf8-ranges`.