2008-04-02 12:16:31 +02:00
|
|
|
/*
|
|
|
|
* ircd-ratbox: A slightly useful ircd.
|
|
|
|
* hash.h: A header for the ircd hashtable code.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
|
|
|
|
* Copyright (C) 1996-2002 Hybrid Development Team
|
|
|
|
* Copyright (C) 2002-2004 ircd-ratbox development team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA
|
|
|
|
*/
|
|
|
|
|
2016-08-13 05:05:54 +02:00
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_HASH_H
|
2008-04-02 12:16:31 +02:00
|
|
|
|
2016-08-13 05:05:54 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
namespace ircd {
|
|
|
|
|
2016-03-23 14:09:58 +01:00
|
|
|
extern rb_dictionary *nd_dict;
|
2016-03-23 14:32:22 +01:00
|
|
|
extern rb_radixtree *resv_tree;
|
2008-04-02 12:16:31 +02:00
|
|
|
|
|
|
|
/* Magic value for FNV hash functions */
|
|
|
|
#define FNV1_32_INIT 0x811c9dc5UL
|
|
|
|
|
|
|
|
/* Client hash table size, used in hash.c/s_debug.c */
|
|
|
|
#define U_MAX_BITS 17
|
|
|
|
#define U_MAX 131072 /* 2^17 */
|
|
|
|
|
2015-12-12 12:20:51 +01:00
|
|
|
/* Client connid hash table size, used in hash.c */
|
|
|
|
#define CLI_CONNID_MAX 4096
|
2008-04-06 16:52:42 +02:00
|
|
|
|
2008-04-02 12:16:31 +02:00
|
|
|
/* Channel hash table size, hash.c/s_debug.c */
|
|
|
|
#define CH_MAX_BITS 16
|
|
|
|
#define CH_MAX 65536 /* 2^16 */
|
|
|
|
|
|
|
|
/* hostname hash table size */
|
|
|
|
#define HOST_MAX_BITS 17
|
|
|
|
#define HOST_MAX 131072 /* 2^17 */
|
|
|
|
|
|
|
|
/* RESV/XLINE hash table size, used in hash.c */
|
|
|
|
#define R_MAX_BITS 10
|
|
|
|
#define R_MAX 1024 /* 2^10 */
|
|
|
|
|
|
|
|
|
|
|
|
#define HASH_WALK(i, max, ptr, table) for (i = 0; i < max; i++) { RB_DLINK_FOREACH(ptr, table[i].head)
|
|
|
|
#define HASH_WALK_SAFE(i, max, ptr, nptr, table) for (i = 0; i < max; i++) { RB_DLINK_FOREACH_SAFE(ptr, nptr, table[i].head)
|
|
|
|
#define HASH_WALK_END }
|
|
|
|
|
|
|
|
struct ConfItem;
|
|
|
|
struct nd_entry;
|
|
|
|
|
2016-03-24 03:33:54 +01:00
|
|
|
extern uint32_t fnv_hash_upper(const unsigned char *s, int bits);
|
|
|
|
extern uint32_t fnv_hash(const unsigned char *s, int bits);
|
|
|
|
extern uint32_t fnv_hash_len(const unsigned char *s, int bits, int len);
|
|
|
|
extern uint32_t fnv_hash_upper_len(const unsigned char *s, int bits, int len);
|
2008-04-02 12:16:31 +02:00
|
|
|
|
2016-08-24 01:54:20 +02:00
|
|
|
inline auto
|
|
|
|
fnv_hash_upper(const char *const &s, const int &bits)
|
|
|
|
{
|
|
|
|
return fnv_hash_upper(reinterpret_cast<const uint8_t *>(s), bits);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline auto
|
|
|
|
fnv_hash(const char *const &s, const int &bits)
|
|
|
|
{
|
|
|
|
return fnv_hash(reinterpret_cast<const uint8_t *>(s), bits);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline auto
|
|
|
|
fnv_hash_len(const char *const &s, const int &bits, const int &len)
|
|
|
|
{
|
|
|
|
return fnv_hash_len(reinterpret_cast<const uint8_t *>(s), bits, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline auto
|
|
|
|
fnv_hash_upper_len(const char *const &s, const int &bits, const int &len)
|
|
|
|
{
|
|
|
|
return fnv_hash_upper_len(reinterpret_cast<const uint8_t *>(s), bits, len);
|
|
|
|
}
|
|
|
|
|
2008-04-02 12:16:31 +02:00
|
|
|
extern void init_hash(void);
|
|
|
|
|
2016-08-22 03:57:43 +02:00
|
|
|
extern void add_to_client_hash(const char *name, client::client *client);
|
|
|
|
extern void del_from_client_hash(const char *name, client::client *client);
|
|
|
|
extern client::client *find_client(const char *name);
|
|
|
|
extern client::client *find_named_client(const char *name);
|
|
|
|
extern client::client *find_server(client::client *source_p, const char *name);
|
2008-04-02 12:16:31 +02:00
|
|
|
|
2016-08-22 03:57:43 +02:00
|
|
|
extern void add_to_id_hash(const char *, client::client *);
|
|
|
|
extern void del_from_id_hash(const char *name, client::client *client);
|
|
|
|
extern client::client *find_id(const char *name);
|
2008-04-02 12:16:31 +02:00
|
|
|
|
2016-08-22 03:57:43 +02:00
|
|
|
extern void add_to_hostname_hash(const char *, client::client *);
|
|
|
|
extern void del_from_hostname_hash(const char *, client::client *);
|
2008-04-02 12:16:31 +02:00
|
|
|
extern rb_dlink_node *find_hostname(const char *);
|
|
|
|
|
|
|
|
extern void add_to_resv_hash(const char *name, struct ConfItem *aconf);
|
|
|
|
extern void del_from_resv_hash(const char *name, struct ConfItem *aconf);
|
|
|
|
extern struct ConfItem *hash_find_resv(const char *name);
|
|
|
|
extern void clear_resv_hash(void);
|
|
|
|
|
2016-08-22 03:57:43 +02:00
|
|
|
void add_to_cli_connid_hash(client::client *client_p, uint32_t id);
|
2016-03-26 01:49:01 +01:00
|
|
|
void del_from_cli_connid_hash(uint32_t id);
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *find_cli_connid_hash(uint32_t connid);
|
2015-12-12 12:20:51 +01:00
|
|
|
|
2016-08-13 05:05:54 +02:00
|
|
|
} // namespace ircd
|
|
|
|
#endif // __cplusplus
|