[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
nStrHash( cString, nHashSize )-> <nHashVal>
------------------------------------------------------------------------------
PARAMETER:
<cString> Is the String whose position should be retrieved
<nHashSize> The maximum length of the hash table
RETURNS:
<nHashVal> is the position of <cString> in the hash table
DESCRIPTION:
nStrHash() calculates the position of a string in a hash table. This is
a very fast method of storing and retrieving informations in an Array.
In a Hash table, the target position of the element to be stored is
calculated by using the Index itself, doing some simple bit shifts.
This way, the retrieval of the entry can be done also by generating the
same index number, and fetching the element then by its position. This
avoids long and slow comparisons.
This technique is used to have fast access to OOP message tables.
One drawback is, that the maximum size of the table has to be known, since
it is used for the hash calculation.
EXAMPLE:
+--------------------------------------------------------------+
| /* Generate a hash table */ |
| |
| aHash := Array( 100 ) |
| aHash[ nStrhash( "Peter",100)] := cPeterData |
| aHash[ nStrhash( "Paul" ,100)] := nPaulData |
| aHash[ nStrhash( "John" ,100)] := nJohnData |
| aHash[ nStrhash( "Tom" ,100)] := xTomData |
| [ ... ] |
| |
| /* Retrieve a value */ |
| |
| nJohnData := aHash( nStrHash("John", 100 )) |
| |
+--------------------------------------------------------------+
SOURCE:
SOURCE\FUNCTIONS\HASH.C
See Also:
StrToken
StrChar
cValToChar
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson