tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: [OT] Help with java Lists
Date Tue, 11 Dec 2007 23:14:13 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

David,

You need a collection that is:

David kerber wrote:
> I need to have some kind of list or collection that I can search quickly
> for a specific entry

Hashed

> and then start stepping through the list item by
> item from that point.

Linked

The only implementation that meets those needs is a LinkedHashSet.
Unfortunately, there's no way to start iterating from the middle of this
type of data structure (nor any Set for that matter). Sets do not have
an ordering, but a LinkedHashSet provides an order. On the other hand,
it does not provide a way to ask "where is this item in the set"?

For that, you need a List.

I would recommend building your own data type that contains both a List
(for identifying items by index and performing manual iterating rather
than using an Iterator) and a HashMap or something similar for quick
lookups. Store your object -> list index in the map and the objects
themselves in the list. You can even write your own iterator to start in
the middle of a list once you've identified where to start.

> If it seems like I'll never get reasonable speed this way, I could
> switch to calling all the stores' data from the database at once, making
> the lists huge, but only needing to load them once.  However, this makes
> speed in searching the lists much more of an issue, and I don't know
> which way is going to give me the best overall performance for this
> report generation.

Sounds like a lot of premature optimization to me. Why not just read
what you need from the database each time?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHXxnF9CaO5/Lv0PARAvfdAKCrytFSU9v+2OKGP+0egybQYy+fkwCdGVm3
cGQmgZUDc82xeGg6gsT3ziM=
=wYjJ
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message