Skip to content

Commit 44a7b0f

Browse files
committed
---
yaml --- r: 151147 b: refs/heads/try2 c: b8f5090 h: refs/heads/master i: 151145: f2f810e 151143: 0d379bb v: v3
1 parent 5faf8f6 commit 44a7b0f

File tree

6 files changed

+39
-62
lines changed

6 files changed

+39
-62
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 02ba8e275419798be044e68379b25cc8ab52a97c
8+
refs/heads/try2: b8f5090a9a10e4dcc20dc64ee61a7b3749500738
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/doc/complement-lang-faq.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ Some examples that demonstrate different aspects of the language:
2222

2323
[sprocketnes]: https://github.com/pcwalton/sprocketnes
2424
[hash]: https://github.com/mozilla/rust/blob/master/src/libstd/hash.rs
25-
[HashMap]: https://github.com/mozilla/rust/blob/master/src/libcollections/hashmap.rs
26-
[json]: https://github.com/mozilla/rust/blob/master/src/libserialize/json.rs
25+
[HashMap]: https://github.com/mozilla/rust/blob/master/src/libstd/hashmap.rs
26+
[json]: https://github.com/mozilla/rust/blob/master/src/libextra/json.rs
2727

2828
You may also be interested in browsing [GitHub's Rust][github-rust] page.
2929

branches/try2/src/libstd/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ pub trait Iterator<A> {
306306
Take{iter: self, n: n}
307307
}
308308

309-
/// Creates a new iterator which behaves in a similar fashion to fold.
309+
/// Creates a new iterator which behaves in a similar fashion to foldl.
310310
/// There is a state which is passed between each iteration and can be
311311
/// mutated as necessary. The yielded values from the closure are yielded
312312
/// from the Scan instance when not None.

branches/try2/src/libstd/num/int_macros.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,15 @@ impl Primitive for $T {}
234234

235235
// String conversion functions and impl str -> num
236236

237-
/// Parse a byte slice as a number in the given base.
237+
/// Parse a byte slice as a number in the given base
238238
///
239239
/// Yields an `Option` because `buf` may or may not actually be parseable.
240240
///
241241
/// # Examples
242242
///
243-
/// ```rust
244-
/// let digits = [49,50,51,52,53,54,55,56,57];
245-
/// let base = 10;
246-
/// let num = std::i64::parse_bytes(digits, base);
243+
/// ```
244+
/// let num = std::i64::parse_bytes([49,50,51,52,53,54,55,56,57], 10);
245+
/// assert!(num == Some(123456789));
247246
/// ```
248247
#[inline]
249248
pub fn parse_bytes(buf: &[u8], radix: uint) -> Option<$T> {
@@ -270,6 +269,16 @@ impl FromStrRadix for $T {
270269
// String conversion functions and impl num -> str
271270

272271
/// Convert to a string as a byte slice in a given base.
272+
///
273+
/// Use in place of x.to_str() when you do not need to store the string permanently
274+
///
275+
/// # Examples
276+
///
277+
/// ```
278+
/// std::int::to_str_bytes(123, 10, |v| {
279+
/// assert!(v == "123".as_bytes());
280+
/// });
281+
/// ```
273282
#[inline]
274283
pub fn to_str_bytes<U>(n: $T, radix: uint, f: |v: &[u8]| -> U) -> U {
275284
// The radix can be as low as 2, so we need at least 64 characters for a

branches/try2/src/libstd/num/uint_macros.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,15 @@ impl Int for $T {}
148148

149149
// String conversion functions and impl str -> num
150150

151-
/// Parse a byte slice as a number in the given base.
151+
/// Parse a byte slice as a number in the given base
152152
///
153153
/// Yields an `Option` because `buf` may or may not actually be parseable.
154154
///
155155
/// # Examples
156156
///
157-
/// ```rust
158-
/// let digits = [49,50,51,52,53,54,55,56,57];
159-
/// let base = 10;
160-
/// let num = std::i64::parse_bytes(digits, base);
157+
/// ```
158+
/// let num = std::uint::parse_bytes([49,50,51,52,53,54,55,56,57], 10);
159+
/// assert!(num == Some(123456789));
161160
/// ```
162161
#[inline]
163162
pub fn parse_bytes(buf: &[u8], radix: uint) -> Option<$T> {
@@ -184,6 +183,16 @@ impl FromStrRadix for $T {
184183
// String conversion functions and impl num -> str
185184

186185
/// Convert to a string as a byte slice in a given base.
186+
///
187+
/// Use in place of x.to_str() when you do not need to store the string permanently
188+
///
189+
/// # Examples
190+
///
191+
/// ```
192+
/// std::uint::to_str_bytes(123, 10, |v| {
193+
/// assert!(v == "123".as_bytes());
194+
/// });
195+
/// ```
187196
#[inline]
188197
pub fn to_str_bytes<U>(n: $T, radix: uint, f: |v: &[u8]| -> U) -> U {
189198
// The radix can be as low as 2, so we need at least 64 characters for a

branches/try2/src/libstd/slice.rs

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ pub struct ElementSwaps {
307307
sdir: ~[SizeDirection],
308308
/// If true, emit the last swap that returns the sequence to initial state
309309
emit_reset: bool,
310-
swaps_made : uint,
311310
}
312311

313312
impl ElementSwaps {
@@ -320,8 +319,7 @@ impl ElementSwaps {
320319
emit_reset: true,
321320
sdir: range(0, length)
322321
.map(|i| SizeDirection{ size: i, dir: Neg })
323-
.collect::<~[_]>(),
324-
swaps_made: 0
322+
.collect::<~[_]>()
325323
}
326324
}
327325
}
@@ -360,30 +358,16 @@ impl Iterator<(uint, uint)> for ElementSwaps {
360358
x.dir = match x.dir { Pos => Neg, Neg => Pos };
361359
}
362360
}
363-
self.swaps_made += 1;
364361
Some((i, j))
365362
},
366-
None => if self.emit_reset {
363+
None => if self.emit_reset && self.sdir.len() > 1 {
367364
self.emit_reset = false;
368-
if self.sdir.len() > 1 {
369-
// The last swap
370-
self.swaps_made += 1;
371-
Some((0, 1))
372-
} else {
373-
// Vector is of the form [] or [x], and the only permutation is itself
374-
self.swaps_made += 1;
375-
Some((0,0))
376-
}
377-
} else { None }
365+
Some((0, 1))
366+
} else {
367+
None
368+
}
378369
}
379370
}
380-
381-
#[inline]
382-
fn size_hint(&self) -> (uint, Option<uint>) {
383-
// For a vector of size n, there are exactly n! permutations.
384-
let n = range(2, self.sdir.len() + 1).product();
385-
(n - self.swaps_made, Some(n - self.swaps_made))
386-
}
387371
}
388372

389373
/// An Iterator that uses `ElementSwaps` to iterate through
@@ -404,19 +388,13 @@ impl<T: Clone> Iterator<~[T]> for Permutations<T> {
404388
fn next(&mut self) -> Option<~[T]> {
405389
match self.swaps.next() {
406390
None => None,
407-
Some((0,0)) => Some(self.v.clone()),
408391
Some((a, b)) => {
409392
let elt = self.v.clone();
410393
self.v.swap(a, b);
411394
Some(elt)
412395
}
413396
}
414397
}
415-
416-
#[inline]
417-
fn size_hint(&self) -> (uint, Option<uint>) {
418-
self.swaps.size_hint()
419-
}
420398
}
421399

422400
/// An iterator over the (overlapping) slices of length `size` within
@@ -2789,33 +2767,19 @@ mod tests {
27892767
{
27902768
let v: [int, ..0] = [];
27912769
let mut it = v.permutations();
2792-
let (min_size, max_opt) = it.size_hint();
2793-
assert_eq!(min_size, 1);
2794-
assert_eq!(max_opt.unwrap(), 1);
2795-
assert_eq!(it.next(), Some(v.as_slice().to_owned()));
27962770
assert_eq!(it.next(), None);
27972771
}
27982772
{
27992773
let v = ["Hello".to_owned()];
28002774
let mut it = v.permutations();
2801-
let (min_size, max_opt) = it.size_hint();
2802-
assert_eq!(min_size, 1);
2803-
assert_eq!(max_opt.unwrap(), 1);
2804-
assert_eq!(it.next(), Some(v.as_slice().to_owned()));
28052775
assert_eq!(it.next(), None);
28062776
}
28072777
{
28082778
let v = [1, 2, 3];
28092779
let mut it = v.permutations();
2810-
let (min_size, max_opt) = it.size_hint();
2811-
assert_eq!(min_size, 3*2);
2812-
assert_eq!(max_opt.unwrap(), 3*2);
28132780
assert_eq!(it.next(), Some(~[1,2,3]));
28142781
assert_eq!(it.next(), Some(~[1,3,2]));
28152782
assert_eq!(it.next(), Some(~[3,1,2]));
2816-
let (min_size, max_opt) = it.size_hint();
2817-
assert_eq!(min_size, 3);
2818-
assert_eq!(max_opt.unwrap(), 3);
28192783
assert_eq!(it.next(), Some(~[3,2,1]));
28202784
assert_eq!(it.next(), Some(~[2,3,1]));
28212785
assert_eq!(it.next(), Some(~[2,1,3]));
@@ -2825,15 +2789,10 @@ mod tests {
28252789
// check that we have N! permutations
28262790
let v = ['A', 'B', 'C', 'D', 'E', 'F'];
28272791
let mut amt = 0;
2828-
let mut it = v.permutations();
2829-
let (min_size, max_opt) = it.size_hint();
2830-
for _perm in it {
2792+
for _perm in v.permutations() {
28312793
amt += 1;
28322794
}
2833-
assert_eq!(amt, it.swaps.swaps_made);
2834-
assert_eq!(amt, min_size);
28352795
assert_eq!(amt, 2 * 3 * 4 * 5 * 6);
2836-
assert_eq!(amt, max_opt.unwrap());
28372796
}
28382797
}
28392798

0 commit comments

Comments
 (0)