cs431_homework/
adt.rs

1use crossbeam_epoch::Guard;
2
3/// Trait for a concurrent key-value map.
4pub trait ConcurrentMap<K: ?Sized, V> {
5    /// Lookups the given key to get the reference to its value.
6    fn lookup<'a>(&'a self, key: &K, guard: &'a Guard) -> Option<&'a V>;
7
8    /// Inserts a key-value pair.
9    fn insert(&self, key: K, value: V, guard: &Guard) -> Result<(), V>;
10
11    /// Deletes the given key and returns a reference to its value.
12    ///
13    /// Unlike stack or queue's pop that can return `Option<V>`, since a `delete`d
14    /// value may also be `lookup`ed, we can only return a reference, not full ownership.
15    fn delete<'a>(&'a self, key: &K, guard: &'a Guard) -> Result<&'a V, ()>;
16}
17
18/// Trait for a concurrent set.
19pub trait ConcurrentSet<T> {
20    /// Returns `true` iff the set contains the value.
21    fn contains(&self, value: &T) -> bool;
22
23    /// Adds the value to the set. Returns whether the value was newly inserted.
24    fn insert(&self, value: T) -> bool;
25
26    /// Removes the value from the set. Returns whether the value was present in the set.
27    fn remove(&self, value: &T) -> bool;
28}