Struct fst::Map [] [src]

pub struct Map(_);

Methods

impl Map
[src]

fn from_file_path<P: AsRef<Path>>(path: P) -> Result<Self>

Opens a map stored at the given file path via a memory map.

The map must have been written with a compatible finite state transducer builder (MapBuilder qualifies). If the format is invalid or if there is a mismatch between the API version of this library and the map, then an error is returned.

fn from_bytes(bytes: Vec<u8>) -> Result<Self>

Creates a map from its representation as a raw byte sequence.

Note that this operation is very cheap (no allocations and no copies).

The map must have been written with a compatible finite state transducer builder (MapBuilder qualifies). If the format is invalid or if there is a mismatch between the API version of this library and the map, then an error is returned.

fn from_iter<K, I>(iter: I) -> Result<Self> where K: AsRef<[u8]>, I: IntoIterator<Item=(K, u64)>

Create a Map from an iterator of lexicographically ordered byte strings and associated values.

If the iterator does not yield unique keys in lexicographic order, then an error is returned.

Note that this is a convenience function to build a map in memory. To build a map that streams to an arbitrary io::Write, use MapBuilder.

fn stream(&self) -> MapStream

fn stream_keys(&self) -> SetStream

Return a lexicographically ordered stream of all keys in this map.

While this is a stream, it does require heap space proportional to the longest key in the map.

If the map is memory mapped, then no further heap space is needed. Note though that your operating system may fill your page cache (which will cause the resident memory usage of the process to go up correspondingly).

Example

Since streams are not iterators, the traditional for loop cannot be used. while let is useful instead:

use fst::{IntoStream, Stream, Map};

let map = Map::from_iter(vec![("a", 1), ("b", 2), ("c", 3)]).unwrap();
let mut stream = map.into_stream();

let mut kvs = vec![];
while let Some((k, v)) = stream.next() {
    kvs.push((k.to_vec(), v));
}
assert_eq!(kvs, vec![
    ("a".as_bytes().to_vec(), 1),
    ("b".as_bytes().to_vec(), 2),
    ("c".as_bytes().to_vec(), 3),
]);

fn range(&self) -> MapStreamBuilder

fn contains<K: AsRef<[u8]>>(&self, key: K) -> bool

Tests the membership of a single key.

Example

use fst::Map;

let map = Map::from_iter(vec![("a", 1), ("b", 2), ("c", 3)]).unwrap();

assert_eq!(map.contains("b"), true);
assert_eq!(map.contains("z"), false);

fn search<A: Automaton>(&self, aut: A) -> MapStreamBuilder<A>

fn len(&self) -> usize

Returns the number of elements in this map.

fn is_empty(&self) -> bool

Returns true if and only if this map is empty.

fn op(&self) -> MapOpBuilder

fn is_disjoint<'f, I, S>(&self, stream: I) -> bool where I: for<'a> IntoStream<'a, Into=S, Item=&'a [u8]>, S: 'f + for<'a> Stream<'a, Item=&'a [u8]>

fn is_subset<'f, I, S>(&self, stream: I) -> bool where I: for<'a> IntoStream<'a, Into=S, Item=&'a [u8]>, S: 'f + for<'a> Stream<'a, Item=&'a [u8]>

fn is_superset<'f, I, S>(&self, stream: I) -> bool where I: for<'a> IntoStream<'a, Into=S, Item=&'a [u8]>, S: 'f + for<'a> Stream<'a, Item=&'a [u8]>

Trait Implementations

impl Debug for Map
[src]

fn fmt(&self, f: &mut Formatter) -> Result

Formats the value using the given formatter.

impl AsRef<Fst> for Map
[src]

Returns the underlying finite state transducer.

fn as_ref(&self) -> &Fst

Performs the conversion.

impl<'s, 'a> IntoStream<'a> for &'s Map
[src]

type Item = (&'a [u8], u64)

The type of the item emitted by the stream.

type Into = MapStream<'s>

The type of the stream to be constructed.

fn into_stream(self) -> Self::Into

Construct a stream from Self.