Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::hash + collections::hashmap #161

Closed
4 tasks done
abonander opened this issue Jul 7, 2014 · 11 comments · Fixed by #205
Closed
4 tasks done

std::hash + collections::hashmap #161

abonander opened this issue Jul 7, 2014 · 11 comments · Fixed by #205

Comments

@abonander
Copy link
Contributor

I can work on these as I've had experience with hashmaps in the past, and I just completed a small project where I had to work out some nuances with hashmaps and lifetimes (I was trying to use references [specifically string slices] as keys).

Topics (ref is an arbitrary reference type, struct or enum):

  • HashMaps, basics and use cases
  • Alternate key types, glossing over primitives and focusing on structs with #[deriving(Eq, Hash)]
  • HashSet<ref>
  • SmallIntMap<ref>

Not sure whether I should go into the underlying implementation of a common hashmap or just how to use it. Maybe compare HashMap<int, int/ref> to Vec<int/ref> and why one would prefer one over the other, and then introduce SmallIntMap<ref> as a specialized alternative. I could present my use case for Hashmaps, an RPN calculator with user-defined variables, or maybe a basic memoizer app (setting values to keys via CLI and retrieving).

@japaric
Copy link
Member

japaric commented Jul 7, 2014

Thanks for commiting to this chapter!

Topics (ref is an arbitrary reference type, struct or enum):

Looks good to me.

Not sure whether I should go into the underlying implementation of a common hashmap or just how to use it.

Main focus should be usage, you could drop as a footnote: what hasher is used, and whether the hasher is crypto-secure or not.

I don't think we should explain how the hasmap is implemented - we could drop a link to an explanation of the implementation, that the reader could follow if she wants to.

Maybe compare HashMap<int, int/ref> to Vec<int/ref> and why one would prefer one over the other, and then introduce SmallIntMap as a specialized alternative.

I'd love to see this. (There should be evidence that justifies the selection)

I could present my use case for Hashmaps, an RPN calculator with user-defined variables, or maybe a basic memoizer app (setting values to keys via CLI and retrieving).

Sound like great examples. But the fact that one can't pass arguments to the executable via the live code editor may diminish their cool factor :-/

@japaric japaric mentioned this issue Jul 7, 2014
52 tasks
@abonander
Copy link
Contributor Author

I have added the topics to the structure.json in my fork:

abonander/rust-by-example@3997d87

Topics are subject to change as I am terrible with planning.

@emkay
Copy link
Contributor

emkay commented Jul 26, 2014

Hi @cybergeek94, any update on this? Getting into HashMap myself.

@abonander
Copy link
Contributor Author

I think I've pushed quite a bit to my fork (on mobile so can't link). If
you have any suggestions feel free to comment. I had to dance back and
forth with mut because the compiler was picky about borrowing an
immutable reference of a mutable value, so it looks pretty bad.
Improvements are welcome.
On Jul 26, 2014 1:54 PM, "Michael Matuzak" notifications@github.com wrote:

Hi @cybergeek94 https://github.com/cybergeek94, any update on this?
Getting into HashMap myself.


Reply to this email directly or view it on GitHub
#161 (comment)
.

@emkay
Copy link
Contributor

emkay commented Jul 26, 2014

Thanks! I'll take a look at your branch.

@abonander
Copy link
Contributor Author

@japaric

If I want to link to the Eq or Hash traits how would I go about doing that in the Markdown?

@japaric
Copy link
Member

japaric commented Jul 28, 2014

If I want to link to the Eq or Hash traits how would I go about doing that in the Markdown?

This:

[Eq](http://doc.rust-lang.org/std/cmp/trait.Eq.html)
[Hash](http://doc.rust-lang.org/std/hash/trait.Hash.html)

turns into this:
Eq
Hash

@abonander
Copy link
Contributor Author

Right, thanks. I was hung up on Javadoc's {@link} syntax.
On Jul 28, 2014 10:50 AM, "Jorge Aparicio" notifications@github.com wrote:

If I want to link to the Eq or Hash traits how would I go about doing that
in the Markdown?

This:

Eq
Hash

turns into this:
Eq http://doc.rust-lang.org/std/cmp/trait.Eq.html
Hash http://doc.rust-lang.org/std/hash/trait.Hash.html


Reply to this email directly or view it on GitHub
#161 (comment)
.

@abonander
Copy link
Contributor Author

@emkay

I fixed the mess in the hash example. It was funky with taking a reference into a local variable. Feeding the value straight into the match block worked fine.

I also finished alt-key-types, but it feels a bit anemic. if you have any suggestions I'm willing to hear them.

@abonander
Copy link
Contributor Author

I've been making many tiny commits, I didn't realize I had to squash them before pushing them so I will probably need to do some janitorial work before I can submit the pull request.

@abonander
Copy link
Contributor Author

I have submitted a pull request that closes this issue. Comments and suggestions are welcome.

Edit: I see the Travis CI build has failed. I'll fix the errors.

Edit 2: I don't see why it's failing now. There's no error message.

abonander added a commit to abonander/rust-by-example that referenced this issue Jul 31, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants