[concurrency-interest] ConcurrentHashMapV8

√iktor Ҡlang viktor.klang at gmail.com
Mon Oct 3 11:18:15 EDT 2011


2011/10/3 Mark Thornton <mthornton at optrak.com>

> **
> On 03/10/11 15:59, √iktor Ҡlang wrote:
>
>
>
>  A Comparator wouldn't be appropriate for a HashMap.
>
>>>
>
> Appropriate? You mean just like doing a DNS lookup in the equals of
> java.net.URL?
>
>
> A Comparator requires a domain with an ordering whereas HashMap's can be
> used on unordered domains.
>

While I agree with your stance on this in general, the contract of
Comparator does not require the parameterized type to have any total
ordering. For the subset of functionality needed in the Comparator (only 0
results are interesting), I'd prefer that over introducing yet another Noun
that is not backported into the main API. (Closable is still not implemented
everywhere)

Now, what we'd really want here is a function from T => T => Boolean, or
uncurried (T,T) => Boolean so we didn't have to come up with new names all
the time. A man can dream, I suppose.


>
>
>
>> What you need is something like:
>>
>> interface Equivalence<T> {
>>    int hash(T value);
>>    boolean isEqual(T a, T b);
>> }
>>
>
> What does hashes have to do with equivalence? Is that appropriate?
>
> interface Hashable<T> {
>   int computeHashFor(T value);
> }
>
> interface Equivalence<T> {
>   boolean isEqual(T a, T b);
> }
>
> and then require something that implements both Hashable<K> and
> Equivalence<V>
>
>
> I think Hashable might extend Equivalence as this sort of hash is tied up
> with equivalence.
>

The tie is the parameterized type signature of ? extends Hashable<K> &
Equivalence<V>,
smashing them together would really limit the usefulness and doesn't add any
value.

Cheers,
√


>
> Mark
>
>


-- 
Viktor Klang

Akka Tech Lead
Typesafe <http://www.typesafe.com/> - Enterprise-Grade Scala from the
Experts

Twitter: @viktorklang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20111003/7f3ef5f4/attachment.html>


More information about the Concurrency-interest mailing list