]> jfr.im git - irc/rqf/shadowircd.git/blob - include/hash.h
switching back on nd_dict instead of ratbox3 hash functions
[irc/rqf/shadowircd.git] / include / hash.h
1 /*
2 * ircd-ratbox: A slightly useful ircd.
3 * hash.h: A header for the ircd hashtable code.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
22 * USA
23 *
24 * $Id: hash.h 24794 2007-12-28 02:36:59Z androsyn $
25 */
26
27 #ifndef INCLUDED_hash_h
28 #define INCLUDED_hash_h
29
30 extern struct Dictionary *nd_dict;
31
32 extern rb_dlink_list resvTable[];
33 extern rb_dlink_list ndTable[];
34
35 /* Magic value for FNV hash functions */
36 #define FNV1_32_INIT 0x811c9dc5UL
37
38 /* Client hash table size, used in hash.c/s_debug.c */
39 #define U_MAX_BITS 17
40 #define U_MAX (1<<U_MAX_BITS)
41
42 /* Client fd hash table size, used in hash.c */
43 #define CLI_FD_MAX 4096
44
45 /* Channel hash table size, hash.c/s_debug.c */
46 #define CH_MAX_BITS 16
47 #define CH_MAX (1<<CH_MAX_BITS) /* 2^16 */
48
49 /* hostname hash table size */
50 #define HOST_MAX_BITS 17
51 #define HOST_MAX (1<<HOST_MAX_BITS) /* 2^17 */
52
53 /* RESV/XLINE hash table size, used in hash.c */
54 #define R_MAX_BITS 10
55 #define R_MAX (1<<R_MAX_BITS) /* 2^10 */
56
57
58 #define HASH_WALK(i, max, ptr, table) for (i = 0; i < max; i++) { RB_DLINK_FOREACH(ptr, table[i].head)
59 #define HASH_WALK_SAFE(i, max, ptr, nptr, table) for (i = 0; i < max; i++) { RB_DLINK_FOREACH_SAFE(ptr, nptr, table[i].head)
60 #define HASH_WALK_END }
61
62 typedef enum
63 {
64 HASH_CLIENT,
65 HASH_ID,
66 HASH_CHANNEL,
67 HASH_HOSTNAME,
68 HASH_RESV
69 } hash_type;
70
71 struct Client;
72 struct Channel;
73 struct ConfItem;
74 struct cachefile;
75 struct nd_entry;
76
77 uint32_t fnv_hash_upper(const unsigned char *s, unsigned int bits, unsigned int unused);
78 uint32_t fnv_hash(const unsigned char *s, unsigned int bits, unsigned int unused);
79 uint32_t fnv_hash_len(const unsigned char *s, unsigned int bits, unsigned int len);
80 uint32_t fnv_hash_upper_len(const unsigned char *s, unsigned int bits, unsigned int len);
81
82 void init_hash(void);
83
84 void add_to_hash(hash_type, const char *, void *);
85 void del_from_hash(hash_type, const char *, void *);
86
87 struct Client *find_any_client(const char *name);
88 struct Client *find_client(const char *name);
89 struct Client *find_named_client(const char *name);
90 struct Client *find_server(struct Client *source_p, const char *name);
91
92 struct Client *find_id(const char *name);
93
94 struct Channel *get_or_create_channel(struct Client *client_p, const char *chname, int *isnew);
95 struct Channel *find_channel(const char *name);
96
97 rb_dlink_node *find_hostname(const char *);
98
99 struct ConfItem *hash_find_resv(const char *name);
100 void clear_resv_hash(void);
101
102 void add_to_help_hash(const char *name, struct cachefile *hptr);
103 void clear_help_hash(void);
104 struct cachefile *hash_find_help(const char *name, int flags);
105
106 void add_to_nd_hash(const char *name, struct nd_entry *nd);
107 struct nd_entry *hash_find_nd(const char *name);
108
109 void add_to_cli_fd_hash(struct Client *client_p);
110 void del_from_cli_fd_hash(struct Client *client_p);
111 struct Client *find_cli_fd_hash(int fd);
112
113 void hash_stats(struct Client *);
114
115 #endif /* INCLUDED_hash_h */