Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 59036 invoked from network); 6 Jun 2009 04:10:57 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 6 Jun 2009 04:10:57 -0000 Received: (qmail 23795 invoked by uid 500); 6 Jun 2009 04:11:07 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 23683 invoked by uid 500); 6 Jun 2009 04:11:07 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 23656 invoked by uid 99); 6 Jun 2009 04:11:07 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 06 Jun 2009 04:11:07 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [193.191.180.221] (HELO host221.post.be) (193.191.180.221) by apache.org (qpsmtpd/0.29) with SMTP; Sat, 06 Jun 2009 04:10:57 +0000 Received: from (unknown [10.192.47.117]) by host221.post.be with smtp id 1831_01fa_fc9f4ad8_524f_11de_99f0_001422111266; Sat, 06 Jun 2009 06:10:36 +0200 Received: from post-lb4 ([10.192.31.217] helo=SWPR073.post.bpgnet.net) by maillog-out.netpost with esmtp (Exim 4.66) (envelope-from ) id 1MCnEq-0001F7-4k for user@commons.apache.org; Sat, 06 Jun 2009 06:10:36 +0200 Received: from SWPR064.post.bpgnet.net ([10.192.200.61]) by SWPR073.post.bpgnet.net with Microsoft SMTPSVC(6.0.3790.3959); Sat, 6 Jun 2009 06:10:36 +0200 x-mimeole: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----_=_NextPart_001_01C9E65C.BD40CD23" Subject: RE: [Collections] LinkedMap question Date: Sat, 6 Jun 2009 06:10:34 +0200 Message-ID: <42023047418D9F49BF30178F5FB3BE7301D0EABD@SWPR064.post.bpgnet.net> X-MS-Has-Attach: X-MS-TNEF-Correlator: <42023047418D9F49BF30178F5FB3BE7301D0EABD@SWPR064.post.bpgnet.net> Thread-Topic: [Collections] LinkedMap question Thread-Index: AcnmEC1BeY2TZeS1SmKpVHgLRz38bQADCzZwAA/VcUo= References: <067b01c9e610$2dc2dbe0$894893a0$@net> <06d401c9e62b$e4da1710$ae8e4530$@net> From: "JEFFREY Mark" To: "Commons Users List" X-OriginalArrivalTime: 06 Jun 2009 04:10:36.0037 (UTC) FILETIME=[BE456B50:01C9E65C] X-NAI-Spam-Flag: NO X-NAI-Spam-Level: X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0.5 X-NAI-Spam-Version: 2.1.0.8571 : core <3291> : streams <226858> : uri <41089 X-Virus-Checked: Checked by ClamAV on apache.org ------_=_NextPart_001_01C9E65C.BD40CD23 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi Andrew, Have you tried java.util.LinkedHashMap? It retains insertion order and remove() seems to be handled correctly = (from code inspection), is this what you want? cheers, Mark *

This class provides all of the optional Map operations, = and * permits null elements. Like HashMap, it provides = constant-time * performance for the basic operations (add, contains = and * remove), assuming the hash function disperses elements * properly among the buckets. Performance is likely to be just = slightly * below that of HashMap, due to the added expense of = maintaining the * linked list, with one exception: Iteration over the collection-views * of a LinkedHashMap requires time proportional to the = size * of the map, regardless of its capacity. Iteration over a = HashMap * is likely to be more expensive, requiring time proportional to its * capacity. -----Original Message----- From: Andrew M [mailto:andrew@oc384.net] Sent: Sat 06/06/2009 00:20 To: 'Commons Users List' Subject: RE: Collections LinkedMap question =20 I just tested the speed of=20 Int x =3D myLinkedMap.indexOf(someObject); It's running in linear time. A 10x increase in map size results in a 10x increase in indexOf() lookup time. org.apache.commons.collections.map.ListOrderedMap is the same way so = neither of these work for me. I need something like a List whose indexOf() = runs in constant time. =20 I need methods like: myCollection.add(object);=20 Object o =3D myCollection.get(index); //fast like an Arraylist int index =3D myCollection.indexOf(object); //fast like a HashMap Object->Index myCollection.remove(object); //index of every Object right of the = deleted object shifts left by one per List interface I had been using both a Vector and HashMap in a TableModel of Order = objects as shown below. That works fine until I want to delete items. Then the HashMap of OrderId->Row is no longer correct above the row deleted. = Surely someone has an elegant solution for stuff like this?=20 HashMap orderIdToRowMap =3D new HashMap(); Vector displayedVector =3D new Vector(); public void entryInserted(Order o) { synchronized (displayedVector) { int row =3D displayedVector.size(); orderIdToRowMap.put(o.getID(), row); displayedVector.add(row, o); fireTableRowsInserted(row, row); } } =20 public void entryUpdated(Order o) { synchronized (displayedVector) { int row =3D orderIdToRowMap.get(o.getID()); displayedVector.set(row, o); fireTableRowsUpdated(row, row); } } =20 public void entryDeleted(Order o) { synchronized (displayedVector) { int row =3D orderIdToRowMap.get(o.getID()); orderIdToRowMap.remove( o.getID() ); displayedVector.remove(row);=20 // HashMap no longer accurate this.fireTableRowsDeleted(row, row); } } public Order getDisplayedOrder(int row) { synchronized (displayedVector) { return displayedVector.get(row); } } Suggestions? Thanks! Andrew --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org ------_=_NextPart_001_01C9E65C.BD40CD23 Content-Type: text/plain; charset=us-ascii --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org ------_=_NextPart_001_01C9E65C.BD40CD23--