cds/smallvec/traits/
ord.rs1use crate::{len::LengthType, mem::SpareMemoryPolicy, smallvec::SmallVec};
2use core::cmp::{Ord, Ordering, PartialOrd};
3
4impl<T, L, SM, const C: usize> PartialOrd for SmallVec<T, C, L, SM>
5where
6 T: PartialOrd,
7 L: LengthType,
8 SM: SpareMemoryPolicy<T>,
9{
10 #[inline]
11 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
12 PartialOrd::partial_cmp(&**self, &**other)
13 }
14}
15
16impl<T, L, SM, const C: usize> Ord for SmallVec<T, C, L, SM>
17where
18 T: Ord,
19 L: LengthType,
20 SM: SpareMemoryPolicy<T>,
21{
22 #[inline]
23 fn cmp(&self, other: &Self) -> Ordering {
24 Ord::cmp(&**self, &**other)
25 }
26}
27
28#[cfg(test)]
29mod testing {
30 use crate as cds;
31 use cds::small_vec;
32 use core::cmp::Ordering;
33
34 #[test]
35 fn test_partial_ord() {
36 let a = small_vec![3; u64; 1, 2, 3];
37 let b = small_vec![3; u64; 2, 2, 3];
38
39 assert!(a < b);
40 assert!(a <= b);
41 assert!(!(a >= b));
42 assert!(!(a > b));
43
44 assert!(b > a);
45 assert!(b >= a);
46 assert!(!(b <= a));
47 assert!(!(b < a));
48 }
49
50 #[test]
51 fn test_ord() {
52 let a = small_vec![3; u64; 1, 2, 3];
53 let b = small_vec![3; u64; 2, 2, 3];
54
55 assert_eq!(a.cmp(&b), Ordering::Less);
56 assert_eq!(b.cmp(&a), Ordering::Greater);
57 assert_eq!(a.cmp(&a), Ordering::Equal);
58 }
59}