Davion ruined my nice, long email I'd typed out. But I do still have some
things to add. Mostly math.
(I call them buckets too, btw)
And memory chunks are generally in powers of 2 because the page size and
memory segment size are in powers of 2. You theoretically have fewer page
faults, don't cross as many memory sectors, and other things that can slow
down memory access.
Now I am guessing that if I needed to loop through all the vnums,
then the hash would be more efficient, but if I only need to check the
exits on 100-300 vnums the for would be more efficient.
You're absolutely right.
In CS terms, we say searching the whole list (which is what you're doing when
you loop through the entire hash) is bound by n, and searching one bucket like
with get_room_index is bound by n/b (where n is the number of rooms, and b is
the number of buckets).
When comparing the two search algorithms you mentioned, it's slightly
different. The search of the whole list is still bound by n, but the search
by get_room_index is now bound by (n/b) * how many rooms you're searching for.
If you'll notice, b*n/b == n, so there's a certain point where you break even
(the number of rooms searched for equals the number of buckets).
The hash size (number of buckets) in stock ROM is 1024, so unless your area is
pretty big, the loop over get_room_index is algorithmically better.
It's also more readable and more maintainable, which is a Good Thing.
--Palrich.
----- Original Message -----
From: "Rick St Jean" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Wednesday, December 22, 2004 12:29 AM
Subject: efficiency lesson
Hi Guys,
I have a question about efficiency, because I am still extremely green
to c programming.
I am writing a function that will loop through all the rooms in an area,
check the exits and see if any of the areas attached are owned by
the clan attempting to claim.
I noticed that there are basically two methods of attacking this.
1 uses a MAX_KEY_HASH, like in exlist.
and one that uses a for loop like rlist.
Now I am guessing that if I needed to loop through all the vnums,
then the hash would be more efficient, but if I only need to check the
exits on 100-300 vnums the for would be more efficient.
In truth I have no idea of how the hash is moving through memory
as compared to the for loop.
1 so my question is which would be more efficient, and would anyone
know of a resource that would explain how to use this hash, because
I am totally lost. I can hack my way through it very easily, but I would
like to start to learn how memory is used and how to make the most
efficient use of it.
Thanks.
Rick.
--
ROM mailing list
[email protected]
http://www.rom.org/cgi-bin/mailman/listinfo/rom