Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6925943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:51:17+00:00 2026-05-27T10:51:17+00:00

For put and get operations OpenHashMap outperform HashMap by about 5 times: https://gist.github.com/1423303 Are

  • 0

For put and get operations OpenHashMap outperform HashMap by about 5 times: https://gist.github.com/1423303

Are any cases when HashMap should be preferred over OpenHashMap?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:51:18+00:00Added an answer on May 27, 2026 at 10:51 am

    Your code exactly matches one of the use cases for OpenHashMap. Your code:

    println ("scala OpenHashMap: " + time (warmup) {  
      val m = new scala.collection.mutable.OpenHashMap[Int,Int]; 
      var i = 0;
      var start = System.currentTimeMillis();
      while(i<100000) { m.put(i,i);i=i+1;};
    })
    

    The explanation for OpenHashMap (scaladoc):

    A mutable hash map based on an open hashing scheme. The precise scheme
    is undefined, but it should make a reasonable effort to ensure that an
    insert with consecutive hash codes is not unneccessarily penalised. In
    particular, mappings of consecutive integer keys should work without
    significant performance loss
    .

    My emphasis. Which explains your findings. When to use OpenHashMap rather than HashMap? See Wikipedia. From there:

    Chained hash tables with linked lists are popular because they require
    only basic data structures with simple algorithms, and can use simple
    hash functions that are unsuitable for other methods.

    The cost of a table operation is that of scanning the entries of the
    selected bucket for the desired key. If the distribution of keys is
    sufficiently uniform, the average cost of a lookup depends only on the
    average number of keys per bucket—that is, on the load factor.

    Chained hash tables remain effective even when the number of table
    entries n is much higher than the number of slots. Their performance
    degrades more gracefully (linearly) with the load factor. For example,
    a chained hash table with 1000 slots and 10,000 stored keys (load
    factor 10) is five to ten times slower than a 10,000-slot table (load
    factor 1); but still 1000 times faster than a plain sequential list,
    and possibly even faster than a balanced search tree.

    For separate-chaining, the worst-case scenario is when all entries
    were inserted into the same bucket, in which case the hash table is
    ineffective and the cost is that of searching the bucket data
    structure. If the latter is a linear list, the lookup procedure may
    have to scan all its entries; so the worst-case cost is proportional
    to the number n of entries in the table.

    This is a generic explanation. As ever with these things, your performance will vary depending upon the use case, if you care about it, you need to measure it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are used to saying that HashMap get/put operations are O(1). However it depends
What are running times (Big O notaton) for the common operations (get, put, size)
I am trying to get put out a simple site, which would pool the
From my understanding, each of these methods: get() and put() are atomic. But, when
Trying to get parameters from a PUT request using HttpServlet#doPut: public void doPut(HttpServletRequest request,
I get a script from a website to put it into my website, but
I just get a script from a website to put it on my own
Simply put; what does my $99 get me, that I can't already get for
How to get average of a column in terms of another column and put
I need to get a range of pages using AJAX and put them into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.