1 // Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
15 #![crate_id = "collections#0.11.0-pre"]
16 #![crate_type = "rlib"]
17 #![license = "MIT/ASL2"]
18 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
19 html_favicon_url = "http://www.rust-lang.org/favicon.ico",
20 html_root_url = "http://doc.rust-lang.org/",
21 html_playground_url = "http://play.rust-lang.org/")]
23 #![feature(macro_rules, managed_boxes, default_type_params, phase, globs)]
29 #[phase(syntax, link)]
33 #[phase(plugin, link)]
36 #[cfg(test)] extern crate native;
37 #[cfg(test)] extern crate test;
38 #[cfg(test)] extern crate debug;
40 #[cfg(test, stage0)] #[phase(syntax, link)] extern crate std;
41 #[cfg(test, stage0)] #[phase(syntax, link)] extern crate log;
42 #[cfg(test, not(stage0))] #[phase(plugin, link)] extern crate std;
43 #[cfg(test, not(stage0))] #[phase(plugin, link)] extern crate log;
47 pub use core::collections::Collection;
48 pub use bitv::{Bitv, BitvSet};
51 pub use enum_set::EnumSet;
52 pub use priority_queue::PriorityQueue;
53 pub use ringbuf::RingBuf;
54 pub use smallintmap::SmallIntMap;
55 pub use string::String;
56 pub use treemap::{TreeMap, TreeSet};
57 pub use trie::{TrieMap, TrieSet};
66 pub mod priority_queue;
77 // Internal unicode fiddly bits for the str module
82 /// A trait to represent mutable containers
83 pub trait Mutable: Collection {
84 /// Clear the container, removing all values.
88 /// A map is a key-value store where values may be looked up by their keys. This
89 /// trait provides basic operations to operate on these stores.
90 pub trait Map<K, V>: Collection {
91 /// Return a reference to the value corresponding to the key
92 fn find<'a>(&'a self, key: &K) -> Option<&'a V>;
94 /// Return true if the map contains a value for the specified key
96 fn contains_key(&self, key: &K) -> bool {
97 self.find(key).is_some()
101 /// This trait provides basic operations to modify the contents of a map.
102 pub trait MutableMap<K, V>: Map<K, V> + Mutable {
103 /// Insert a key-value pair into the map. An existing value for a
104 /// key is replaced by the new value. Return true if the key did
105 /// not already exist in the map.
107 fn insert(&mut self, key: K, value: V) -> bool {
108 self.swap(key, value).is_none()
111 /// Remove a key-value pair from the map. Return true if the key
112 /// was present in the map, otherwise false.
114 fn remove(&mut self, key: &K) -> bool {
115 self.pop(key).is_some()
118 /// Insert a key-value pair from the map. If the key already had a value
119 /// present in the map, that value is returned. Otherwise None is returned.
120 fn swap(&mut self, k: K, v: V) -> Option<V>;
122 /// Removes a key from the map, returning the value at the key if the key
123 /// was previously in the map.
124 fn pop(&mut self, k: &K) -> Option<V>;
126 /// Return a mutable reference to the value corresponding to the key
127 fn find_mut<'a>(&'a mut self, key: &K) -> Option<&'a mut V>;
130 /// A set is a group of objects which are each distinct from one another. This
131 /// trait represents actions which can be performed on sets to iterate over
133 pub trait Set<T>: Collection {
134 /// Return true if the set contains a value
135 fn contains(&self, value: &T) -> bool;
137 /// Return true if the set has no elements in common with `other`.
138 /// This is equivalent to checking for an empty intersection.
139 fn is_disjoint(&self, other: &Self) -> bool;
141 /// Return true if the set is a subset of another
142 fn is_subset(&self, other: &Self) -> bool;
144 /// Return true if the set is a superset of another
145 fn is_superset(&self, other: &Self) -> bool {
146 other.is_subset(self)
149 // FIXME #8154: Add difference, sym. difference, intersection and union iterators
152 /// This trait represents actions which can be performed on sets to mutate
154 pub trait MutableSet<T>: Set<T> + Mutable {
155 /// Add a value to the set. Return true if the value was not already
156 /// present in the set.
157 fn insert(&mut self, value: T) -> bool;
159 /// Remove a value from the set. Return true if the value was
160 /// present in the set.
161 fn remove(&mut self, value: &T) -> bool;
164 /// A double-ended sequence that allows querying, insertion and deletion at both
166 pub trait Deque<T> : Mutable {
167 /// Provide a reference to the front element, or None if the sequence is
169 fn front<'a>(&'a self) -> Option<&'a T>;
171 /// Provide a mutable reference to the front element, or None if the
172 /// sequence is empty
173 fn front_mut<'a>(&'a mut self) -> Option<&'a mut T>;
175 /// Provide a reference to the back element, or None if the sequence is
177 fn back<'a>(&'a self) -> Option<&'a T>;
179 /// Provide a mutable reference to the back element, or None if the sequence
181 fn back_mut<'a>(&'a mut self) -> Option<&'a mut T>;
183 /// Insert an element first in the sequence
184 fn push_front(&mut self, elt: T);
186 /// Insert an element last in the sequence
187 fn push_back(&mut self, elt: T);
189 /// Remove the last element and return it, or None if the sequence is empty
190 fn pop_back(&mut self) -> Option<T>;
192 /// Remove the first element and return it, or None if the sequence is empty
193 fn pop_front(&mut self) -> Option<T>;
196 // FIXME(#14344) this shouldn't be necessary
198 pub fn fixme_14344_be_sure_to_link_to_collections() {}
202 pub use core::fmt; // necessary for fail!()
203 pub use core::option; // necessary for fail!()
204 pub use core::clone; // deriving(Clone)
205 pub use core::cmp; // deriving(Eq, Ord, etc.)
206 pub use hash; // deriving(Hash)