classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: java.util.HashSet


From: Artur Biesiadowski
Subject: Re: java.util.HashSet
Date: Sat, 8 Sep 2001 11:12:37 +0200 (CEST)

On Fri, 7 Sep 2001, Eric Blake wrote:

> I was just looking at the code for HashSet tonight, and noticed that it
> just uses HashMap as its backing store.  This may be the way that Sun
> does it, according to their javadoc, but I don't think the
> implementation is a necessary detail; just the API and behavior.  And it
> seems to me that making a HashMap of (Object, java.lang.Boolean.TRUE)
> pairs is a waste of memory and processor time, when the set could be
> implemented directly.

It is not so obvious about memory and processor time. With code resuse,
you save bytecode, reducing amount of space taken by jitted methods and
save processor time spent on jitting them. On the other hand you take up
more space on heap and have slight overhead for each call.

Probably having specialized HashSet would provide savings after all. But
this is not so obvious. And you have a drawback of having to manually
synchronized two pieces of code.


Artur




reply via email to

[Prev in Thread] Current Thread [Next in Thread]