about summary refs log tree commit diff stats
path: root/src/LYHash.c
blob: a40f392b92de2774c6a573c0ab6833069353040e (plain) (blame)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* A hash table for the (fake) CSS support in Lynx-rp
** (c) 1996 Rob Partington
*/
#include <LYHash.h>

#ifdef USE_COLOR_STYLE

#ifdef NOT_USED

PUBLIC int hash_table[CSHASHSIZE]; /* 32K should be big enough */

PUBLIC int hash_code_rp ARGS1(char*,string)
{
    char* hash_ptr = string;
    int hash_tmp = 0xC00A | ((*hash_ptr) << 4);

    while (*hash_ptr++)
    {
	hash_tmp ^= (((*hash_ptr)<<4) ^ ((*hash_ptr)<<12));
	hash_tmp >>= 1;
    }
    return (hash_tmp % CSHASHSIZE);
}
#endif

/*
 *  This is the same function as the private HASH_FUNCTION() in HTAnchor.c,
 *  but with a different value for HASH_SIZE.
 */

#ifdef NOT_USED
#define HASH_SIZE 8193		/* Arbitrary prime.  Memory/speed tradeoff */
#else
#define HASH_SIZE CSHASHSIZE
#endif

#define HASH_OF(h, v) ((int)((h) * 3 + (unsigned char)(v)) % HASH_SIZE)

PUBLIC int hash_code ARGS1 (char*, string)
{
    int hash;
    unsigned char *p;

    for (p = (unsigned char *)string, hash = 0; *p; p++)
	hash = HASH_OF(hash,*p);

    return hash;
}

PUBLIC int hash_code_lowercase_on_fly ARGS1 (char*, string)
{
    int hash;
    unsigned char *p;

    for (p = (unsigned char *)string, hash = 0; *p; p++)
	hash = HASH_OF(hash,tolower(*(char *)p));

    return hash;
}

PUBLIC int hash_code_aggregate_char ARGS2 (char, c,int,hash)
{
    return HASH_OF(hash,c);
}

PUBLIC int hash_code_aggregate_lower_str ARGS2 (char*, string,int,hash_was)
{
    int hash;
    unsigned char *p;

    for (p = (unsigned char *)string, hash = hash_was ; *p; p++)
	hash = HASH_OF(hash,tolower(*(char *)p));

    return hash;
}

#endif /* USE_COLOR_STYLE */