@@ -32,9 +32,11 @@ extern crate alloc;
32
32
#[ cfg( test) ] #[ phase( syntax, link) ] extern crate std;
33
33
#[ cfg( test) ] #[ phase( syntax, link) ] extern crate log;
34
34
35
+ use core:: prelude:: * ;
36
+
37
+ pub use core:: collections:: Collection ;
35
38
pub use bitv:: { Bitv , BitvSet } ;
36
39
pub use btree:: BTree ;
37
- pub use deque:: Deque ;
38
40
pub use dlist:: DList ;
39
41
pub use enum_set:: EnumSet ;
40
42
pub use priority_queue:: PriorityQueue ;
@@ -47,7 +49,6 @@ mod macros;
47
49
48
50
pub mod bitv;
49
51
pub mod btree;
50
- pub mod deque;
51
52
pub mod dlist;
52
53
pub mod enum_set;
53
54
pub mod priority_queue;
@@ -64,12 +65,120 @@ pub mod hash;
64
65
// Internal unicode fiddly bits for the str module
65
66
mod unicode;
66
67
67
- // FIXME(#14008) should this actually exist, or should a method be added?
68
- fn expect < T > ( a : core:: option:: Option < T > , b : & str ) -> T {
69
- match a {
70
- core:: option:: Some ( a) => a,
71
- core:: option:: None => fail ! ( "{}" , b) ,
68
+ mod deque;
69
+
70
+ /// A trait to represent mutable containers
71
+ pub trait Mutable : Collection {
72
+ /// Clear the container, removing all values.
73
+ fn clear ( & mut self ) ;
74
+ }
75
+
76
+ /// A map is a key-value store where values may be looked up by their keys. This
77
+ /// trait provides basic operations to operate on these stores.
78
+ pub trait Map < K , V > : Collection {
79
+ /// Return a reference to the value corresponding to the key
80
+ fn find < ' a > ( & ' a self , key : & K ) -> Option < & ' a V > ;
81
+
82
+ /// Return true if the map contains a value for the specified key
83
+ #[ inline]
84
+ fn contains_key ( & self , key : & K ) -> bool {
85
+ self . find ( key) . is_some ( )
86
+ }
87
+ }
88
+
89
+ /// This trait provides basic operations to modify the contents of a map.
90
+ pub trait MutableMap < K , V > : Map < K , V > + Mutable {
91
+ /// Insert a key-value pair into the map. An existing value for a
92
+ /// key is replaced by the new value. Return true if the key did
93
+ /// not already exist in the map.
94
+ #[ inline]
95
+ fn insert ( & mut self , key : K , value : V ) -> bool {
96
+ self . swap ( key, value) . is_none ( )
97
+ }
98
+
99
+ /// Remove a key-value pair from the map. Return true if the key
100
+ /// was present in the map, otherwise false.
101
+ #[ inline]
102
+ fn remove ( & mut self , key : & K ) -> bool {
103
+ self . pop ( key) . is_some ( )
104
+ }
105
+
106
+ /// Insert a key-value pair from the map. If the key already had a value
107
+ /// present in the map, that value is returned. Otherwise None is returned.
108
+ fn swap ( & mut self , k : K , v : V ) -> Option < V > ;
109
+
110
+ /// Removes a key from the map, returning the value at the key if the key
111
+ /// was previously in the map.
112
+ fn pop ( & mut self , k : & K ) -> Option < V > ;
113
+
114
+ /// Return a mutable reference to the value corresponding to the key
115
+ fn find_mut < ' a > ( & ' a mut self , key : & K ) -> Option < & ' a mut V > ;
116
+ }
117
+
118
+ /// A set is a group of objects which are each distinct from one another. This
119
+ /// trait represents actions which can be performed on sets to iterate over
120
+ /// them.
121
+ pub trait Set < T > : Collection {
122
+ /// Return true if the set contains a value
123
+ fn contains ( & self , value : & T ) -> bool ;
124
+
125
+ /// Return true if the set has no elements in common with `other`.
126
+ /// This is equivalent to checking for an empty intersection.
127
+ fn is_disjoint ( & self , other : & Self ) -> bool ;
128
+
129
+ /// Return true if the set is a subset of another
130
+ fn is_subset ( & self , other : & Self ) -> bool ;
131
+
132
+ /// Return true if the set is a superset of another
133
+ fn is_superset ( & self , other : & Self ) -> bool {
134
+ other. is_subset ( self )
72
135
}
136
+
137
+ // FIXME #8154: Add difference, sym. difference, intersection and union iterators
138
+ }
139
+
140
+ /// This trait represents actions which can be performed on sets to mutate
141
+ /// them.
142
+ pub trait MutableSet < T > : Set < T > + Mutable {
143
+ /// Add a value to the set. Return true if the value was not already
144
+ /// present in the set.
145
+ fn insert ( & mut self , value : T ) -> bool ;
146
+
147
+ /// Remove a value from the set. Return true if the value was
148
+ /// present in the set.
149
+ fn remove ( & mut self , value : & T ) -> bool ;
150
+ }
151
+
152
+ /// A double-ended sequence that allows querying, insertion and deletion at both
153
+ /// ends.
154
+ pub trait Deque < T > : Mutable {
155
+ /// Provide a reference to the front element, or None if the sequence is
156
+ /// empty
157
+ fn front < ' a > ( & ' a self ) -> Option < & ' a T > ;
158
+
159
+ /// Provide a mutable reference to the front element, or None if the
160
+ /// sequence is empty
161
+ fn front_mut < ' a > ( & ' a mut self ) -> Option < & ' a mut T > ;
162
+
163
+ /// Provide a reference to the back element, or None if the sequence is
164
+ /// empty
165
+ fn back < ' a > ( & ' a self ) -> Option < & ' a T > ;
166
+
167
+ /// Provide a mutable reference to the back element, or None if the sequence
168
+ /// is empty
169
+ fn back_mut < ' a > ( & ' a mut self ) -> Option < & ' a mut T > ;
170
+
171
+ /// Insert an element first in the sequence
172
+ fn push_front ( & mut self , elt : T ) ;
173
+
174
+ /// Insert an element last in the sequence
175
+ fn push_back ( & mut self , elt : T ) ;
176
+
177
+ /// Remove the last element and return it, or None if the sequence is empty
178
+ fn pop_back ( & mut self ) -> Option < T > ;
179
+
180
+ /// Remove the first element and return it, or None if the sequence is empty
181
+ fn pop_front ( & mut self ) -> Option < T > ;
73
182
}
74
183
75
184
// FIXME(#14344) this shouldn't be necessary
0 commit comments