chisel_stringtable/common.rs
1//! Common traits, types etc...
2
3use std::borrow::Cow;
4
5/// Trait defining the basic operations required by a string table
6pub trait StringTable<'a, Key : PartialOrd + Copy>
7{
8 /// Add a new value to the string table. Returns the [u32] hash value
9 /// of the entry. If the entry already exists within the table, then
10 /// this operation is idempotent, but the hash value is still returned.
11 fn add(&mut self, value : &str) -> Key;
12
13 /// Attempts to remove a given value from the table.
14 fn remove(&mut self, key: Key) -> ();
15
16 /// Attempts to retrieve a given value from the table.
17 fn get(&self, key : Key) -> Option<&Cow<'a, str>>;
18
19 /// The number of elements currently within the table
20 fn len(&self) -> usize;
21
22 /// Check whether a given value already exists within the table. If it does, then
23 /// return the hash value associated with it. If not, just return None.
24 fn contains(&self, value : &str) -> Option<u64>;
25
26 /// Get the hash value associated with a given value. This should be consistent and
27 /// repeatable between calls for the same value.
28 fn hash(&self, value : &str) -> u64;
29
30}