Giter VIP home page Giter VIP logo

Comments (2)

coriolinus avatar coriolinus commented on May 26, 2024

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.

sabn0 avatar sabn0 commented on May 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.