rust
rust copied to clipboard
Implement new Concept Exercise: hashmap
This issue describes how to implement the hashmap concept exercise for the Rust track.
Getting started
Please please please read the docs before starting. Posting PRs without reading these docs will be a lot more frustrating for you during the review cycle, and exhaust Exercism's maintainers' time. So, before diving into the implementation, please read up on the following documents:
Please also watch the following video:
Goal
The hashmap collection is a commonly-used collection in Rust that has many miscellaneous methods associated with it. This concept exercise should serve as an introduction to the common-case usage of HashMaps, though it is not intended to cover its usage exhaustively.
Learning objectives
Student should be able to...
- call basic HashMap methods such as:
newinsertcontains_keyremoveget
- collect a vector of tuples into a HashMap
- recognize a few good use-cases for HashMaps
Student may be able to...
- work with similar collections such as HashSets and/or BTreeMaps, due to the similarities between their APIs and HashMap's
Out of scope
- The entry API (this will be covered in a separate concept exercise)
- HashMap internals and how they work
Concepts
- HashMaps
Prerequisites
This exercise should depend only on a basic understanding of functions, types, and variables. They need to know enough to be able to shove something into a HashMap, after all.
Is it before or after methods? Is it before or after Iterator? Is it before or after generics? The lesson may change accordingly. Including variances is not required: assume the most minimal form. Additional content for possible usage may be included in the .meta folder of the exercise.
Resources to refer to
Hints
- The HashMap documentation: https://doc.rust-lang.org/std/collections/struct.HashMap.html
- Rust by Example: https://doc.rust-lang.org/rust-by-example/std/hash.html
After
- The HashMap source code is fun to explore: https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#202-204
- Alexis Beingessner wrote a great post on the inner workings of Rust's HashMap implementation for those interested in the topic: http://cglab.ca/~abeinges/blah/robinhood-part-1/
Representer
This should require no special changes to the representer.
Analyzer
This should require no special changes to the analyzer.
Implementing
See our implementation guide for guidance. In addition, you may want to make use of the shell script while in the concept directory
Help
If you have any questions while implementing the exercise, please post the questions as comments in this issue.
I’d be tempted to expose people to the rabin-karp algorithm as an example of how to use a hashtable. https://www.freecodecamp.org/news/the-rabin-karp-algorithm-explained/
The exercise could be framed as “we want you to write a plagiarism detector for exercism submissions “ :-)
(It’s an algorithm I would love to have come across earlier and it’s pretty easy).
After several failed attempts to create a high-quality syllabus, I believe any future attempts will have to do their own design work from scratch.