8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- /*!
12
- * A simple map based on a vector for small integer keys. Space requirements
13
- * are O(highest integer key).
14
- */
11
+ //! A simple map based on a vector for small integer keys. Space requirements
12
+ //! are O(highest integer key).
15
13
16
14
#![ allow( missing_doc) ]
17
15
@@ -32,12 +30,12 @@ pub struct SmallIntMap<T> {
32
30
}
33
31
34
32
impl < V > Collection for SmallIntMap < V > {
35
- /// Return the number of elements in the map
33
+ /// Return the number of elements in the map.
36
34
fn len ( & self ) -> uint {
37
35
self . v . iter ( ) . filter ( |elt| elt. is_some ( ) ) . count ( )
38
36
}
39
37
40
- /// Return true if there are no elements in the map
38
+ /// Return ` true` if there are no elements in the map.
41
39
fn is_empty ( & self ) -> bool {
42
40
self . v . iter ( ) . all ( |elt| elt. is_none ( ) )
43
41
}
@@ -49,7 +47,7 @@ impl<V> Mutable for SmallIntMap<V> {
49
47
}
50
48
51
49
impl < V > Map < uint , V > for SmallIntMap < V > {
52
- /// Return a reference to the value corresponding to the key
50
+ /// Return a reference to the value corresponding to the key.
53
51
fn find < ' a > ( & ' a self , key : & uint ) -> Option < & ' a V > {
54
52
if * key < self . v . len ( ) {
55
53
match * self . v . get ( * key) {
@@ -63,7 +61,7 @@ impl<V> Map<uint, V> for SmallIntMap<V> {
63
61
}
64
62
65
63
impl < V > MutableMap < uint , V > for SmallIntMap < V > {
66
- /// Return a mutable reference to the value corresponding to the key
64
+ /// Return a mutable reference to the value corresponding to the key.
67
65
fn find_mut < ' a > ( & ' a mut self , key : & uint ) -> Option < & ' a mut V > {
68
66
if * key < self . v . len ( ) {
69
67
match * self . v . get_mut ( * key) {
@@ -76,7 +74,7 @@ impl<V> MutableMap<uint, V> for SmallIntMap<V> {
76
74
}
77
75
78
76
/// Insert a key-value pair into the map. An existing value for a
79
- /// key is replaced by the new value. Return true if the key did
77
+ /// key is replaced by the new value. Return ` true` if the key did
80
78
/// not already exist in the map.
81
79
fn insert ( & mut self , key : uint , value : V ) -> bool {
82
80
let exists = self . contains_key ( & key) ;
@@ -88,14 +86,14 @@ impl<V> MutableMap<uint, V> for SmallIntMap<V> {
88
86
!exists
89
87
}
90
88
91
- /// Remove a key-value pair from the map. Return true if the key
92
- /// was present in the map, otherwise false.
89
+ /// Remove a key-value pair from the map. Return ` true` if the key
90
+ /// was present in the map, otherwise ` false` .
93
91
fn remove ( & mut self , key : & uint ) -> bool {
94
92
self . pop ( key) . is_some ( )
95
93
}
96
94
97
95
/// Insert a key-value pair from the map. If the key already had a value
98
- /// present in the map, that value is returned. Otherwise None is returned.
96
+ /// present in the map, that value is returned. Otherwise ` None` is returned.
99
97
fn swap ( & mut self , key : uint , value : V ) -> Option < V > {
100
98
match self . find_mut ( & key) {
101
99
Some ( loc) => { return Some ( replace ( loc, value) ) ; }
@@ -121,10 +119,10 @@ impl<V> Default for SmallIntMap<V> {
121
119
}
122
120
123
121
impl < V > SmallIntMap < V > {
124
- /// Create an empty SmallIntMap
122
+ /// Create an empty SmallIntMap.
125
123
pub fn new ( ) -> SmallIntMap < V > { SmallIntMap { v : vec ! ( ) } }
126
124
127
- /// Create an empty SmallIntMap with capacity `capacity`
125
+ /// Create an empty SmallIntMap with capacity `capacity`.
128
126
pub fn with_capacity ( capacity : uint ) -> SmallIntMap < V > {
129
127
SmallIntMap { v : Vec :: with_capacity ( capacity) }
130
128
}
@@ -134,7 +132,7 @@ impl<V> SmallIntMap<V> {
134
132
}
135
133
136
134
/// An iterator visiting all key-value pairs in ascending order by the keys.
137
- /// Iterator element type is (uint, &'r V)
135
+ /// Iterator element type is ` (uint, &'r V)`.
138
136
pub fn iter < ' r > ( & ' r self ) -> Entries < ' r , V > {
139
137
Entries {
140
138
front : 0 ,
@@ -145,7 +143,7 @@ impl<V> SmallIntMap<V> {
145
143
146
144
/// An iterator visiting all key-value pairs in ascending order by the keys,
147
145
/// with mutable references to the values
148
- /// Iterator element type is (uint, &'r mut V)
146
+ /// Iterator element type is ` (uint, &'r mut V)`.
149
147
pub fn mut_iter < ' r > ( & ' r mut self ) -> MutEntries < ' r , V > {
150
148
MutEntries {
151
149
front : 0 ,
@@ -154,7 +152,7 @@ impl<V> SmallIntMap<V> {
154
152
}
155
153
}
156
154
157
- /// Empties the hash map, moving all values into the specified closure
155
+ /// Empties the hash map, moving all values into the specified closure.
158
156
pub fn move_iter ( & mut self )
159
157
-> FilterMap < ( uint , Option < V > ) , ( uint , V ) ,
160
158
Enumerate < vec:: MoveItems < Option < V > > > >
0 commit comments