commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Colebourne" <scolebou...@btopenworld.com>
Subject Re: [collections] Array based int keyed map
Date Tue, 23 Mar 2004 22:46:18 GMT
At the moment, I would say that this is a specialised collection, presumably
to solve a particular problem you have. As such it doesn't feel right for
inclusion in [collections].
Stephen

----- Original Message -----
From: "Joel Shellman" <joel@ikestrel.com>
> Stephen Colebourne wrote:
> > 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 index
>
> Object get(int key);
> // Return value at index
>
> So.... 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" <joel@ikestrel.com>
> >
> >>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: commons-user-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message