File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed
branches/try2/src/libcollections Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
5
5
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
7
7
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8
- refs/heads/try2: a698b81ebfe02a614f9b41e68c6b604597a81229
8
+ refs/heads/try2: 7a7ae993ce694bf75a11632b394916e055a4d8ec
9
9
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
10
10
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
11
11
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
Original file line number Diff line number Diff line change @@ -515,9 +515,10 @@ impl BitvSet {
515
515
/// Grows the vector to be able to store bits with indices `[0, size - 1]`
516
516
fn grow ( & mut self , size : uint ) {
517
517
let & BitvSet ( ref mut bitv) = self ;
518
+ let old_size = bitv. storage . len ( ) ;
518
519
let size = ( size + uint:: BITS - 1 ) / uint:: BITS ;
519
- if bitv . storage . len ( ) < size {
520
- bitv. storage . grow ( size, & 0 ) ;
520
+ if old_size < size {
521
+ bitv. storage . grow ( size - old_size , & 0 ) ;
521
522
}
522
523
}
523
524
@@ -1253,14 +1254,22 @@ mod tests {
1253
1254
1254
1255
#[ test]
1255
1256
fn test_bitv_set_basic ( ) {
1257
+ // calculate nbits with uint::BITS granularity
1258
+ fn calc_nbits ( bits : uint ) -> uint {
1259
+ uint:: BITS * ( ( bits + uint:: BITS - 1 ) / uint:: BITS )
1260
+ }
1261
+
1256
1262
let mut b = BitvSet :: new ( ) ;
1263
+ assert_eq ! ( b. capacity( ) , calc_nbits( 0 ) ) ;
1257
1264
assert ! ( b. insert( 3 ) ) ;
1265
+ assert_eq ! ( b. capacity( ) , calc_nbits( 3 ) ) ;
1258
1266
assert ! ( !b. insert( 3 ) ) ;
1259
1267
assert ! ( b. contains( & 3 ) ) ;
1260
1268
assert ! ( b. insert( 4 ) ) ;
1261
1269
assert ! ( !b. insert( 4 ) ) ;
1262
1270
assert ! ( b. contains( & 3 ) ) ;
1263
1271
assert ! ( b. insert( 400 ) ) ;
1272
+ assert_eq ! ( b. capacity( ) , calc_nbits( 400 ) ) ;
1264
1273
assert ! ( !b. insert( 400 ) ) ;
1265
1274
assert ! ( b. contains( & 400 ) ) ;
1266
1275
assert_eq ! ( b. len( ) , 3 ) ;
You can’t perform that action at this time.
0 commit comments