Skip to content

Commit 1b3475e

Browse files
committed
---
yaml --- r: 28118 b: refs/heads/try c: 0e5a0e1 h: refs/heads/master v: v3
1 parent 353f9db commit 1b3475e

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
@@ -2,7 +2,7 @@
22
refs/heads/master: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
5-
refs/heads/try: 88e0476bd024ef83052479588278669f56a346e2
5+
refs/heads/try: 0e5a0e1da54f385c1ac623bb7cfe6cf19fcde8f8
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df

branches/try/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)