Re: [guava] Java Equivalent of LinkedHashMap<Double, Double> meetingRecord

259 views
Skip to first unread message

Chris Povirk

unread,
Feb 23, 2013, 6:14:32 PM2/23/13
to Osman Khalid, guava-...@googlegroups.com
Since we wouldn't know exactly which primitive types and which
collection types users would need, we decided to stay away from
primitive collections for the most part. They're available in various
other libraries: http://stackoverflow.com/q/3307622/28465

For example: http://fastutil.di.unimi.it/docs/it/unimi/dsi/fastutil/doubles/Double2DoubleLinkedOpenHashMap.html

morten hattesen

unread,
Feb 24, 2013, 4:38:43 AM2/24/13
to guava-...@googlegroups.com
Is it not a matter of premature optimization? Autoboxing and -unboxing is quite fast, and garbage collection of short-lived objects is too. Did you analyze the performance impact?


On Sunday, February 24, 2013 12:00:02 AM UTC+1, Osman Khalid wrote:

I have a LinkedHashMap based on "Double" data types.

LinkedHashMap<Double, Double> meetingRecord;

I want it to be in primitive data type, which is not default java api

LinkedHashMap<double, double> meetingRecord;
Is there any equivalent available guava? I don't want to use loop to convert a huge list from Double to double. 

Osvaldo Doederlein

unread,
Feb 24, 2013, 11:06:44 AM2/24/13
to morten hattesen, guava-discuss
On Sun, Feb 24, 2013 at 4:38 AM, morten hattesen <morten....@gmail.com> wrote:
Is it not a matter of premature optimization? Autoboxing and -unboxing is quite fast, and garbage collection of short-lived objects is too. Did you analyze the performance impact?

This is true mostly at a small scale: when your boxed objects are few enough and short-lived enough to fit in the CPU caches, or at least in the young generation of the heap never being promoted to old space; or when collections are tiny so other overheads dominate over boxing, or when objects are used very locally so Escape Analysis is able to unbox, etc. As soon as you have boxed objects inside huge and long-lived data sets, it's all pain and weeping and gnashing of teeth.

It's rare though that the boxed values are a significant fraction of big data sets; if I have for example some memory index where the key is an Integer (perhaps the primary-key of cached entities), this is just a tiny piece of each cached entry, the bulk being the value object. A HashMap<Double, Double> is also strange because using Doubles as keys is generally not a good idea -- be always suspicious of code relying on equality comparison of floating-point values...


 
On Sunday, February 24, 2013 12:00:02 AM UTC+1, Osman Khalid wrote:

I have a LinkedHashMap based on "Double" data types.

LinkedHashMap<Double, Double> meetingRecord;

I want it to be in primitive data type, which is not default java api

LinkedHashMap<double, double> meetingRecord;
Is there any equivalent available guava? I don't want to use loop to convert a huge list from Double to double. 

--
--
guava-...@googlegroups.com
Project site: http://guava-libraries.googlecode.com
This group: http://groups.google.com/group/guava-discuss
 
This list is for general discussion.
To report an issue: http://code.google.com/p/guava-libraries/issues/entry
To get help: http://stackoverflow.com/questions/ask (use the tag "guava")
 
---
You received this message because you are subscribed to the Google Groups "guava-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to guava-discus...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages