Hello,
I'm trying to design an TrieSet, that is, an ordered set backed by a trie. I wrote a simple trait for the ordered set abstract data type (but the last two methods are commented out for now):
pub trait OrderedSet<E> {
/// Returns a new instance of `OrderedSet`.
fn new() -> Self;
/// Returns the number elements in the `OrderedSet`.
fn count(&self) -> usize;
/// Returns whether the ordered set contains no elements.
fn is_empty(&self) -> bool;
/// Returns whether the ordered set contains `element`.
fn contains(&self, element: &E) -> bool;
/// Inserts `element` to the ordered set.
/// Returns whether `element` was newly inserted.
fn add(&mut self, element: E) -> bool;
/// Removes `element` from the ordered set.
/// Returns whether `element` was
fn remove(&mut self, element: &E) -> bool;
/// Returns the first element in the ordered set.
fn first(&self) -> Option<&E>;
/// Returns the last element in the ordered set.
fn last(&self) -> Option<&E>;
// /// Returns a iterator pointing to the element right after `element`.
// fn lower_bound(&self, element: E) -> ;
// /// Returns an iterator pointing to the element right before `element`.
// fn upper_bound(&self, element: E) ->;
}
I also think I'm going to have to enforce Ord on E, but that's an issue for later.
The issue I'm facing is that since Tries are optimized for string keys (in this case, I called them elements), I decided to "plug" str inside the angle brackets for my impl block.