-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhash.c
57 lines (46 loc) · 778 Bytes
/
hash.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
#include "c2ada.h"
hash_t common_hash(char* str)
{
hash_t val;
for(val = HASH_PRIME; *str; str++)
{
val -= (hash_t)*str;
}
return val;
}
int lcase(int c)
{
if(c >= 'A' && c <= 'Z')
{
return c - 'A' + 'a';
}
return c;
}
hash_t lcase_hash(char* str)
{
hash_t val;
char c;
for(val = HASH_PRIME; *str; str++)
{
c = lcase(*str);
val -= (hash_t)c;
}
return val;
}
int lcasecmp(char* s1, char* s2)
{
char c1, c2;
for(;;)
{
c1 = lcase(*s1++);
c2 = lcase(*s2++);
if(c1 != c2 || c1 == 0)
break;
}
/*
* return 0 if s1 == s2
* return <0 if s1 < s2
* return >0 if s1 > s2
*/
return ((int)c1) - ((int)c2);
}