Advertisement

Is this a faster way to go through a linked list?

Started by January 31, 2002 07:34 AM
16 comments, last by Jeff D 22 years, 7 months ago
Hash tables never used em. Ill search them up right now on Google. Perhaps you are right.

Thx

Jeff D


Suffered seven plagues, but refused to let the slaves go free. ~ Ross Atherton
Suffered seven plagues, but refused to let the slaves go free. ~ Ross Atherton
If need to go through the list fast but it must still be a linked list (so it can grow to any size<total memory) while not try creating a class around it that allows you to either iterate through it or to access it by ID. When access it by ID you can use a fixed array of "Last Search" pointers. Each stores a pointer to an item along with that items ID. Whenever you want to access an item by ID just check to see which pointer is closest (include the head/first item pointer and the tail pointer if the list is reverse transversable) and go from there. Once the item is found same its pointer and ID to the "Last Search" table, replacing the item to do the search or better (but harder) by timestamping each item in the "Last search" array whenever it is used so you can delete the most useless one. One of the Java linked-list classes does something like this though it only keeps one "last search" pointer.
Advertisement
quote: Original post by Fruny
What if, say CurrentItem->next->next == NULL ?
CurrentItem = CurrentItem->next->next->next->next->next will send you on a one-way trip to Segfaultland.


Haha, Segfaultland. Very original .

I would suggest using a hash table.
I looked up things about hash tables they seem quite advanced for me. heheh Im still quite new to C++. Well I was sitting down and thought. Im gonna make the weapons, armor, items, spells. I know the amount so why not just create them with arrays. Is this like a bad habit to get into with programming

Hash tables seemed confusing, maybe I''m just tired right now.

Jeff D




Suffered seven plagues, but refused to let the slaves go free. ~ Ross Atherton
Suffered seven plagues, but refused to let the slaves go free. ~ Ross Atherton
It''s not a bad idea, but take the time to look up the basics on making a template class. Then use the code I gave you, because it will save you some trouble.

If you REALLY don''t know up from down yet, I can give you a complete Array template class that I have written.

George D. Filiotis
Are you in support of the ban of Dihydrogen Monoxide? You should be!
Geordi
George D. Filiotis
Hey I take all the code I can get if its to big to put on here send to domon_m@hotmail.com. Thx

About template classes I got Teach yourself c++ in 24 hours ill take a look at it.

Jeff D




Suffered seven plagues, but refused to let the slaves go free. ~ Ross Atherton
Suffered seven plagues, but refused to let the slaves go free. ~ Ross Atherton
Advertisement
You could also use the builting vector class. Of course there is no hashing, but it can be treated just like an array. That way you have 2 options: you could make a vector for each category, ie weapons, armour, etc... or you could make a root object like CharacterStuff, derive the character items and spells from that and save them all in one vector.

---
Make it work.
Make it fast.

"Commmmpuuuuterrrr.." --Scotty Star Trek IV:The Voyage Home
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]
That''s also a good idea, when I can I''ll send you my Array class (i''m still completing some finishing touches) and then you can pick from your options

George D. Filiotis
Are you in support of the ban of Dihydrogen Monoxide? You should be!
Geordi
George D. Filiotis

This topic is closed to new replies.

Advertisement