Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #19263
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Jim Janney <jjanney@shell.xmission.com> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) |
| Date | Fri, 12 Oct 2012 09:12:33 -0600 |
| Organization | objurgating the centipede |
| Lines | 70 |
| Message-ID | <ydnobk767xa.fsf@shell.xmission.com> (permalink) |
| References | <k4jua8$77d$1@news.albasani.net> <ydn4nm38kpc.fsf@shell.xmission.com> <ydnzk3u74od.fsf@shell.xmission.com> <k544ha$hj0$1@dont-email.me> <ydnvcei70lu.fsf@shell.xmission.com> <ydnr4p66x16.fsf@shell.xmission.com> <k54sau$htf$1@dont-email.me> <ydnfw5m6iw0.fsf@shell.xmission.com> <k592ob$8b4$1@news.albasani.net> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Injection-Info | mx04.eternal-september.org; posting-host="75975abe3fe3503ca7350803ab98e478"; logging-data="29774"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+JEHOM533EEeBzfuH+nkUg" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) |
| Cancel-Lock | sha1:ta7CBtslVhjCb2n7tCX+Y/qVjYs= sha1:bNvRCph+0Spbdh0T5auEaLqr2nw= |
| Xref | csiph.com comp.lang.java.programmer:19263 |
Show key headers only | View raw
Jan Burse <janburse@fastmail.fm> writes:
> Any particular reason you use WeakHashMap?
> You have:
>
> @Override
> public V remove(Object key) {
> insertionRanks.remove(key);
> return super.remove(key);
> }
>
> So I guess an ordinary HashMap would do.
I was worried about a potential memory leak, but I hadn't thought it
through. The keys are held in the TreeMap anyway, so using WeakHashMap
doesn't accomplish anything.
> Further your implementation would not generate the
> order I desire. It generates an insert-order, but
> not a first-insert-order, but last-insert-order
> since you have:
>
> @Override
> public V put(K key, V value) {
> insertionRanks.put(key, nextInsertionRank++);
> return super.put(key, value);
> };
>
> So when I do:
>
> put("2","a")
> put("1","b")
> put("2","a")
>
> I get the order "1", "2".
> But result should be "2", "1".
>
> Bye
I missed that. For first-insert order it should be
@Override
public V put(K key, V value) {
if (!insertionRanks.containsKey(key)) {
insertionRanks.put(key, nextInsertionRank++);
}
return super.put(key, value);
};
And for last-insert order the original code is wrong: it should be
@Override
public V put(K key, V value) {
super.remove(key);
insertionRanks.put(key, nextInsertionRank++);
return super.put(key, value);
};
The tree structure is based on the ordering, so if you change the
ordering you have to modify the tree also.
>
> P.S.: It is also not access order as Eric Sosman
> claims, since the get() does not influence the order.
Right. For access order you would have to remove the entry and add it
back on every get.
--
Jim Janney
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Glitch in Java Collections (No descendingMap in LinkedHashMap) Jan Burse <janburse@fastmail.fm> - 2012-10-04 14:09 +0200
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Robert Klemme <shortcutter@googlemail.com> - 2012-10-04 23:01 +0200
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Lew <lewbloch@gmail.com> - 2012-10-04 14:43 -0700
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jan Burse <janburse@fastmail.fm> - 2012-10-05 00:17 +0200
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Robert Klemme <shortcutter@googlemail.com> - 2012-10-05 19:11 +0200
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Lew <lewbloch@gmail.com> - 2012-10-05 11:05 -0700
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jan Burse <janburse@fastmail.fm> - 2012-10-05 20:18 +0200
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-10-05 12:06 -0700
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Lew <lewbloch@gmail.com> - 2012-10-05 13:04 -0700
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jan Burse <janburse@fastmail.fm> - 2012-10-05 23:44 +0200
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jan Burse <janburse@fastmail.fm> - 2012-10-05 23:50 +0200
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jan Burse <janburse@fastmail.fm> - 2012-10-06 00:00 +0200
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-10-05 23:39 +0000
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jan Burse <janburse@fastmail.fm> - 2012-10-06 12:18 +0200
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jan Burse <janburse@fastmail.fm> - 2012-10-06 12:22 +0200
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-10-05 15:51 -0700
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Robert Klemme <shortcutter@googlemail.com> - 2012-10-06 13:53 +0200
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jim Janney <jjanney@shell.xmission.com> - 2012-10-09 14:16 -0600
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jim Janney <jjanney@shell.xmission.com> - 2012-10-10 09:00 -0600
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-10-10 11:34 -0400
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jim Janney <jjanney@shell.xmission.com> - 2012-10-10 10:28 -0600
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jim Janney <jjanney@shell.xmission.com> - 2012-10-10 11:45 -0600
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Lew <lewbloch@gmail.com> - 2012-10-10 10:52 -0700
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jim Janney <jjanney@shell.xmission.com> - 2012-10-10 12:47 -0600
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jim Janney <jjanney@shell.xmission.com> - 2012-10-11 14:17 -0600
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-10-10 18:20 -0400
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jim Janney <jjanney@shell.xmission.com> - 2012-10-10 16:51 -0600
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jan Burse <janburse@fastmail.fm> - 2012-10-12 14:34 +0200
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jim Janney <jjanney@shell.xmission.com> - 2012-10-12 09:12 -0600
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-10-12 11:42 -0400
Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jan Burse <janburse@fastmail.fm> - 2012-10-12 21:02 +0200
csiph-web