• Post Reply Bookmark Topic Watch Topic
  • New Topic

Good idea how to structure my data in a HashMap, HashSet or ?  RSS feed

 
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a big hashmap, here are some of the value:



The data is loaded in memory in the server, so i dont need to load the data.

Now i have to create a methoed the retrieves a int, eksample, if i retrieve 6 this is a value between -5 and 10,if have to return the value 7, the key values as you can se in
the hashmap is split up by a ";".

Yes i know i kan take ewery key and split up to tow ints and check if the value is between this 2 keys.

But what is the best way, any good ideas out there, maybe create a other form off Map, and then go into this Map to retrieve my values ?

Frank

 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I edited your post, putting your table inside code tags. This preserves the spacing. When I first looked, I couldn't tell if the key was -5 and the value was "10 7" or if the key was "-5;10" and the value 7. I think it's easier to read this way.
 
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you organising the keys? Have you got a RangeBetween class which encapsulates both extremities of the range? You can retrieve 7 from -5;10 but not vice versa. You would need a bi-directional map for that. There isn't such a thing (I don't think) in the Sun/Oracle API, but search Apache Commons, because I think they do have a bi-directional map.
If you are trying to organise the ranges in some sort of order, maybe a Tree would be more appropriate, or a tree associated with a map, of which there is an example in the Sun/Oracle API.
You might need to have some sort of comparison method (eg implementing Comparable<T> or Comparator<T>) which returns 0 if you pass 0 to -5;10 and -1 if you pass 0 to 11;20.

I presume your data are free from overlapping ranges, eg -5;10 and 1;20 would not be permitted.
 
Frank Jacobsen
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct the is no overlapping in the ranges, i can see in java 6, there is a NavigableMap, but i using java 5.0 , soo i will solve this manually i will look at treemap, and see how i can do this easy.

Thanks
 
Campbell Ritchie
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome and good luck with it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!