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

Support for HashMap? #21

Open
hoang17 opened this issue Jan 16, 2021 · 1 comment
Open

Support for HashMap? #21

hoang17 opened this issue Jan 16, 2021 · 1 comment

Comments

@hoang17
Copy link

hoang17 commented Jan 16, 2021

Hi,

First of all, thank you for the great library! I am using this for a personal project. Any chance for supporting HashMap?

Best regards,

@twop
Copy link
Owner

twop commented Jan 17, 2021

Hey @hoang17 I didn't have immediate need at the time and decided to defer adding new types until the need arrives.

It is possible that the time is now :)

There are two main questions how to approach this:

  1. What data structure will be used in JS?
  2. What kind of limitations/restrictions need to be in place?

They are kinda related to each, and here is my thoughts:

  • I would love to avoid building custom types (like immutablejs or mobx-state-tree do).
  • That leaves us either with native Map or plain object
  • Out of these I prefer native Map
  • which can potentially use any types for keys but in our use case it boils down to 'number' (f32, f64, i32) or string
  • at the time that restriction seemed to be major enough to defer the decision until I get more info.

I actually did a work around for one of my use cases: Have a collection of Vec(Tuple(Key, Value)). In reality that is how serde internally transforms maps, of course, that incurs significant overhead on both sides to transform data to a 'Map' structure. For me it worked fine because there were not many values passed in.

@hoang17 pls let me know what are your thoughts and could you tell me more about your use case?
I think adding a HashMap shouldn't be too hard, I probably can hack it within a day with the Key limited to numbers or strings.

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

No branches or pull requests

2 participants