@@ -60,13 +60,13 @@ impl<T: Hash + Eq + PartialEq + Clone + Display> Counter<T> {
60
60
}
61
61
62
62
/// Remove an item from the internal order store
63
- fn purge_from_order ( & mut self , item : & T , count : u64 ) {
64
- if let Some ( order) = self . order . get_mut ( & count) {
63
+ fn purge_from_order ( & mut self , item : & T , count : & u64 ) {
64
+ if let Some ( order) = self . order . get_mut ( count) {
65
65
// If there was data there, remove the existing item
66
66
if !order. is_empty ( ) {
67
67
order. retain ( |i| i != item) ;
68
68
if order. is_empty ( ) {
69
- self . order . remove ( & count) ;
69
+ self . order . remove ( count) ;
70
70
}
71
71
} ;
72
72
} ;
@@ -78,7 +78,7 @@ impl<T: Hash + Eq + PartialEq + Clone + Display> Counter<T> {
78
78
79
79
/// Update the internal item order HashMap
80
80
fn update_order ( & mut self , item : T , old_count : & u64 , new_count : & u64 ) {
81
- self . purge_from_order ( & item, * old_count) ;
81
+ self . purge_from_order ( & item, old_count) ;
82
82
match self . order . get_mut ( new_count) {
83
83
Some ( v) => {
84
84
v. push ( item) ;
@@ -91,7 +91,7 @@ impl<T: Hash + Eq + PartialEq + Clone + Display> Counter<T> {
91
91
92
92
/// Increment an item into the counter, creating if it does not exist
93
93
fn increment ( & mut self , item : T ) {
94
- let old_count = * self . state . get ( & item) . unwrap_or ( & 0 ) ;
94
+ let old_count = self . state . get ( & item) . unwrap_or ( & 0 ) . to_owned ( ) ;
95
95
let new_count = old_count. checked_add ( 1 ) ;
96
96
match new_count {
97
97
Some ( count) => self . state . insert ( item. to_owned ( ) , count) ,
@@ -102,7 +102,7 @@ impl<T: Hash + Eq + PartialEq + Clone + Display> Counter<T> {
102
102
103
103
/// Reduce an item from the counter, removing if it becomes 0
104
104
fn decrement ( & mut self , item : T ) {
105
- let old_count = * self . state . get ( & item) . unwrap_or ( & 0 ) ;
105
+ let old_count = self . state . get ( & item) . unwrap_or ( & 0 ) . to_owned ( ) ;
106
106
let new_count = old_count. checked_sub ( 1 ) ;
107
107
match new_count {
108
108
Some ( count) => {
@@ -121,10 +121,9 @@ impl<T: Hash + Eq + PartialEq + Clone + Display> Counter<T> {
121
121
122
122
/// Remove an item from the counter completely
123
123
fn delete ( & mut self , item : & T ) {
124
- if let Some ( count) = self . state . get ( item) {
125
- self . purge_from_order ( item, * count) ;
126
- self . purge_from_state ( item) ;
127
- }
124
+ let count = self . state . get ( item) . unwrap ( ) . to_owned ( ) ;
125
+ self . purge_from_order ( item, & count) ;
126
+ self . purge_from_state ( item) ;
128
127
}
129
128
}
130
129
0 commit comments