Apolyton Archive  |  Preserved copy of the Apolyton Civilization Site forums as they ran on Ultimate Bulletin Board, 1998–2001. Read-only; nothing here can be posted to or replied to.  |  Forum index |  About this archive |  The 2005 site & forums

  Apolyton Civilization Site Forums
  Clash of Civilizations
  Arrays VS linked-lists

Post New Topic  Post A ReplyPost A Reply In A New Window

profile | register | preferences | faq | search next newest topic | next oldest topic bottom of page
Author
Topic:   Arrays VS linked-lists Format for Better Printing
jacobo
Chieftain

b.02-15-99
posted September 02, 1999 17:53   Click Here to See the Profile for jacoboClick Here to Email jacobo  send a private message to jacobo
Edit/Delete Message    Reply To And Quote This Message
IP: Logged, Admin Access Only
Most of the code i have seen uses arrays rather then linked lists is there a speed or other issue behind this? The main reason I ask is I am planning to make a storage for all the treaty classes(see Diplomacy thread) and am wondering what method to use.
Mark_Everson
Clash of Civilizations
Project Lead

Canton, MI, USA
b.02-15-99
posted September 02, 1999 18:49   Click Here to See the Profile for Mark_EversonClick Here to Email Mark_Everson  send a private message to Mark_EversonSend a Message to UIN: 30578681 Visit Mark_Everson's Homepage!
Edit/Delete Message    Reply To And Quote This Message
IP: Logged, Admin Access Only
I haven't done any detailed tradeoff calculations... However, arrays mean that a map square can know what its index in a provinces' squares array is, making removing it from that array Much quicker that finding it in a linked list that could have around 1000 entries late in the game. (Most of the other arrays shouldn't grow that big.) However, on the downside I need to check for array size, and sometime resize the arrays. What do the experienced programmers think about this?
mca
Chieftain
Odense, Denmark
b.02-15-99
posted September 03, 1999 13:59   Click Here to See the Profile for mcaClick Here to Email mca  send a private message to mca
Edit/Delete Message    Reply To And Quote This Message
IP: Logged, Admin Access Only
jacobo: I don't know what your experience level is, so I'll just give the lecture

It all depends on what operations you are going to use on the storage:

If the number of elements in the storage never changes, use an array. Indexing (element=storage[i] or storage[i]=element) is cheapest with arrays.

If the number of elements change over time, you may need something else.

Linked lists are cheap to iterate through, and removing/inserting elements is usually cheap, but indexing is really expensive.

Vectors (resizable arrays) feature cheap indexing and removing and inserting elements at the end of the vector is cheap, but removing/inserting elements in the middle of the vector is really expensive.

Hashtables feature somewhat cheap indexing, insert/remove, and iteration, but the elements are unordered. (They are my favorite when I want high flexibility and not high performance, and when I need to index by Strings and not ints).

The above is not the whole truth, but I think it comes close enough.

Also, you might want to take a look at the Java 2 Collection API in java.util.

Martin

JimC
Clash of Civilizations
AI Coding

Birmingham, England
May 99
posted September 03, 1999 14:02   Click Here to See the Profile for JimCClick Here to Email JimC  send a private message to JimCSend a Message to UIN: 15227822 Visit JimC's Homepage!
Edit/Delete Message    Reply To And Quote This Message
IP: Logged, Admin Access Only
Quick note:

Speed issue (may be important, may not be)....

Vector class is synchronized, ArrayList is identical but unsynchronized.

ArrayList is usually a lot faster, if you aren't using threads.

Jim

Apolyton Civilization Site Forums
> > > Clash of Civilizations Forum

next newest topic | next oldest topictop of page

All times are EDT

Administrative Options: Close Topic | Archive/Move | Delete Topic | Top
Post New Topic  Post A ReplyPost A Reply In A New Window
Hop to:

Contact Us
Apolyton Civilization Site

Powered by: Ultimate Bulletin Board, Version 5.44a
© Infopop Corporation (formerly Madrona Park, Inc.), 1998 - 2000.

Front Page | Civilization III | Dinosaurs | Civilization II | Call to Power | Call to Power II | Alpha Centauri | Alternative Civs | Misc | Links | About ACS | GameStats
GameLeague | Scenario League | HAC | Civilization Scenario Collection | Spanish CivII Site | Clash of Civs | CtP Maps | Art of War | WesW's Ctp1/2 Site