Logo Search packages:      
Sourcecode: pwlib version File versions  Download package

PINDEX PString::HashFunction (  ) const [virtual, inherited]

Calculate a hash value for use in sets and dictionaries.

The hash function for strings will produce a value based on the sum of the first three characters of the string. This is a fairly basic function and make no assumptions about the string contents. A user may descend from PString and override the hash function if they can take advantage of the types of strings being used, eg if all strings start with the letter 'A' followed by 'B or 'C' then the current hash function will not perform very well.

hash value for string.

Definition at line 1620 of file contain.cxx.

Referenced by PRemoteConnection::HashFunction(), and PURL::HashFunction().

  // Hash function from "Data Structures and Algorithm Analysis in C++" by
  // Mark Allen Weiss, with limit of only executing over first 8 characters to
  // increase speed when dealing with large strings.

  PINDEX hash = 0;
  for (PINDEX i = 0; i < 8 && theArray[i] != 0; i++)
    hash = (hash << 5) ^ tolower(theArray[i] & 0xff) ^ hash;
  return PABSINDEX(hash)%127;

Here is the caller graph for this function:

Generated by  Doxygen 1.6.0   Back to index