Skip to content

Commit

Permalink
remove a useless clone in PartialSumMap
Browse files Browse the repository at this point in the history
  • Loading branch information
Ekleog committed Jun 17, 2022
1 parent 3368652 commit 06c3a2f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/types/src/partial_sum_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ impl<K: Clone + Ord + num_traits::Unsigned + num_traits::CheckedAdd, V> PartialS
/// Note that the result can be greater than `usize::MAX` if eg. `K` is a BigInt type. Cast at your own risk.
///
/// `O(1)`
pub fn size(&self) -> K {
self.size.clone()
pub fn size(&self) -> &K {
&self.size
}

/// Find the value by the index.
Expand Down Expand Up @@ -109,18 +109,18 @@ mod tests {
fn empty_partial_map() {
let map = PartialSumMap::<u32, u32>::new();
assert_eq!(None, map.find(0));
assert_eq!(0, map.size());
assert_eq!(0, *map.size());
}

#[test]
fn basic_function() {
let mut map = PartialSumMap::<u32, u32>::new();
assert_eq!(None, map.max_index());
assert_eq!(0, map.size());
assert_eq!(0, *map.size());
for i in 0..10 {
map.push(1, i).unwrap();
assert_eq!(Some(i), map.max_index());
assert_eq!(i + 1, map.size());
assert_eq!(i + 1, *map.size());
}
for i in 0..10 {
assert_eq!(Some(&i), map.find(i));
Expand All @@ -134,13 +134,13 @@ mod tests {
let mut map = PartialSumMap::<u32, u32>::new();
assert_eq!(Ok(()), map.push(0, 0));
assert_eq!(None, map.max_index());
assert_eq!(0, map.size());
assert_eq!(0, *map.size());
assert_eq!(Ok(()), map.push(10, 42));
assert_eq!(Some(9), map.max_index());
assert_eq!(10, map.size());
assert_eq!(10, *map.size());
assert_eq!(Ok(()), map.push(0, 43));
assert_eq!(Some(9), map.max_index());
assert_eq!(10, map.size());
assert_eq!(10, *map.size());
}

#[test]
Expand Down

0 comments on commit 06c3a2f

Please sign in to comment.