Skip to content

Commit f8863d9

Browse files
committed
---
yaml --- r: 137678 b: refs/heads/auto c: 6beddcf h: refs/heads/master v: v3
1 parent 6f7314a commit f8863d9

File tree

37 files changed

+96
-247
lines changed

37 files changed

+96
-247
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: 79d056f94b75e1c9ad5d72bd8081d6aa5e323848
16+
refs/heads/auto: 6beddcfd830d1450d5e82b4bcb05d30ee459a8b1
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/libarena/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#![license = "MIT/ASL2"]
2727
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
2828
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
29-
html_root_url = "http://doc.rust-lang.org/0.12.0/")]
29+
html_root_url = "http://doc.rust-lang.org/master/")]
3030

3131
#![feature(unsafe_destructor)]
3232
#![allow(missing_doc)]

branches/auto/src/libcollections/bitv.rs

Lines changed: 57 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -235,20 +235,11 @@ impl Bitv {
235235
/// }
236236
/// ```
237237
pub fn with_capacity(nbits: uint, init: bool) -> Bitv {
238-
let mut bitv = Bitv {
238+
Bitv {
239239
storage: Vec::from_elem((nbits + uint::BITS - 1) / uint::BITS,
240240
if init { !0u } else { 0u }),
241241
nbits: nbits
242-
};
243-
244-
// Zero out any unused bits in the highest word if necessary
245-
let used_bits = bitv.nbits % uint::BITS;
246-
if init && used_bits != 0 {
247-
let largest_used_word = (bitv.nbits + uint::BITS - 1) / uint::BITS - 1;
248-
*bitv.storage.get_mut(largest_used_word) &= (1 << used_bits) - 1;
249242
}
250-
251-
bitv
252243
}
253244

254245
/// Retrieves the value at index `i`.
@@ -638,9 +629,9 @@ impl Bitv {
638629
/// ```
639630
pub fn reserve(&mut self, size: uint) {
640631
let old_size = self.storage.len();
641-
let new_size = (size + uint::BITS - 1) / uint::BITS;
642-
if old_size < new_size {
643-
self.storage.grow(new_size - old_size, 0);
632+
let size = (size + uint::BITS - 1) / uint::BITS;
633+
if old_size < size {
634+
self.storage.grow(size - old_size, 0);
644635
}
645636
}
646637

@@ -695,15 +686,8 @@ impl Bitv {
695686
}
696687
// Allocate new words, if needed
697688
if new_nwords > self.storage.len() {
698-
let to_add = new_nwords - self.storage.len();
699-
self.storage.grow(to_add, full_value);
700-
701-
// Zero out and unused bits in the new tail word
702-
if value {
703-
let tail_word = new_nwords - 1;
704-
let used_bits = new_nbits % uint::BITS;
705-
*self.storage.get_mut(tail_word) &= (1 << used_bits) - 1;
706-
}
689+
let to_add = new_nwords - self.storage.len();
690+
self.storage.grow(to_add, full_value);
707691
}
708692
// Adjust internal bit count
709693
self.nbits = new_nbits;
@@ -986,8 +970,9 @@ impl<'a> RandomAccessIterator<bool> for Bits<'a> {
986970
/// }
987971
///
988972
/// // Can convert back to a `Bitv`
989-
/// let bv: Bitv = s.into_bitv();
990-
/// assert!(bv.get(3));
973+
/// let bv: Bitv = s.unwrap();
974+
/// assert!(bv.eq_vec([true, true, false, true,
975+
/// false, false, false, false]));
991976
/// ```
992977
#[deriving(Clone)]
993978
pub struct BitvSet(Bitv);
@@ -1008,8 +993,7 @@ impl FromIterator<bool> for BitvSet {
1008993
impl Extendable<bool> for BitvSet {
1009994
#[inline]
1010995
fn extend<I: Iterator<bool>>(&mut self, iterator: I) {
1011-
let &BitvSet(ref mut self_bitv) = self;
1012-
self_bitv.extend(iterator);
996+
self.get_mut_ref().extend(iterator);
1013997
}
1014998
}
1015999

@@ -1065,8 +1049,7 @@ impl BitvSet {
10651049
/// ```
10661050
#[inline]
10671051
pub fn with_capacity(nbits: uint) -> BitvSet {
1068-
let bitv = Bitv::with_capacity(nbits, false);
1069-
BitvSet::from_bitv(bitv)
1052+
BitvSet(Bitv::with_capacity(nbits, false))
10701053
}
10711054

10721055
/// Creates a new bit vector set from the given bit vector.
@@ -1085,9 +1068,7 @@ impl BitvSet {
10851068
/// }
10861069
/// ```
10871070
#[inline]
1088-
pub fn from_bitv(mut bitv: Bitv) -> BitvSet {
1089-
// Mark every bit as valid
1090-
bitv.nbits = bitv.capacity();
1071+
pub fn from_bitv(bitv: Bitv) -> BitvSet {
10911072
BitvSet(bitv)
10921073
}
10931074

@@ -1121,10 +1102,7 @@ impl BitvSet {
11211102
/// ```
11221103
pub fn reserve(&mut self, size: uint) {
11231104
let &BitvSet(ref mut bitv) = self;
1124-
bitv.reserve(size);
1125-
if bitv.nbits < size {
1126-
bitv.nbits = bitv.capacity();
1127-
}
1105+
bitv.reserve(size)
11281106
}
11291107

11301108
/// Consumes this set to return the underlying bit vector.
@@ -1138,12 +1116,11 @@ impl BitvSet {
11381116
/// s.insert(0);
11391117
/// s.insert(3);
11401118
///
1141-
/// let bv = s.into_bitv();
1142-
/// assert!(bv.get(0));
1143-
/// assert!(bv.get(3));
1119+
/// let bv = s.unwrap();
1120+
/// assert!(bv.eq_vec([true, false, false, true]));
11441121
/// ```
11451122
#[inline]
1146-
pub fn into_bitv(self) -> Bitv {
1123+
pub fn unwrap(self) -> Bitv {
11471124
let BitvSet(bitv) = self;
11481125
bitv
11491126
}
@@ -1167,15 +1144,38 @@ impl BitvSet {
11671144
bitv
11681145
}
11691146

1147+
/// Returns a mutable reference to the underlying bit vector.
1148+
///
1149+
/// # Example
1150+
///
1151+
/// ```
1152+
/// use std::collections::BitvSet;
1153+
///
1154+
/// let mut s = BitvSet::new();
1155+
/// s.insert(0);
1156+
/// assert_eq!(s.contains(&0), true);
1157+
/// {
1158+
/// // Will free the set during bv's lifetime
1159+
/// let bv = s.get_mut_ref();
1160+
/// bv.set(0, false);
1161+
/// }
1162+
/// assert_eq!(s.contains(&0), false);
1163+
/// ```
11701164
#[inline]
1171-
fn other_op(&mut self, other: &BitvSet, f: |uint, uint| -> uint) {
1172-
// Expand the vector if necessary
1173-
self.reserve(other.capacity());
1165+
pub fn get_mut_ref<'a>(&'a mut self) -> &'a mut Bitv {
1166+
let &BitvSet(ref mut bitv) = self;
1167+
bitv
1168+
}
11741169

1170+
#[inline]
1171+
fn other_op(&mut self, other: &BitvSet, f: |uint, uint| -> uint) {
11751172
// Unwrap Bitvs
11761173
let &BitvSet(ref mut self_bitv) = self;
11771174
let &BitvSet(ref other_bitv) = other;
11781175

1176+
// Expand the vector if necessary
1177+
self_bitv.reserve(other_bitv.capacity());
1178+
11791179
// virtually pad other with 0's for equal lengths
11801180
let mut other_words = {
11811181
let (_, result) = match_words(self_bitv, other_bitv);
@@ -1376,10 +1376,9 @@ impl BitvSet {
13761376
///
13771377
/// let mut a = BitvSet::from_bitv(bitv::from_bytes([a]));
13781378
/// let b = BitvSet::from_bitv(bitv::from_bytes([b]));
1379-
/// let res = BitvSet::from_bitv(bitv::from_bytes([res]));
13801379
///
13811380
/// a.union_with(&b);
1382-
/// assert_eq!(a, res);
1381+
/// assert_eq!(a.unwrap(), bitv::from_bytes([res]));
13831382
/// ```
13841383
#[inline]
13851384
pub fn union_with(&mut self, other: &BitvSet) {
@@ -1400,10 +1399,9 @@ impl BitvSet {
14001399
///
14011400
/// let mut a = BitvSet::from_bitv(bitv::from_bytes([a]));
14021401
/// let b = BitvSet::from_bitv(bitv::from_bytes([b]));
1403-
/// let res = BitvSet::from_bitv(bitv::from_bytes([res]));
14041402
///
14051403
/// a.intersect_with(&b);
1406-
/// assert_eq!(a, res);
1404+
/// assert_eq!(a.unwrap(), bitv::from_bytes([res]));
14071405
/// ```
14081406
#[inline]
14091407
pub fn intersect_with(&mut self, other: &BitvSet) {
@@ -1426,17 +1424,15 @@ impl BitvSet {
14261424
///
14271425
/// let mut bva = BitvSet::from_bitv(bitv::from_bytes([a]));
14281426
/// let bvb = BitvSet::from_bitv(bitv::from_bytes([b]));
1429-
/// let bva_b = BitvSet::from_bitv(bitv::from_bytes([a_b]));
1430-
/// let bvb_a = BitvSet::from_bitv(bitv::from_bytes([b_a]));
14311427
///
14321428
/// bva.difference_with(&bvb);
1433-
/// assert_eq!(bva, bva_b);
1429+
/// assert_eq!(bva.unwrap(), bitv::from_bytes([a_b]));
14341430
///
14351431
/// let bva = BitvSet::from_bitv(bitv::from_bytes([a]));
14361432
/// let mut bvb = BitvSet::from_bitv(bitv::from_bytes([b]));
14371433
///
14381434
/// bvb.difference_with(&bva);
1439-
/// assert_eq!(bvb, bvb_a);
1435+
/// assert_eq!(bvb.unwrap(), bitv::from_bytes([b_a]));
14401436
/// ```
14411437
#[inline]
14421438
pub fn difference_with(&mut self, other: &BitvSet) {
@@ -1458,10 +1454,9 @@ impl BitvSet {
14581454
///
14591455
/// let mut a = BitvSet::from_bitv(bitv::from_bytes([a]));
14601456
/// let b = BitvSet::from_bitv(bitv::from_bytes([b]));
1461-
/// let res = BitvSet::from_bitv(bitv::from_bytes([res]));
14621457
///
14631458
/// a.symmetric_difference_with(&b);
1464-
/// assert_eq!(a, res);
1459+
/// assert_eq!(a.unwrap(), bitv::from_bytes([res]));
14651460
/// ```
14661461
#[inline]
14671462
pub fn symmetric_difference_with(&mut self, other: &BitvSet) {
@@ -1543,14 +1538,20 @@ impl MutableSet<uint> for BitvSet {
15431538
if self.contains(&value) {
15441539
return false;
15451540
}
1546-
1547-
// Ensure we have enough space to hold the new element
15481541
if value >= self.capacity() {
15491542
let new_cap = cmp::max(value + 1, self.capacity() * 2);
15501543
self.reserve(new_cap);
15511544
}
1552-
15531545
let &BitvSet(ref mut bitv) = self;
1546+
if value >= bitv.nbits {
1547+
// If we are increasing nbits, make sure we mask out any previously-unconsidered bits
1548+
let old_rem = bitv.nbits % uint::BITS;
1549+
if old_rem != 0 {
1550+
let old_last_word = (bitv.nbits + uint::BITS - 1) / uint::BITS - 1;
1551+
*bitv.storage.get_mut(old_last_word) &= (1 << old_rem) - 1;
1552+
}
1553+
bitv.nbits = value + 1;
1554+
}
15541555
bitv.set(value, true);
15551556
return true;
15561557
}
@@ -2224,15 +2225,14 @@ mod tests {
22242225
assert!(a.insert(160));
22252226
assert!(a.insert(19));
22262227
assert!(a.insert(24));
2227-
assert!(a.insert(200));
22282228

22292229
assert!(b.insert(1));
22302230
assert!(b.insert(5));
22312231
assert!(b.insert(9));
22322232
assert!(b.insert(13));
22332233
assert!(b.insert(19));
22342234

2235-
let expected = [1, 3, 5, 9, 11, 13, 19, 24, 160, 200];
2235+
let expected = [1, 3, 5, 9, 11, 13, 19, 24, 160];
22362236
let actual = a.union(&b).collect::<Vec<uint>>();
22372237
assert_eq!(actual.as_slice(), expected.as_slice());
22382238
}
@@ -2281,27 +2281,6 @@ mod tests {
22812281
assert!(c.is_disjoint(&b))
22822282
}
22832283

2284-
#[test]
2285-
fn test_bitv_set_union_with() {
2286-
//a should grow to include larger elements
2287-
let mut a = BitvSet::new();
2288-
a.insert(0);
2289-
let mut b = BitvSet::new();
2290-
b.insert(5);
2291-
let expected = BitvSet::from_bitv(from_bytes([0b10000100]));
2292-
a.union_with(&b);
2293-
assert_eq!(a, expected);
2294-
2295-
// Standard
2296-
let mut a = BitvSet::from_bitv(from_bytes([0b10100010]));
2297-
let mut b = BitvSet::from_bitv(from_bytes([0b01100010]));
2298-
let c = a.clone();
2299-
a.union_with(&b);
2300-
b.union_with(&c);
2301-
assert_eq!(a.len(), 4);
2302-
assert_eq!(b.len(), 4);
2303-
}
2304-
23052284
#[test]
23062285
fn test_bitv_set_intersect_with() {
23072286
// Explicitly 0'ed bits
@@ -2332,59 +2311,6 @@ mod tests {
23322311
assert_eq!(b.len(), 2);
23332312
}
23342313

2335-
#[test]
2336-
fn test_bitv_set_difference_with() {
2337-
// Explicitly 0'ed bits
2338-
let mut a = BitvSet::from_bitv(from_bytes([0b00000000]));
2339-
let b = BitvSet::from_bitv(from_bytes([0b10100010]));
2340-
a.difference_with(&b);
2341-
assert!(a.is_empty());
2342-
2343-
// Uninitialized bits should behave like 0's
2344-
let mut a = BitvSet::new();
2345-
let b = BitvSet::from_bitv(from_bytes([0b11111111]));
2346-
a.difference_with(&b);
2347-
assert!(a.is_empty());
2348-
2349-
// Standard
2350-
let mut a = BitvSet::from_bitv(from_bytes([0b10100010]));
2351-
let mut b = BitvSet::from_bitv(from_bytes([0b01100010]));
2352-
let c = a.clone();
2353-
a.difference_with(&b);
2354-
b.difference_with(&c);
2355-
assert_eq!(a.len(), 1);
2356-
assert_eq!(b.len(), 1);
2357-
}
2358-
2359-
#[test]
2360-
fn test_bitv_set_symmetric_difference_with() {
2361-
//a should grow to include larger elements
2362-
let mut a = BitvSet::new();
2363-
a.insert(0);
2364-
a.insert(1);
2365-
let mut b = BitvSet::new();
2366-
b.insert(1);
2367-
b.insert(5);
2368-
let expected = BitvSet::from_bitv(from_bytes([0b10000100]));
2369-
a.symmetric_difference_with(&b);
2370-
assert_eq!(a, expected);
2371-
2372-
let mut a = BitvSet::from_bitv(from_bytes([0b10100010]));
2373-
let b = BitvSet::new();
2374-
let c = a.clone();
2375-
a.symmetric_difference_with(&b);
2376-
assert_eq!(a, c);
2377-
2378-
// Standard
2379-
let mut a = BitvSet::from_bitv(from_bytes([0b11100010]));
2380-
let mut b = BitvSet::from_bitv(from_bytes([0b01101010]));
2381-
let c = a.clone();
2382-
a.symmetric_difference_with(&b);
2383-
b.symmetric_difference_with(&c);
2384-
assert_eq!(a.len(), 2);
2385-
assert_eq!(b.len(), 2);
2386-
}
2387-
23882314
#[test]
23892315
fn test_bitv_set_eq() {
23902316
let a = BitvSet::from_bitv(from_bytes([0b10100010]));

branches/auto/src/libcollections/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#![license = "MIT/ASL2"]
2020
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
2121
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
22-
html_root_url = "http://doc.rust-lang.org/0.12.0/",
22+
html_root_url = "http://doc.rust-lang.org/master/",
2323
html_playground_url = "http://play.rust-lang.org/")]
2424

2525
#![allow(unknown_features)]

branches/auto/src/libcore/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
#![crate_type = "rlib"]
5454
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
5555
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
56-
html_root_url = "http://doc.rust-lang.org/0.12.0/",
56+
html_root_url = "http://doc.rust-lang.org/master/",
5757
html_playground_url = "http://play.rust-lang.org/")]
5858

5959
#![no_std]

branches/auto/src/libdebug/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#![crate_type = "dylib"]
2424
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
2525
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
26-
html_root_url = "http://doc.rust-lang.org/0.12.0/")]
26+
html_root_url = "http://doc.rust-lang.org/master/")]
2727
#![experimental]
2828
#![feature(macro_rules)]
2929
#![allow(experimental)]

0 commit comments

Comments
 (0)