How do I implement HashMap<String,Double>

621 views
Skip to first unread message

Rajiv Abraham

unread,
Apr 16, 2013, 2:46:57 PM4/16/13
to fast...@googlegroups.com
Hi,

- How do I create an HashMap<String,Double>? I see char but no strings. Do I have to use Object2IntOpenHashMap<K>?
- Would you recommend using Char[] over String? If so, is there a way of using fastutil to have Char[] as key?

motivation: I have to create a billion of a type A which each instance has a distinct hashmap<String,Double>.
usage: Typically, I would use the the hashmap for zipping. Example

if a1.map contains  ("a",1.2) and ("b",4.5) 
and a2.map contains ("a",2.2) ,("b",9.9)and ("c",5.5)

I will zip it to give me a list of Tuples(in Scala) where the result would be a list containing ("a",1.2,2.2),("b",4.5,9.9) and ("c",None,5.5)


Warm Regards,
Rajiv


Sebastiano Vigna

unread,
Apr 16, 2013, 2:51:14 PM4/16/13
to fast...@googlegroups.com
On 16 Apr 2013, at 8:46 PM, Rajiv Abraham <rajiv....@gmail.com> wrote:

> - How do I create an HashMap<String,Double>? I see char but no strings. Do I have to use Object2IntOpenHashMap<K>?

To create a HashMap<String,Double> you do new HashMap<String,Double>(). Is that a real question?

If you mean: how do I create a fastutil hash map from strings to doubles, it's

new Object2DoubleOpenHashMap<String>.

> - Would you recommend using Char[] over String? If so, is there a way of using fastutil to have Char[] as key?

No. I could recommend using char[], but certainly not Char[]. It's a design choice. You have also to use a custom hash strategy, as equality between arrays is not by content (there are ready-made strategies for custom hashing of arrays--see the overview).

Ciao,

seba

Rajiv Abraham

unread,
Apr 16, 2013, 3:25:23 PM4/16/13
to fast...@googlegroups.com, vi...@di.unimi.it
Thanks Seba. I will check out the overview for custom hash strategy.
Reply all
Reply to author
Forward
0 new messages