@@ -91,7 +91,7 @@ use core::num::Int;
91
91
use core:: slice:: { Items , MutItems } ;
92
92
use core:: { u8, u32, uint} ;
93
93
94
- use hash;
94
+ use core :: hash;
95
95
use Vec ;
96
96
97
97
type Blocks < ' a > = Cloned < Items < ' a , u32 > > ;
@@ -922,7 +922,7 @@ pub fn from_bytes(bytes: &[u8]) -> Bitv {
922
922
923
923
/// Deprecated: Now a static method on Bitv.
924
924
#[ deprecated = "Now a static method on Bitv" ]
925
- pub fn from_fn < F > ( len : uint , mut f : F ) -> Bitv where F : FnMut ( uint ) -> bool {
925
+ pub fn from_fn < F > ( len : uint , f : F ) -> Bitv where F : FnMut ( uint ) -> bool {
926
926
Bitv :: from_fn ( len, f)
927
927
}
928
928
@@ -1226,55 +1226,53 @@ impl BitvSet {
1226
1226
self . bitv . capacity ( )
1227
1227
}
1228
1228
1229
- /// Reserves capacity for an element to be inserted at `index` in the given
1230
- /// `Bitv`. The collection may reserve more space to avoid frequent reallocations.
1229
+ /// Reserves capacity for the given `BitvSet` to contain `len` distinct elements. In the case
1230
+ /// of `BitvSet` this means reallocations will not occur as long as all inserted elements
1231
+ /// are less than `len`.
1231
1232
///
1232
- /// # Panics
1233
+ /// The collection may reserve more space to avoid frequent reallocations.
1233
1234
///
1234
- /// Panics if the new capacity overflows `uint`.
1235
1235
///
1236
1236
/// # Examples
1237
1237
///
1238
1238
/// ```
1239
1239
/// use std::collections::BitvSet;
1240
1240
///
1241
1241
/// let mut s = BitvSet::new();
1242
- /// s.reserve_index (10);
1243
- /// assert!(s.capacity() >= 11 );
1242
+ /// s.reserve_len (10);
1243
+ /// assert!(s.capacity() >= 10 );
1244
1244
/// ```
1245
1245
#[ unstable = "matches collection reform specification, waiting for dust to settle" ]
1246
- pub fn reserve_index ( & mut self , index : uint ) {
1247
- let len = self . bitv . len ( ) ;
1248
- if index >= len {
1249
- self . bitv . reserve ( index - len + 1 ) ;
1246
+ pub fn reserve_len ( & mut self , len : uint ) {
1247
+ let cur_len = self . bitv . len ( ) ;
1248
+ if len >= cur_len {
1249
+ self . bitv . reserve ( len - cur_len ) ;
1250
1250
}
1251
1251
}
1252
1252
1253
- /// Reserves the minimum capacity for an element to be inserted at `index`
1254
- /// in the given `BitvSet`. Does nothing if the capacity is already sufficient.
1253
+ /// Reserves the minimum capacity for the given `BitvSet` to contain `len` distinct elements.
1254
+ /// In the case of `BitvSet` this means reallocations will not occur as long as all inserted
1255
+ /// elements are less than `len`.
1255
1256
///
1256
1257
/// Note that the allocator may give the collection more space than it requests. Therefore
1257
- /// capacity can not be relied upon to be precisely minimal. Prefer `reserve_index ` if future
1258
+ /// capacity can not be relied upon to be precisely minimal. Prefer `reserve_len ` if future
1258
1259
/// insertions are expected.
1259
1260
///
1260
- /// # Panics
1261
- ///
1262
- /// Panics if the new capacity overflows `uint`.
1263
1261
///
1264
1262
/// # Examples
1265
1263
///
1266
1264
/// ```
1267
1265
/// use std::collections::BitvSet;
1268
1266
///
1269
1267
/// let mut s = BitvSet::new();
1270
- /// s.reserve_index_exact (10);
1271
- /// assert!(s.capacity() >= 11 );
1268
+ /// s.reserve_len_exact (10);
1269
+ /// assert!(s.capacity() >= 10 );
1272
1270
/// ```
1273
1271
#[ unstable = "matches collection reform specification, waiting for dust to settle" ]
1274
- pub fn reserve_index_exact ( & mut self , index : uint ) {
1275
- let len = self . bitv . len ( ) ;
1276
- if index >= len {
1277
- self . bitv . reserve_exact ( index - len + 1 ) ;
1272
+ pub fn reserve_len_exact ( & mut self , len : uint ) {
1273
+ let cur_len = self . bitv . len ( ) ;
1274
+ if len >= cur_len {
1275
+ self . bitv . reserve_exact ( len - cur_len ) ;
1278
1276
}
1279
1277
}
1280
1278
@@ -2636,9 +2634,9 @@ mod bitv_set_test {
2636
2634
for & b in bools. iter ( ) {
2637
2635
for & l in lengths. iter ( ) {
2638
2636
let bitset = BitvSet :: from_bitv ( Bitv :: from_elem ( l, b) ) ;
2639
- assert_eq ! ( bitset. contains( & 1 u) , b)
2640
- assert_eq ! ( bitset. contains( & ( l-1 u) ) , b)
2641
- assert ! ( !bitset. contains( & l) )
2637
+ assert_eq ! ( bitset. contains( & 1 u) , b) ;
2638
+ assert_eq ! ( bitset. contains( & ( l-1 u) ) , b) ;
2639
+ assert ! ( !bitset. contains( & l) ) ;
2642
2640
}
2643
2641
}
2644
2642
}
0 commit comments