forked from adesutherland/CMS-370-BREXX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hashvalu.c
63 lines (59 loc) · 1.45 KB
/
hashvalu.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* $Id: hashvalu.c,v 1.8 2008/07/15 07:40:54 bnv Exp $
* $Log: hashvalu.c,v $
* Revision 1.8 2008/07/15 07:40:54 bnv
* #include changed from <> to ""
*
* Revision 1.7 2008/07/14 13:08:16 bnv
* MVS,CMS support
*
* Revision 1.6 2003/02/12 16:42:12 bnv
* *** empty log message ***
*
* Revision 1.5 2003/01/30 08:22:20 bnv
* Java algorithm used
*
* Revision 1.4 2002/06/11 12:37:15 bnv
* Added: CDECL
*
* Revision 1.3 2001/06/25 18:49:48 bnv
* Header changed to Id
*
* Revision 1.2 1999/11/26 09:56:55 bnv
* Added: Error message fror CE
*
* Revision 1.1 1998/07/02 17:18:00 bnv
* Initial Version
*
* Similar hash code like in Java
* hash = s[0]*31?(n-1) + s[1]*31?(n-2) + ... + s[n-1]
* The hash string of an empty string is zero
*/
#include "lstring.h"
/* --------------- Lhashvalue ------------------ */
dword __CDECL
Lhashvalue(const PLstr str) {
dword value = 0;
size_t i, l = 0;
if (LISNULL(*str)) return 0;
switch (LTYPE(*str)) {
case LINTEGER_TY:
l = sizeof(long);
break;
case LREAL_TY:
l = sizeof(double);
break;
case LSTRING_TY:
l = MIN(255, LLEN(*str));
break;
}
for (i = 0; i < l; i++)
value = 31 * value + LSTR(*str)[i];
/* for (i=0; i<l; i+=4) {
for (j=0; j<4 && i+j<l; j++)
value ^= LSTR(*str)[i+j] << (8*j);
value = (value>>3) | (value<<29);
}
*/
return value;
} /* Lhashvalue */