diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs index 9789dbea131..9642dd0c3dd 100644 --- a/src/libstd/smallintmap.rs +++ b/src/libstd/smallintmap.rs @@ -14,7 +14,7 @@ */ use core::container::{Container, Mutable, Map, Set}; -use core::iter::BaseIter; +use core::iter::{BaseIter, ReverseIter}; use core::option::{Some, None}; use core::prelude::*; @@ -36,6 +36,18 @@ impl SmallIntMap: BaseIter<(uint, &V)> { pure fn size_hint(&self) -> Option { Some(self.len()) } } +impl SmallIntMap: ReverseIter<(uint, &V)> { + /// Visit all key-value pairs in reverse order + pure fn each_reverse(&self, it: fn(&(uint, &self/V)) -> bool) { + for uint::range_rev(self.v.len(), 0) |i| { + match self.v[i - 1] { + Some(ref elt) => if !it(&(i - 1, elt)) { break }, + None => () + } + } + } +} + impl SmallIntMap: Container { /// Return the number of elements in the map pure fn len(&self) -> uint {