Comments (2)
We already have a Deref
impl to give immutable access to the inner HashMap
; it sounds like what you're asking for is a DerefMut
impl. That way you could just delegate to the retain
method.
let mut counter = "abcdefgggg".chars().collect::<Counter<_>>();
counter.retain(|_ch, count| count >= 2);
let as_vec = counter.iter().collect::<Vec<_>>();
assert_eq!(as_vec, vec![('g', 4)]);
I'd be happy to review a PR adding a DerefMut
impl; it would have a straightforward path to merging. (I'm on vacation right now and may or may not find time to write such an impl myself.) I don't recommend a PR with the implementations you've suggested; they're too Vec
-oriented for my taste.
from counter-rs.
Actually I do see a DerefMut
impl on master, and you are completely correct: with both DerefMut
and the HashMap's retain
method it's possible to apply a minimal count + k_most_common_ordered
together in a nice way:
let mut counter: Counter<char, usize> = Counter::init("abcdeffgggg".chars());
counter.retain(|_, count| *count >= 2);
let by_common = counter.k_most_common_ordered(1);
let expected: Vec<(char, usize)> = vec![('g', 4)];
assert!(expected == by_common)
Thanks!
from counter-rs.
Related Issues (14)
- Use defaultmap crate HOT 3
- Most common should take a number HOT 2
- Add/Sub clone self unnecessarily HOT 7
- is_subset / is_superset methods? HOT 8
- impl<T> FromIterator<(T, usize)> for Counter<T>? HOT 2
- Suggestion: add 'multiset' and 'bag' tags to repository, README and Cargo.toml
- Suggestion: make Counter generic over the hashing algorithm HOT 2
- Refactoring & Optional data concurrency HOT 4
- Is the `zero` instance member still required?
- Counter doesn't derive Debug HOT 1
- `impl PartialOrd` via `is_{sub,super}set` HOT 1
- Make Counter generic over the count type? HOT 5
- Add into_hashmap function
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from counter-rs.