4 /// Return the smaller of the two
5 fn min<'a>(&'a self, other: &'a Self) -> &'a Self;
8 /// Return a pointer to the minimal value of `v`.
9 pub fn vec_min<T: Minimum>(v: &Vec<T>) -> Option<&T> {
12 min = Some(match min {
19 // Notice that `Option<&T>` is technically (leaving the borrowing story aside) a pointer to a `T`,
20 // that could optionally be invalid. In other words, it's just like a pointer in C(++) or Java
21 // that can be `NULL`! However, thanks to `Option` being an `enum`, we cannot forget to check
22 // the pointer for validity, avoiding the safety issues of C(++). At the same time, when we
23 // have a borrow like `v` above that's not an `Option`, we *know* that is has to be a valid
24 // pointer, so we don't even need to do a `NULL`-check.<br/>
25 // Also, if you are worried about wasting space, notice that Rust knows that `&T` can never be
26 // `NULL`, and hence optimizes `Option<&T>` to be no larger than `&T`. The `None` case is represented
27 // as `NULL`. This is another great example of a zero-cost abstraction: `Option<&T>` is exactly like
28 // a pointer in C(++), if you look at what happens during execution - but it's much safer to use.
30 impl Minimum for BigInt {
31 fn min<'a>(&'a self, other: &'a Self) -> &'a Self {
32 debug_assert!(self.test_invariant() && other.test_invariant());
33 if self.data.len() < other.data.len() {
35 } else if self.data.len() > other.data.len() {
38 // compare back-to-front, i.e., most significant digit first
39 let mut idx = self.data.len()-1;
41 if self.data[idx] < other.data[idx] {
43 } else if self.data[idx] > other.data[idx] {