/[ascend]/trunk/base/generic/general/hashpjw.c
ViewVC logotype

Contents of /trunk/base/generic/general/hashpjw.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 59 - (show annotations) (download) (as text)
Sun Oct 30 01:38:20 2005 UTC (18 years, 6 months ago) by jds
File MIME type: text/x-csrc
File size: 1275 byte(s)
- prototype unit test suite based on CUnit added.
- unit tests for base/generic/general and base/generic/utilites added.
- 2nd manual rework of doxygen documentation in general and utilities.
- bug fixes (mostly general & utilities) found during test development.
- added asc_assert prototype to redirect failures to Asc_Panic() and enable decoupling assertions from NDEBUG.
- some modifications of interface & implementation to facilitate testing.
- utilities/ascPrint & utilities/ascMalloc functions now always included in base libs to minimize recompilation when an interface chooses different options.
1 /*
2 * Hash function
3 * by Tom Epperly
4 * 10/24/89
5 * Version: $Revision: 1.1 $
6 * Version control file: $RCSfile: hashpjw.c,v $
7 * Date last modified: $Date: 1997/07/18 11:38:36 $
8 * Last modified by: $Author: mthomas $
9 *
10 * This file is part of the Ascend Language Interpreter.
11 */
12
13 #include <stdio.h>
14 #include "utilities/ascConfig.h"
15 #include "utilities/ascPanic.h"
16 #include "general/hashpjw.h"
17
18 #ifndef lint
19 static CONST char HashpjwID[] = "$Id: hashpjw.c,v 1.1 1997/07/18 11:38:36 mthomas Exp $";
20 #endif
21
22 unsigned long hashpjw(register CONST char *str,
23 register unsigned long int size)
24 {
25 register CONST char *p;
26 register unsigned long h=0,g;
27
28 asc_assert((NULL != str) && (size > 0));
29
30 for(p = str; *p != '\0'; p++) {
31 h = (h << 4) + (*p);
32 if (0 != (g = h&0xf0000000)) {
33 h = h ^ (g >> 24);
34 h = h ^ g;
35 }
36 }
37 return h % size;
38 }
39
40 /*
41 * This is a temporary integer hashing function.
42 * It is relatively expensive, as we first do int to str
43 * transformation. This needs to be fixed with a proper
44 * integer hashing function.
45 */
46 unsigned long hashpjw_int(int id,
47 register unsigned long int size)
48 {
49 char tmp[64];
50
51 (void)snprintf(tmp, 64, "%d", id);
52 return hashpjw(tmp, size);
53 }
54
55
56

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22