commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alex Karasulu" <>
Subject RE: [primitives] Looking for a primitive hashtable
Date Wed, 31 Mar 2004 19:24:17 GMT
> -----Original Message-----
> From: Tatu Vanhanen []
> Sent: Wednesday, March 31, 2004 2:18 AM
> To: Jakarta Commons Users List
> Subject: RE: [primitives] Looking for a primitive hashtable
> I'm not the original sender, but interesting issue though.
> > From: Rodney Waldhoff []
> ...
> > Since the existing commons-primitives component was punted out of
> > commons-collections, commons-primitives is probably the place for it
> here.
> >
> > Depending upon your density, isn't Object[] essentially an int-keyed
> map?
> Yes but no ;) Using an integer (or long, short, etc) as an index is quite
> different than using it as a hash key. As an example concider a situation
> where you would like to cache some objects to a map based on the object's
> id
> (an integer). If there are a lot of objects, it feels bad to allocate a
> lot
> of Integers to be able to use the id as a key. And it also feels bad to
> just
> allocate an Object array big enough to handle the biggest possible id and
> somehow manage the array as values are inserted, removed and updated. So:
> map functionality is needed.

I agree!

The array would be over 8 GB in size.  Basically the maximum int in Java is
2^31-1 so that's a 2Giga-element (2x10^9) array.  Each object reference is 4
bytes and so that's 8GB of memory.  So this would not acceptable.  

> It is true that a primitive-keyed-map probably uses an Object array to
> store
> the values. But to be useful as a general purpose map, an Object array
> needs
> some functionality around it. And the result is... an int-keyed map.

That's exactly my point.  Did you see how the example IntHashMap I attached
worked - it's a joke.  What we would have to implement would be similar
except we would basically need to define an IntMap interface that is
analogous to the Map interface which takes an int key.  If we're in
agreement and no one minds I'll just add the interface and start on an
implementation in commons primitives.  We can then look at those interfaces
and make sure they're what we want.  Is that cool?


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message