Crate symbol_map [] [src]

Provides fast mapping of arbitrary values to symbolic identifiers.

The mapping to symbols is stored in the Table type, which retains ownership of the values being mapped. Any type that implements SymbolId may be used as a symbol. Impls are provided for Rust's default unsigned integer types.

Fast bidirectional lookup on top of a Table is provided by the indexing package, through the Indexing trait. For convenience, a HashMap-backed index is provided in HashIndexing.


use symbol_map::indexing::{HashIndexing,Indexing};
use std::str::FromStr;

let mut pos_index = HashIndexing::<String, usize>::default();
let s1 = String::from_str("NNP").unwrap();
let s2 = String::from_str("VBD").unwrap();
let s3 = String::from_str("NNP").unwrap();

// We lose ownership of values passed to get_or_insert, so we pass in
// clones of our data.
    // The value returned by get_or_inset tells us whether a new association
    // was inserted, but we just unwrap it here. The resulting association
    // has a borrow of the index and its underlying symbol table, so we
    // restrict assoc to this inner scope in order to make additional
    // insertions below.
    let assoc = pos_index.get_or_insert(s1.clone()).unwrap();
    assert!(* == 0);
    assert!( == &s1);
    assert!( == &s3);
// Look up the values we just inserted.
let assoc1 = pos_index.get(&s1).unwrap();
let assoc2 = pos_index.get(&s2).unwrap();
let assoc3 = pos_index.get(&s3).unwrap();
assert!( == &s1);
assert!( == &s3);
assert!(* == 0);
assert!(* == 1);
assert!(* == 0);
assert!(assoc1 != assoc2);
assert!(assoc1 == assoc3);



Indexing on top of a Table.



A table entry that associates an instance of T with an atomic symbol.


The head of a linked list associating Ts with SymbolIds. SymbolId values start at 0 and increase by 1 for each T added to the table.


Iterator that consumes a table.


Iterator over table contents.



An atomic ID.