Skip to content

Commit 62700bc

Browse files
committed
---
yaml --- r: 49950 b: refs/heads/auto c: b3ee49c h: refs/heads/master v: v3
1 parent 6284ab3 commit 62700bc

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: c724dae7def417cd9aea8710d479b28155ed0f4f
17+
refs/heads/auto: b3ee49c7e249e4fc2fb6456088b556e9ff8316d9
1818
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167

branches/auto/src/libstd/deque.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,40 +22,61 @@ pub struct Deque<T> {
2222
}
2323

2424
impl<T> Container for Deque<T> {
25+
/// Return the number of elements in the deque
2526
pure fn len(&self) -> uint { self.nelts }
27+
28+
/// Return true if the deque contains no elements
2629
pure fn is_empty(&self) -> bool { self.len() == 0 }
2730
}
2831

2932
impl<T> Mutable for Deque<T> {
33+
/// Clear the deque, removing all values.
3034
fn clear(&mut self) {
31-
for vec::each_mut(self.elts) |x| { *x = None }
35+
for self.elts.each_mut |x| { *x = None }
3236
self.nelts = 0;
3337
self.lo = 0;
3438
self.hi = 0;
3539
}
3640
}
3741

3842
pub impl<T> Deque<T> {
43+
/// Create an empty Deque
3944
static pure fn new() -> Deque<T> {
4045
Deque{nelts: 0, lo: 0, hi: 0,
4146
elts: vec::from_fn(initial_capacity, |_| None)}
4247
}
4348

49+
/// Return a reference to the first element in the deque
50+
///
51+
/// Fails if the deque is empty
4452
fn peek_front(&self) -> &self/T { get(self.elts, self.lo) }
53+
54+
/// Return a reference to the last element in the deque
55+
///
56+
/// Fails if the deque is empty
4557
fn peek_back(&self) -> &self/T { get(self.elts, self.hi - 1u) }
4658

59+
/// Retrieve an element in the deque by index
60+
///
61+
/// Fails if there is no element with the given index
4762
fn get(&self, i: int) -> &self/T {
4863
let idx = (self.lo + (i as uint)) % self.elts.len();
4964
get(self.elts, idx)
5065
}
5166

67+
/// Remove and return the first element in the deque
68+
///
69+
/// Fails if the deque is empty
5270
fn pop_front(&mut self) -> T {
5371
let mut result = self.elts[self.lo].swap_unwrap();
5472
self.lo = (self.lo + 1u) % self.elts.len();
5573
self.nelts -= 1u;
5674
result
5775
}
5876

77+
/// Remove and return the last element in the deque
78+
///
79+
/// Fails if the deque is empty
5980
fn pop_back(&mut self) -> T {
6081
if self.hi == 0u {
6182
self.hi = self.elts.len() - 1u;
@@ -66,6 +87,7 @@ pub impl<T> Deque<T> {
6687
result
6788
}
6889

90+
/// Prepend an element to the deque
6991
fn add_front(&mut self, t: T) {
7092
let oldlo = self.lo;
7193
if self.lo == 0u {
@@ -80,6 +102,7 @@ pub impl<T> Deque<T> {
80102
self.nelts += 1u;
81103
}
82104

105+
/// Append an element to the deque
83106
fn add_back(&mut self, t: T) {
84107
if self.lo == self.hi && self.nelts != 0u {
85108
self.elts = grow(self.nelts, self.lo, self.elts);

0 commit comments

Comments
 (0)