Craig,
> -----Original Message-----
> From: Craig McClanahan [mailto:craigmcc@apache.org]
> Alex Karasulu wrote:
>
> >I'm probably outta luck if one does not exist in the primitives
> >packages.
> Your search is likely to be in vain ... primitives like "int" in Java
> are not actually objects. The best you can do is make your keys
> instances of the corresponding wrapper classes (like java.lang.Integer)
> if you want to actually implement the java.util.Map contract.
Yeah but I don't want to create objects.
> It's possible that the auto-boxing features in JDK 1.5 can create a
> convincing simulation that you're really using primitives as keys, but
> under the covers it will still be using wrapper objects even there.
I found a few implementations out there that claim to be maps that key
off of an int because and hence lack the need to wrap it using an Integer.
However I don't think they're compatible with the ASL. I'll probably
have to write one myself. Anyway here's a link to one's javadocs:
http://www.ognl.org/2.6.3/Documentation/javadoc/ognl/IntHashMap.html
I was trying to determine if it's worth while implementing such
a construct for commons primitives. I attached the actual source
file just to show how the author is dealing with the hashing using
an int. Here's a quick look at how he hashes with an int key:
public final boolean containsKey(int key)
{
int index = (key & 0x7FFFFFFF) % table.length;
for (Entry e = table[index] ; e != null ; e = e.next) {
if ((e.hash == key) && (e.key == key)) {
return true;
}
}
return false;
}
BTW funny you in particular responded because I needed this for a
digester implementation designed for an ASN.1 BER TLV decoder.
The BERDigester class I have basically molds your original idea of
having SAX events trigger Rules and applies them to build ASN.1
messages from a BER encoded stream. Nice thing though is that
the pattern for this situation is an int[] representing the nesting
of the TLV Tag fields. The reason why I needed the primitive int hash
was because I'm building a TagTree whose nodes contain Rules and
are used for fast pattern matching. I basically would like the
primitive int hash tbl for performance reasons.
Also if you find the time perhaps you can give me your advice
on the idea. Here's the original email on the matter:
http://nagoya.apache.org/eyebrowse/ReadMsg?listName=directory-dev@incubator.
apache.org&msgNo=944
Thanks a bunch,
Alex