A little confused ;-) Are you proposing a class that implements Map, or List, or Collection?
The required operations are:
int add(Object newObject);
// Add new object to end of array or fill in a whole
// Returns the new int key for it (which is the index
// in the array)void set(int key, Object newObject);
// Set the value at a specific indexObject get(int key);
// Return value at indexSo.... yeah, it doesn't fit List or Map.
It is an int to Object Map, but looking at primitives, it doesn't appear to have anything like that in their currently.
As for the advantage over ArrayList. ArrayList does not give you a lookup mechanism, which is the whole point of what I'm after. Let's say you add two items in an ArrayList. Even if kept track of which index they were at, if you removed the first one, the second one's index would change, so you can't use that.
-joel shellman
If its an int to Object Map, then [primitives] would be the place for it to go. If its a List, then the implementation you describe would violate the List interface. If its a Collection, then it might work, but I can't really see the advantage over an ArrayList style implementation.
Stephen
----- Original Message ----- From: "Joel Shellman" <[EMAIL PROTECTED]>
At least I think that describes it.
Here's the application: I have a very large collection of objects that has an int key. Structural changes (add/remove) occur extremely seldom.
Wouldn't it be useful to have a data structure such that accessing it by that key is simply an array lookup?
myObject = myArray[key];
Removal support could be handled by setting that index to null and holding on to a stack of unused indexes. Adding new values use up the unused indexes before appending to the end.
I have already written a simple initial implementation of this. I'm wondering:
1) Do others think this is generally useful? 2) Is this functionality already available in the commons-collections and I missed it? 3) Would it be useful to include this in commons-collections?
Thank you,
Joel Shellman
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
