Skip to content

Commit f6643d9

Browse files
committed
---
yaml --- r: 30140 b: refs/heads/incoming c: 0e5a0e1 h: refs/heads/master v: v3
1 parent 869b2cd commit f6643d9

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: 88e0476bd024ef83052479588278669f56a346e2
9+
refs/heads/incoming: 0e5a0e1da54f385c1ac623bb7cfe6cf19fcde8f8
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/libcore/vec.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Vectors
22
3+
import cmp::{Eq, Ord};
34
import option::{Some, None};
45
import ptr::addr_of;
56
import libc::size_t;
@@ -1374,6 +1375,80 @@ pure fn as_mut_buf<T,U>(s: &[mut T],
13741375
}
13751376
}
13761377

1378+
// Equality
1379+
1380+
pure fn eq<T: Eq>(a: &[T], b: &[T]) -> bool {
1381+
let (a_len, b_len) = (a.len(), b.len());
1382+
if a_len != b_len { return false; }
1383+
1384+
let mut i = 0;
1385+
while i < a_len {
1386+
if a[i] != b[i] { return false; }
1387+
i += 1;
1388+
}
1389+
1390+
return true;
1391+
}
1392+
1393+
impl<T: Eq> &[T]: Eq {
1394+
#[inline(always)]
1395+
pure fn eq(&&other: &[T]) -> bool {
1396+
eq(self, other)
1397+
}
1398+
}
1399+
1400+
impl<T: Eq> ~[T]: Eq {
1401+
#[inline(always)]
1402+
pure fn eq(&&other: ~[T]) -> bool {
1403+
eq(self, other)
1404+
}
1405+
}
1406+
1407+
impl<T: Eq> @[T]: Eq {
1408+
#[inline(always)]
1409+
pure fn eq(&&other: @[T]) -> bool {
1410+
eq(self, other)
1411+
}
1412+
}
1413+
1414+
// Lexicographical comparison
1415+
1416+
pure fn lt<T: Ord>(a: &[T], b: &[T]) -> bool {
1417+
let (a_len, b_len) = (a.len(), b.len());
1418+
let mut end = uint::min(a_len, b_len);
1419+
1420+
let mut i = 0;
1421+
while i < end {
1422+
let (c_a, c_b) = (&a[i], &b[i]);
1423+
if *c_a < *c_b { return true; }
1424+
if *c_a > *c_b { return false; }
1425+
i += 1;
1426+
}
1427+
1428+
return a_len < b_len;
1429+
}
1430+
1431+
impl<T: Ord> &[T]: Ord {
1432+
#[inline(always)]
1433+
pure fn lt(&&other: &[T]) -> bool {
1434+
lt(self, other)
1435+
}
1436+
}
1437+
1438+
impl<T: Ord> ~[T]: Ord {
1439+
#[inline(always)]
1440+
pure fn lt(&&other: ~[T]) -> bool {
1441+
lt(self, other)
1442+
}
1443+
}
1444+
1445+
impl<T: Ord> @[T]: Ord {
1446+
#[inline(always)]
1447+
pure fn lt(&&other: @[T]) -> bool {
1448+
lt(self, other)
1449+
}
1450+
}
1451+
13771452
#[cfg(notest)]
13781453
impl<T: copy> ~[T]: add<&[const T],~[T]> {
13791454
#[inline(always)]

0 commit comments

Comments
 (0)