home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / graphtal / hash.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-19  |  928 b   |  43 lines

  1. /*
  2.  * Hash.C - character based hashing functions.
  3.  *
  4.  * Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  */
  17.  
  18. #include "Hash.h"
  19.  
  20. // string hashing by P.J. Weinberger
  21. unsigned int hash(const char* s)
  22. {
  23.   unsigned int h=0;
  24.   unsigned int g;
  25.  
  26.   for (register int i=0; s[i] != '\0'; i++) {
  27.     h = (h<<4) + s[i];
  28.     if (g = h & 0xf0000000)
  29.     {
  30.       h = h^(g>>24);
  31.       h = h^g;
  32.     }
  33.   }
  34.   return h;
  35. }
  36.  
  37. unsigned int hash(const char* s, long arg)
  38. {
  39.   return ((hash(s)<<5)+arg);
  40. }
  41.  
  42.  
  43.