diff --git a/src/list/mod.rs b/src/list/mod.rs index 6d76bf3..264c5b5 100644 --- a/src/list/mod.rs +++ b/src/list/mod.rs @@ -4,6 +4,10 @@ mod unique; /// Defines the shared interface between the unique list (which is effectively an insert-ordered /// Set) and the unique list which supports removals. pub trait List { + fn new() -> Self; + fn with_capacity(capacity: usize) -> Self; + fn len(&self) -> usize; + fn shrink_to_fit(&mut self); fn append_if_new(&mut self, item: String); fn merge(&mut self, other: Self); fn merge_from(&mut self, other: &Self); diff --git a/src/list/removable.rs b/src/list/removable.rs index ea46d02..e23bb95 100644 --- a/src/list/removable.rs +++ b/src/list/removable.rs @@ -67,6 +67,30 @@ impl From for Vec { } impl List for RemovableList { + #[inline] + fn new() -> Self { + Self::default() + } + + #[inline] + fn with_capacity(capacity: usize) -> Self { + Self { + items: Vec::with_capacity(capacity), + negations: vec![], + } + } + + #[inline] + fn len(&self) -> usize { + self.items.len() + } + + #[inline] + fn shrink_to_fit(&mut self) { + self.items.shrink_to_fit(); + self.negations.shrink_to_fit(); + } + /// Appends or removes item from list /// /// Regular strings are inserted in the list if they're not present yet. When `item` is diff --git a/src/list/unique.rs b/src/list/unique.rs index 4de8e9d..8f57e04 100644 --- a/src/list/unique.rs +++ b/src/list/unique.rs @@ -44,6 +44,28 @@ impl From for Vec { } impl List for UniqueList { + #[inline] + fn new() -> Self { + Self::default() + } + + #[inline] + fn with_capacity(capacity: usize) -> Self { + Self { + items: Vec::with_capacity(capacity), + } + } + + #[inline] + fn len(&self) -> usize { + self.items.len() + } + + #[inline] + fn shrink_to_fit(&mut self) { + self.items.shrink_to_fit(); + } + /// Appends item to list if it's not present yet fn append_if_new(&mut self, item: String) { if item_pos(&self.items, &item).is_none() {