about summary refs log tree commit diff stats
path: root/src/LYHash.c
blob: 6feca1e663cc8207173f7735b3d3608e1cd610b2 (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
/* A hash table for the (fake) CSS support in Lynx-rp
 * (c) 1996 Rob Partington
 */
#include <LYHash.h>

#ifdef USE_COLOR_STYLE

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

#define HASH_SIZE CSHASHSIZE
#define HASH_OF(h, v) ((int)((h) * 3 + UCH(v)) % HASH_SIZE)

int hash_code(const char *string)
{
    int hash;
    const char *p;

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

    return hash;
}

int hash_code_lowercase_on_fly(const char *string)
{
    int hash;
    const char *p;

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

    return hash;
}

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

int hash_code_aggregate_lower_str(const char *string, int hash_was)
{
    int hash;
    const char *p;

    for (p = string, hash = hash_was; *p; p++)
	hash = HASH_OF(hash, TOLOWER(*p));

    return hash;
}

#endif /* USE_COLOR_STYLE */