forked from Angry-Penguins-Colony/mx-rust-utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
managed_vec_utils.rs
39 lines (32 loc) · 869 Bytes
/
managed_vec_utils.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use elrond_wasm::{
api::ManagedTypeApi,
types::{ManagedVec, ManagedVecItem},
};
pub trait EqUtils<M, T>
where
M: ManagedTypeApi,
T: ManagedVecItem,
{
/// Check if two unordered vec are equals
fn eq_unorder(&self, other: &Self) -> bool;
}
impl<M, T> EqUtils<M, T> for ManagedVec<M, T>
where
M: ManagedTypeApi,
T: ManagedVecItem + PartialEq + Clone,
{
fn eq_unorder(&self, other: &Self) -> bool {
if self.len() != other.len() {
return false;
}
let mut other_copy: ManagedVec<M, T> = other.clone();
for item in self.into_iter() {
let opt_item_index = other_copy.find(&item);
if opt_item_index.is_none() {
return false;
}
other_copy.remove(opt_item_index.unwrap());
}
return other_copy.len() == 0;
}
}