Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #18442
| From | Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Question about HashMap and Map.Entry ... |
| Date | 2012-08-30 19:24 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <slrnk3vff3.u9l.avl@gamma.logic.tuwien.ac.at> (permalink) |
| References | <slrnk3v9ba.u9l.avl@gamma.logic.tuwien.ac.at> <k1o8uk$7m5$1@dont-email.me> <35O%r.171$_I7.84@newsfe20.iad> |
Daniel Pitts <newsgroup.nospam@virtualinfinity.net> wrote:
> On 8/30/12 10:46 AM, markspace wrote:
>> On 8/30/2012 10:39 AM, Andreas Leitgeb wrote:
>>> What I'm missing, however, is:
>>> How would I get the Entry for a given key?
>> What about: [...] I think that's what you said you are doing.
You thought essentially right, markspace ;-)
> In theory, this does more work than it needs to, computing the hash
> bucket twice,...
That lets it look like I was caring for performance and
(premature, of course) optimization, which I've indeed
often a weakness for, but which isn't relevant for this
thread.
Let's say, I've got a method that takes an Map.Entry, and
the new value, and it updates the Entry's value accordingly.
So far I happened to use it for all keys in a Map, so
I iterated the entrySet, and called the method on each
loop-cycle.
Now, I'd rather call that method for specific keys, and
that's how I'd arrive at the outset of this thread.
My choice is now:
a) duplicating the method's code into one that operates
on the map directly for a key, or inlining the method's
code directly into the loop-body. (what I did)
b) creating an anonymous "implementation" of Map.Entry
with key&value, and writing the value back to the
map unconditionally afterwards. (I don't care about
eventually overwriting with same value)
but unfortunately not:
c) getting some darned Map-backed Entry just for that
darned key ;-)
> I would like to suggest to the OP to look into Trove <...>,
> which has support for primitive collections (longs, rather
> than Longs), which may be much faster and more memory efficient,
> depending on your use-cases.
If the TLongLongHashMap had a method to return a
java.util.Map.Entry<Long,Long>, then I'd be all for it ;-)
But it was still interesting to read about adjustOrPutValue(),
foreach*() and putIfAbsent() methods. These might come in handy some
time, and it's good to know, these trove collections offer stuff beyond
merely wrapping the primitives directly, compared to java.util.HashMap.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Question about HashMap and Map.Entry ... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2012-08-30 17:39 +0000
Re: Question about HashMap and Map.Entry ... markspace <-@.> - 2012-08-30 10:46 -0700
Re: Question about HashMap and Map.Entry ... Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-08-30 11:15 -0700
Re: Question about HashMap and Map.Entry ... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2012-08-30 19:24 +0000
Re: Question about HashMap and Map.Entry ... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2012-08-30 19:32 +0000
Re: Question about HashMap and Map.Entry ... Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-08-30 13:08 -0700
Re: Question about HashMap and Map.Entry ... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2012-08-30 21:55 +0000
Re: Question about HashMap and Map.Entry ... Robert Klemme <shortcutter@googlemail.com> - 2012-08-31 07:27 +0200
Re: Question about HashMap and Map.Entry ... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2012-08-31 10:26 +0000
Re: Question about HashMap and Map.Entry ... Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-08-31 11:22 -0700
Re: Question about HashMap and Map.Entry ... Robert Klemme <shortcutter@googlemail.com> - 2012-09-01 11:06 +0200
Re: Question about HashMap and Map.Entry ... markspace <-@.> - 2012-08-30 14:30 -0700
Re: Question about HashMap and Map.Entry ... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2012-08-30 22:42 +0000
Re: Question about HashMap and Map.Entry ... markspace <-@.> - 2012-08-30 14:34 -0700
Re: Question about HashMap and Map.Entry ... Lew <lewbloch@gmail.com> - 2012-08-30 13:42 -0700
Re: Question about HashMap and Map.Entry ... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2012-08-30 22:34 +0000
csiph-web