diff options
| author | Roy Frostig <[email protected]> | 2010-07-28 14:00:44 -0700 |
|---|---|---|
| committer | Roy Frostig <[email protected]> | 2010-07-28 14:00:44 -0700 |
| commit | 596d19e2ea1f2cc96f7e493171a692bc0b912ce6 (patch) | |
| tree | f9a4be20be28121856a359e31ba0d07c56bf1213 /src/lib/deque.rs | |
| parent | Switch machine-type lexemes to use suffixes. Remove support for foo(bar) as a... (diff) | |
| download | rust-596d19e2ea1f2cc96f7e493171a692bc0b912ce6.tar.xz rust-596d19e2ea1f2cc96f7e493171a692bc0b912ce6.zip | |
Test the deque a bit. Give it a get-by-index method. Fix two uncovered state-calculation bugs --- one decently, the other with an ugly hack. Bug on the latter coming right up.
Diffstat (limited to 'src/lib/deque.rs')
| -rw-r--r-- | src/lib/deque.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/lib/deque.rs b/src/lib/deque.rs index 699b3f0d..24a03ed0 100644 --- a/src/lib/deque.rs +++ b/src/lib/deque.rs @@ -17,6 +17,8 @@ type t[T] = obj { fn peek_front() -> T; fn peek_back() -> T; + + fn get(int i) -> T; }; fn create[T]() -> t[T] { @@ -128,6 +130,11 @@ fn create[T]() -> t[T] { fn peek_back() -> T { ret get[T](elts, hi); } + + fn get(int i) -> T { + let uint idx = (lo + (i as uint)) % _vec.len[cell[T]](elts); + ret get[T](elts, idx); + } } let vec[cell[T]] v = _vec.init_elt[cell[T]](util.none[T](), |