Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: optimsed HashMap Date: Mon, 26 Nov 2012 20:28:08 -0500 Organization: A noiseless patient Spider Lines: 31 Message-ID: References: <8i70b8d0pm6ibk03ti4t2pv60jd0bctlcs@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 27 Nov 2012 01:28:14 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="ffb8f7085759b339c1002252b48331a4"; logging-data="21156"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+WVzWS3/COfcJTplR8cheM" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/17.0 Thunderbird/17.0 In-Reply-To: Cancel-Lock: sha1:qyqiPip32Vi7274Tux885rd8rJQ= Xref: csiph.com comp.lang.java.programmer:19990 On 11/26/2012 6:44 PM, Daniel Pitts wrote: > On 11/23/12 5:12 PM, Roedy Green wrote: >> Is there something like HashMap but that optimised when nearly always >> the thing you are looking up is not in the list, and when you can add >> the list of words to look up and then freeze it. >> >> I have to scan an entire website looking up every word. >> > > I don't think your use-case needs this kind of (read "micro") > optimization. However, I have often wished for a way to get a Map.Entry > for a key, which could then be used to insert a new value efficiently. > > Map.Entry getOrAddEntry(K key); > > > Map.Entry e = map.getOrAddEntry(myKey); > > if (e.getValue() == null) { > e.setValue(newValue(myKey)); > } > > useValue(e.getValue()); > > Alas, not exactly possible to add it now. java.util.concurrent.ConcurrentMap has putIfAbsent(). -- Eric Sosman esosman@comcast-dot-net.invalid