Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  Sequential Map  (Read 1397 times)
0 Members and 2 Guests are viewing this topic.
Offline Sanxion

Jr. Member
**

Posts: 55


Java games rock!


« on: 2003-08-30 17:46:54 »

I need to:
1) retrieve values using keys
2) be able to iterate the contents in the order they were inserted.

I can't find this functionality in any of the Maps. Have I missed one or I must I make my own? If thats the case, how to make it speedy for get and iteration.
Offline tom

JGO Neuromancer
****

Posts: 1113
Medals: 5



« Reply #1 on: 2003-08-30 18:31:31 »

Don't believe there exist a Map that does exactly this. I would suggest you make your own class using a Hastable for 1) and a Vector for 2).

The other option would be to use a SortedMap where you use your own Comparable interface. But I guess you would have to bake in a insertion id in the key.

Offline kevglass
« League of Dukes »

JGO Kernel
*****

Posts: 5214
Medals: 49


Mentally unstable, best avoided.


« Reply #2 on: 2003-08-31 01:46:42 »

You could always wrap a list and a map into one object. It might save you worrying about implemenation and you could rely on the exiting collections for performance.

Kev

Games published by our own members! Go get 'em!
Offline Sanxion

Jr. Member
**

Posts: 55


Java games rock!


« Reply #3 on: 2003-08-31 04:09:34 »

Would using two Arrays be a good idea?

String [] keys;
Object [] values;

I don't need to modify its contents beyond initialization of the program.
Offline NVaidya

Jr. Member
**

Posts: 95


Java games rock!


« Reply #4 on: 2003-08-31 04:14:50 »


If you haven't already examined it, check out
java.util.LinkedHashMap. I've found it very useful
on specific occassions.


Gravity Sucks !
Offline Sanxion

Jr. Member
**

Posts: 55


Java games rock!


« Reply #5 on: 2003-09-01 06:36:45 »

LinkedHashMap worked perfectly. I wonder if a I would gain anything by implementing my own thing based on Arrays? Isn't Arrays the most effiecient way to iterate objects?
Offline troggan

Full Member
**

Posts: 113


no guts no glory


« Reply #6 on: 2003-09-01 07:54:46 »

You could gain a little bit speed with implementing that. but i don't think it's worth the work Wink.

Never forget: write first, profile, fix all things that are too slow.

Don't try to optimize before profiling Cheesy.

troggan

(http://www.wannawork.de) - Will work for food
(http://tvbrowser.org) - Java EPG
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.093 seconds with 19 queries.