File tree Expand file tree Collapse file tree 3 files changed +50
-0
lines changed
Expand file tree Collapse file tree 3 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,10 @@ mod unique;
44/// Defines the shared interface between the unique list (which is effectively an insert-ordered
55/// Set) and the unique list which supports removals.
66pub trait List {
7+ fn new ( ) -> Self ;
8+ fn with_capacity ( capacity : usize ) -> Self ;
9+ fn len ( & self ) -> usize ;
10+ fn shrink_to_fit ( & mut self ) ;
711 fn append_if_new ( & mut self , item : String ) ;
812 fn merge ( & mut self , other : Self ) ;
913 fn merge_from ( & mut self , other : & Self ) ;
Original file line number Diff line number Diff line change @@ -67,6 +67,30 @@ impl From<RemovableList> for Vec<String> {
6767}
6868
6969impl List for RemovableList {
70+ #[ inline]
71+ fn new ( ) -> Self {
72+ Self :: default ( )
73+ }
74+
75+ #[ inline]
76+ fn with_capacity ( capacity : usize ) -> Self {
77+ Self {
78+ items : Vec :: with_capacity ( capacity) ,
79+ negations : vec ! [ ] ,
80+ }
81+ }
82+
83+ #[ inline]
84+ fn len ( & self ) -> usize {
85+ self . items . len ( )
86+ }
87+
88+ #[ inline]
89+ fn shrink_to_fit ( & mut self ) {
90+ self . items . shrink_to_fit ( ) ;
91+ self . negations . shrink_to_fit ( ) ;
92+ }
93+
7094 /// Appends or removes item from list
7195 ///
7296 /// Regular strings are inserted in the list if they're not present yet. When `item` is
Original file line number Diff line number Diff line change @@ -44,6 +44,28 @@ impl From<UniqueList> for Vec<String> {
4444}
4545
4646impl List for UniqueList {
47+ #[ inline]
48+ fn new ( ) -> Self {
49+ Self :: default ( )
50+ }
51+
52+ #[ inline]
53+ fn with_capacity ( capacity : usize ) -> Self {
54+ Self {
55+ items : Vec :: with_capacity ( capacity) ,
56+ }
57+ }
58+
59+ #[ inline]
60+ fn len ( & self ) -> usize {
61+ self . items . len ( )
62+ }
63+
64+ #[ inline]
65+ fn shrink_to_fit ( & mut self ) {
66+ self . items . shrink_to_fit ( ) ;
67+ }
68+
4769 /// Appends item to list if it's not present yet
4870 fn append_if_new ( & mut self , item : String ) {
4971 if item_pos ( & self . items , & item) . is_none ( ) {
You can’t perform that action at this time.
0 commit comments