]> jfr.im git - irc/rqf/shadowircd.git/blob - include/hash.h
[svn] - the new plan:
[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-2004 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 *
24 * $Id: hash.h 722 2006-02-08 21:51:28Z nenolod $
25 */
26
27 #ifndef INCLUDED_hash_h
28 #define INCLUDED_hash_h
29
30 #include "tools.h"
31
32 extern dlink_list *clientTable;
33 extern dlink_list *channelTable;
34 extern dlink_list *idTable;
35 extern dlink_list *resvTable;
36 extern dlink_list *hostTable;
37 extern dlink_list *helpTable;
38 extern dlink_list *ndTable;
39
40 /* Magic value for FNV hash functions */
41 #define FNV1_32_INIT 0x811c9dc5UL
42
43 /* Client hash table size, used in hash.c/s_debug.c */
44 #define U_MAX_BITS (32-17)
45 #define U_MAX 131072 /* 2^17 */
46
47 /* Channel hash table size, hash.c/s_debug.c */
48 #define CH_MAX_BITS (32-16)
49 #define CH_MAX 65536 /* 2^16 */
50
51 /* hostname hash table size */
52 #define HOST_MAX_BITS (32-17)
53 #define HOST_MAX 131072 /* 2^17 */
54
55 /* RESV/XLINE hash table size, used in hash.c */
56 #define R_MAX_BITS (32-10)
57 #define R_MAX 1024 /* 2^10 */
58
59
60 #define HASH_WALK(i, max, ptr, table) for (i = 0; i < max; i++) { DLINK_FOREACH(ptr, table[i].head)
61 #define HASH_WALK_SAFE(i, max, ptr, nptr, table) for (i = 0; i < max; i++) { DLINK_FOREACH_SAFE(ptr, nptr, table[i].head)
62 #define HASH_WALK_END }
63
64 struct Client;
65 struct Channel;
66 struct ConfItem;
67 struct cachefile;
68 struct nd_entry;
69
70 extern u_int32_t fnv_hash_upper(const unsigned char *s, int bits);
71 extern u_int32_t fnv_hash(const unsigned char *s, int bits);
72 extern u_int32_t fnv_hash_len(const unsigned char *s, int bits, int len);
73 extern u_int32_t fnv_hash_upper_len(const unsigned char *s, int bits, int len);
74
75 extern void init_hash(void);
76
77 extern void add_to_client_hash(const char *name, struct Client *client);
78 extern void del_from_client_hash(const char *name, struct Client *client);
79 extern struct Client *find_any_client(const char *name);
80 extern struct Client *find_client(const char *name);
81 extern struct Client *find_named_client(const char *name);
82 extern struct Client *find_server(struct Client *source_p, const char *name);
83
84 extern void add_to_id_hash(const char *, struct Client *);
85 extern void del_from_id_hash(const char *name, struct Client *client);
86 extern struct Client *find_id(const char *name);
87
88 extern struct Channel *get_or_create_channel(struct Client *client_p, const char *chname, int *isnew);
89 extern void del_from_channel_hash(const char *name, struct Channel *chan);
90 extern struct Channel *find_channel(const char *name);
91
92 extern void add_to_hostname_hash(const char *, struct Client *);
93 extern void del_from_hostname_hash(const char *, struct Client *);
94 extern dlink_node *find_hostname(const char *);
95
96 extern void add_to_resv_hash(const char *name, struct ConfItem *aconf);
97 extern void del_from_resv_hash(const char *name, struct ConfItem *aconf);
98 extern struct ConfItem *hash_find_resv(const char *name);
99 extern void clear_resv_hash(void);
100
101 extern void add_to_help_hash(const char *name, struct cachefile *hptr);
102 extern void clear_help_hash(void);
103 extern struct cachefile *hash_find_help(const char *name, int flags);
104
105 extern void add_to_nd_hash(const char *name, struct nd_entry *nd);
106 extern struct nd_entry *hash_find_nd(const char *name);
107
108 extern void hash_stats(struct Client *);
109
110 #endif /* INCLUDED_hash_h */