[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jakarta-commons-user
Subject:    RE: [primitives] Looking for a primitive hashtable
From:       "Alex Karasulu" <aok123 () bellsouth ! net>
Date:       2004-03-31 19:24:17
Message-ID: 20040331192420.VAE1729.imf24aec.mail.bellsouth.net () franklin
[Download RAW message or body]

> -----Original Message-----
> From: Tatu Vanhanen [mailto:tatu.vanhanen@graftor.fi]
> 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 [mailto:rwaldhoff@apache.org]
> ...
> > 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?

-alex



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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic