Well, I'll first say this. You don't need to use a hash :) Just do this

for( i = pArea->min_vnum ; i < pAarea->max_vnum ; i++ )
{      if( !( pRoom = get_room_index(i) ) )
                 continue;
         /* Do stuff you want done here */
}

Bam! Through all the rooms in an area. Now, about hashes. To my
understanding a hash is just an array of beginings to linked lists.
Soo, with this said, how you would cycle through the whole hash list,
is.

for( i = 0; i < MAX_KEY_HASH ; i++ )
     for(room = room_index_hash[i] ; room ; room = room->next)

The first cycles through all the 'beginings' the second cycles through
all the nodes in that specific list. What the point of them is to
index, and shorten cycling. Obviously if you had to go through every
room each time, it'd be a looong list. So it takes one biiig list,
hacks it down into many small ones, for easy, quick searching.

Now, about how its indexed. If you'd want to find, say, vnum 500, we'd

for( room = room_index_hash[500 % MAX_KEY_HASH] ; room ; room = room->next) )

Which, MAX_KEY_HASH would be 1024. I don't know why they chose that
number, if anybody knows (I asume it has to be with it being 2^10, but
who knows!)

And if 500 exits, it'll be in that particular 'bucket'. ( I like to
call each list a bucket for... some... reason.). I hope this helps
some what!

Davion

Reply via email to