Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #21382

Re: idea for more efficient HashMap

From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.java.programmer
Subject Re: idea for more efficient HashMap
Date 2013-01-13 19:44 +0100
Message-ID <algdl5Ff2dvU1@mid.individual.net> (permalink)
References <9hc2f8ltgn1bmdsrk8vb9kuu1vi5dkl2r5@4ax.com>

Show all headers | View raw


On 12.01.2013 10:55, Roedy Green wrote:
> Inside HashMap are little glue Entry objects that point to the key and
> value.
>
> What if you could implement an interface on your objects so that
> HashMap could use them directly without separate key or Entry glue?.
>
> e.g. getKey()
>         getPrev()
>         getNext()
>         setPrev()
>         setNext()
>
> One drawback would be your objects could live on only one such
> space-efficient HashMap.

I've once implemented a hash map which uses double hashingand uses a 
single Object[] for storage of keys and values.  It creates Entry 
instances on the fly while iterating.  We did this to get rid of a few 
hundred thousand Entry instances and improve GC behavior of the 
application.  Works pretty good.

http://en.wikipedia.org/wiki/Double_hashing

Side benefit of that implementation was that you get 
ConcurrentModificationException only if the map needed to be resized as 
part of an insert operation.

I cannot share this implementation here as it is proprietary code.  But 
you should pretty much have everything to implement it yourself.  If you 
do it do not forget to create meaningful unit tests.

Kind regards

	robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

idea for more efficient HashMap Roedy Green <see_website@mindprod.com.invalid> - 2013-01-12 01:55 -0800
  Re: idea for more efficient HashMap v_borchert@despammed.com (Volker Borchert) - 2013-01-12 14:21 +0000
  Re: idea for more efficient HashMap Robert Klemme <shortcutter@googlemail.com> - 2013-01-13 19:44 +0100
  Re: idea for more efficient HashMap Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2013-01-14 21:56 -0800
    Re: idea for more efficient HashMap Robert Klemme <shortcutter@googlemail.com> - 2013-01-16 14:31 -0800
      Re: idea for more efficient HashMap Lars Enderin <lars.enderin@telia.com> - 2013-01-17 10:23 +0100
        Re: idea for more efficient HashMap Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2013-01-17 19:30 -0800
          Re: idea for more efficient HashMap Robert Klemme <shortcutter@googlemail.com> - 2013-01-20 20:28 +0100
          Re: idea for more efficient HashMap Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-01-20 14:49 -0500
          Re: idea for more efficient HashMap Roedy Green <see_website@mindprod.com.invalid> - 2013-01-29 01:41 -0800
            Re: idea for more efficient HashMap Arne Vajhøj <arne@vajhoej.dk> - 2013-01-29 22:03 -0500
              Re: idea for more efficient HashMap Gene Wirchenko <genew@telus.net> - 2013-01-30 11:34 -0800
                Re: idea for more efficient HashMap Arne Vajhøj <arne@vajhoej.dk> - 2013-01-30 21:35 -0500
                Re: idea for more efficient HashMap Gene Wirchenko <genew@telus.net> - 2013-01-31 10:47 -0800
                Re: idea for more efficient HashMap Arne Vajhøj <arne@vajhoej.dk> - 2013-02-01 19:57 -0500

csiph-web