• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

any object better than hashmap

 
him jain
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to store 2 keys and one value.
I have used hashmap but it's very slow for retrieval of the data as well as in searching of data.
So, can I have a better solution for it.
Please suggest me an efficient one.
Thanks
 
Kees Jan Koster
JavaMonitor Support
Rancher
Posts: 251
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Him,

Could you paste the lookup code? Unless you have some very specific requirements I would say a hashmap should perform just fine. I'm kind'a surprised you find it slow.

Kees Jan
 
him jain
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have taken a map and stored my key and value into it.
as, i have 2 keys, so i have taken one more map with parameter as key and a map.
now, i have searched for the key in this map.
It takes more than 25 minutes to search 10,000 keys.
(my map is loaded with 1 million entries).
That's why I am asking for a solution.
Please reply asap.
Thanks
 
Kees Jan Koster
JavaMonitor Support
Rancher
Posts: 251
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Him,

Please post your lookup code.

Also, how much memory does your data structure use in memory, what is the heap size you allocated for this JVM?

Does this run in a stand-alone JVM or in an application server?

Kees Jan
 
him jain
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Structure of maps:

1st map contains string of size 10 and 2nd is of numeric of 3 digits and value is of 4 characters
Heap size is 75M

Edit: I put code tags around the code to make it sort of readable. Indenting it nicely... too much trouble. -- Paul C
 
Kees Jan Koster
JavaMonitor Support
Rancher
Posts: 251
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Him,

What is wrong with this:


 
him jain
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it has taken 144s just to query 1000 times.
Please suggest me a better solution or please let me know where I am wrong in my code.
Thanks
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem isn't that you have chosen data structures which aren't very efficient. The problem is that you have chosen to use them in an extremely inefficient way. For example this code:

could be replaced by

Essentially you have taken a data structure which provides an access method which is O(1) as its standard access method, and ignored that in favour of writing your own access method which is O(N).
 
Kees Jan Koster
JavaMonitor Support
Rancher
Posts: 251
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Him,

Did you try my code?

Also note that 75M is peanuts if your map is 1.000.000 items. How much memory does your map need?

Kees Jan
 
him jain
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, It worked.
I am extremely grateful to both of you especially Mr. Kees Jan.
I got what you have pointed out.
Thank you very much
It took only 3.5 s to execute 1 million query now.
 
Kees Jan Koster
JavaMonitor Support
Rancher
Posts: 251
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Him,

That sounds a lot more like a hashmap.

Please check that you are not using more memory than your heap is large. If you use more memory than you have things will also slow down.

Kees Jan
 
him jain
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Really sir.
That really now sounds like that.
Thanks for all the info..
[removed email addresses]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic