osom_lib_btree/btree/operations/
equality.rs1use core::hash::Hash;
2
3use crate::btree::{BTree, BTreeConfig};
4
5impl<TKey, TValue, TConfig> PartialEq for BTree<TKey, TValue, TConfig>
6where
7 TKey: Ord,
8 TValue: PartialEq,
9 TConfig: BTreeConfig,
10{
11 fn eq(&self, other: &Self) -> bool {
12 if self.len() != other.len() {
13 return false;
14 }
15
16 let mut right_iter = other.iter();
17
18 for left_kvp in self.iter() {
21 let right_kvp = right_iter
22 .next()
23 .expect("[PartialEq] left and right iterators should have the same length");
24
25 if left_kvp.unpack() != right_kvp.unpack() {
26 return false;
27 }
28 }
29
30 true
31 }
32}
33
34impl<TKey, TValue, TConfig> Eq for BTree<TKey, TValue, TConfig>
35where
36 TKey: Ord,
37 TValue: Eq,
38 TConfig: BTreeConfig,
39{
40}
41
42impl<TKey, TValue, TConfig> Hash for BTree<TKey, TValue, TConfig>
43where
44 TKey: Ord + Hash,
45 TValue: Hash,
46 TConfig: BTreeConfig,
47{
48 fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
49 self.len().hash(state);
50 for kvp in self.iter() {
51 kvp.key.hash(state);
52 kvp.value.hash(state);
53 }
54 }
55}