@@ -253,11 +253,15 @@ pub mod linear {
253
253
}
254
254
255
255
impl < K : Hash IterBytes Eq , V > LinearMap < K , V > : Container {
256
+ /// Return the number of elements in the map
256
257
pure fn len ( & self ) -> uint { self . size }
258
+
259
+ /// Return true if the map contains no elements
257
260
pure fn is_empty ( & self ) -> bool { self . len ( ) == 0 }
258
261
}
259
262
260
263
impl < K : Hash IterBytes Eq , V > LinearMap < K , V > : Mutable {
264
+ /// Clear the map, removing all key-value pairs.
261
265
fn clear ( & mut self ) {
262
266
for uint:: range( 0 , self . buckets. len( ) ) |idx| {
263
267
self . buckets [ idx] = None ;
@@ -267,13 +271,15 @@ pub mod linear {
267
271
}
268
272
269
273
impl < K : Hash IterBytes Eq , V > LinearMap < K , V > : Map < K , V > {
274
+ /// Return true if the map contains a value for the specified key
270
275
pure fn contains_key ( & self , k : & K ) -> bool {
271
276
match self . bucket_for_key ( self . buckets , k) {
272
277
FoundEntry ( _) => { true }
273
278
TableFull | FoundHole ( _) => { false }
274
279
}
275
280
}
276
281
282
+ /// Visit all key-value pairs
277
283
pure fn each ( & self , blk : fn ( k : & K , v : & V ) -> bool ) {
278
284
for vec:: each( self . buckets) |slot| {
279
285
let mut broke = false ;
@@ -286,14 +292,17 @@ pub mod linear {
286
292
}
287
293
}
288
294
295
+ /// Visit all keys
289
296
pure fn each_key ( & self , blk : fn ( k : & K ) -> bool ) {
290
297
self . each ( |k, _v| blk ( k) )
291
298
}
292
299
300
+ /// Visit all values
293
301
pure fn each_value ( & self , blk : fn ( v : & V ) -> bool ) {
294
302
self . each ( |_k, v| blk ( v) )
295
303
}
296
304
305
+ /// Return the value corresponding to the key in the map
297
306
pure fn find ( & self , k : & K ) -> Option < & self /V > {
298
307
match self . bucket_for_key ( self . buckets , k) {
299
308
FoundEntry ( idx) => {
@@ -314,6 +323,9 @@ pub mod linear {
314
323
}
315
324
}
316
325
326
+ /// Insert a key-value pair into the map. An existing value for a
327
+ /// key is replaced by the new value. Return true if the key did
328
+ /// not already exist in the map.
317
329
fn insert ( & mut self , k : K , v : V ) -> bool {
318
330
if self . size >= self . resize_at {
319
331
// n.b.: We could also do this after searching, so
@@ -329,6 +341,8 @@ pub mod linear {
329
341
self . insert_internal ( hash, move k, move v)
330
342
}
331
343
344
+ /// Remove a key-value pair from the map. Return true if the key
345
+ /// was present in the map, otherwise false.
332
346
fn remove ( & mut self , k : & K ) -> bool {
333
347
match self . pop ( k) {
334
348
Some ( _) => true ,
@@ -448,11 +462,15 @@ pub mod linear {
448
462
}
449
463
450
464
impl < T : Hash IterBytes Eq > LinearSet < T > : Container {
465
+ /// Return the number of elements in the set
451
466
pure fn len ( & self ) -> uint { self . map . len ( ) }
467
+
468
+ /// Return true if the set contains no elements
452
469
pure fn is_empty ( & self ) -> bool { self . map . is_empty ( ) }
453
470
}
454
471
455
472
impl < T : Hash IterBytes Eq > LinearSet < T > : Mutable {
473
+ /// Clear the set, removing all values.
456
474
fn clear ( & mut self ) { self . map . clear ( ) }
457
475
}
458
476
0 commit comments