1use crate::{len::LengthType, mem::SpareMemoryPolicy, smallvec::SmallVec};
2use core::cmp::{Eq, PartialEq};
3
4impl<T, L, U, SM, const C: usize, const N: usize> PartialEq<&'_ [U; N]> for SmallVec<T, C, L, SM>
5where
6 T: PartialEq<U>,
7 L: LengthType,
8 SM: SpareMemoryPolicy<T>,
9{
10 #[inline]
11 fn eq(&self, other: &&'_ [U; N]) -> bool {
12 self[..] == other[..]
13 }
14}
15
16impl<T, L, U, SM, const C: usize, const N: usize> PartialEq<[U; N]> for SmallVec<T, C, L, SM>
17where
18 T: PartialEq<U>,
19 L: LengthType,
20 SM: SpareMemoryPolicy<T>,
21{
22 #[inline]
23 fn eq(&self, other: &[U; N]) -> bool {
24 self[..] == other[..]
25 }
26}
27
28impl<T, L, U, SM, const C: usize, const N: usize> PartialEq<[U; N]> for &SmallVec<T, C, L, SM>
29where
30 T: PartialEq<U>,
31 L: LengthType,
32 SM: SpareMemoryPolicy<T>,
33{
34 #[inline]
35 fn eq(&self, other: &[U; N]) -> bool {
36 self[..] == other[..]
37 }
38}
39
40impl<T, L, U, SM, const C: usize, const N: usize> PartialEq<[U; N]> for &mut SmallVec<T, C, L, SM>
41where
42 T: PartialEq<U>,
43 L: LengthType,
44 SM: SpareMemoryPolicy<T>,
45{
46 #[inline]
47 fn eq(&self, other: &[U; N]) -> bool {
48 self[..] == other[..]
49 }
50}
51
52impl<T, L, U, SM, const C: usize> PartialEq<&'_ [U]> for SmallVec<T, C, L, SM>
53where
54 T: PartialEq<U>,
55 L: LengthType,
56 SM: SpareMemoryPolicy<T>,
57{
58 #[inline]
59 fn eq(&self, other: &&'_ [U]) -> bool {
60 self[..] == other[..]
61 }
62}
63
64impl<T, L, U, SM, const C: usize> PartialEq<[U]> for SmallVec<T, C, L, SM>
65where
66 T: PartialEq<U>,
67 L: LengthType,
68 SM: SpareMemoryPolicy<T>,
69{
70 #[inline]
71 fn eq(&self, other: &[U]) -> bool {
72 self[..] == other[..]
73 }
74}
75
76impl<T, U, LT, LU, SMT, SMU, const C: usize, const N: usize> PartialEq<SmallVec<U, N, LU, SMU>>
77 for SmallVec<T, C, LT, SMT>
78where
79 T: PartialEq<U>,
80 LT: LengthType,
81 LU: LengthType,
82 SMT: SpareMemoryPolicy<T>,
83 SMU: SpareMemoryPolicy<U>,
84{
85 #[inline]
86 fn eq(&self, other: &SmallVec<U, N, LU, SMU>) -> bool {
87 self[..] == other[..]
88 }
89}
90
91impl<T, U, LT, LU, SMT, SMU, const C: usize, const N: usize> PartialEq<&'_ SmallVec<U, N, LU, SMU>>
92 for SmallVec<T, C, LT, SMT>
93where
94 T: PartialEq<U>,
95 LT: LengthType,
96 LU: LengthType,
97 SMT: SpareMemoryPolicy<T>,
98 SMU: SpareMemoryPolicy<U>,
99{
100 #[inline]
101 fn eq(&self, other: &&'_ SmallVec<U, N, LU, SMU>) -> bool {
102 self[..] == other[..]
103 }
104}
105
106impl<T: Eq, L: LengthType, SM: SpareMemoryPolicy<T>, const C: usize> Eq for SmallVec<T, C, L, SM> {}
107
108#[cfg(test)]
109mod testing {
110 use crate as cds;
111 use cds::{small_vec, smallvec::SmallVec};
112
113 type SV = SmallVec<u64, 7>;
114
115 #[test]
116 fn test_eq_arr_ref() {
117 let v = SV::from_iter(0..3);
118 assert!(v == &[0, 1, 2]);
119 assert!(v != &[0, 1, 2, 3]);
120 }
121
122 #[test]
123 fn test_eq_arr() {
124 let v = SV::from_iter(1..3);
125 assert!(v == [1, 2]);
126 assert!(v != [1]);
127 }
128
129 #[test]
130 fn test_eq_slice_ref() {
131 let v = SV::from_iter((100..102).rev());
132 assert!(v == [101u64, 100].as_ref());
133 assert!(v != [100].as_ref());
134 }
135
136 #[test]
137 fn test_eq_slice() {
138 let v = SV::from_iter(3..5);
139 let arr1: [u64; 2] = [3, 4];
140 let arr2: [u64; 2] = [5, 6];
141 assert!(v == arr1[..]);
142 assert!(v != arr2[..]);
143 }
144
145 #[test]
146 fn test_ref_eq_arr() {
147 let v = SV::from_iter(3..5);
148 let arr1: [u64; 2] = [3, 4];
149 let arr2: [u64; 2] = [5, 6];
150 assert!(&v == arr1);
151 assert!(&v != arr2);
152 }
153
154 #[test]
155 fn test_eq_av_ref() {
156 let a = SV::from_iter(0..2);
157 let b = small_vec![2; u64; 0, 1];
158 assert!(a == &b);
159 assert!(a != &small_vec![7; u64]);
160 }
161
162 #[test]
163 fn test_eq_av() {
164 let a = SV::from_iter(0..2);
165 let b = small_vec![2; u64; 0, 1];
166 assert!(a == b);
167 assert!(a != small_vec![7; u64]);
168 }
169}