~ubuntu-branches/ubuntu/karmic/pdnsd/karmic

« back to all changes in this revision

Viewing changes to src/hash.h

  • Committer: Bazaar Package Importer
  • Author(s): Takuo KITAME
  • Date: 2002-04-07 02:30:11 UTC
  • Revision ID: james.westby@ubuntu.com-20020407023011-6zzd1y8a8tk5fz97
Tags: upstream-1.1.7
ImportĀ upstreamĀ versionĀ 1.1.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* hash.h - Manage hashes for cached dns records
 
2
   Copyright (C) 2000 Thomas Moestl
 
3
 
 
4
This file is part of the pdnsd package.
 
5
 
 
6
pdnsd is free software; you can redistribute it and/or modify
 
7
it under the terms of the GNU General Public License as published by
 
8
the Free Software Foundation; either version 2, or (at your option)
 
9
any later version.
 
10
 
 
11
pdnsd is distributed in the hope that it will be useful,
 
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
GNU General Public License for more details.
 
15
 
 
16
You should have received a copy of the GNU General Public License
 
17
along with pdsnd; see the file COPYING.  If not, write to
 
18
the Free Software Foundation, 59 Temple Place - Suite 330,
 
19
Boston, MA 02111-1307, USA.  */
 
20
 
 
21
/* $Id: hash.h,v 1.3 2001/05/09 17:51:52 tmm Exp $ */
 
22
 
 
23
#ifndef _HASH_H_
 
24
#define _HASH_H_
 
25
#include <config.h>
 
26
#include "cache.h"
 
27
 
 
28
typedef struct {
 
29
        void          *next;
 
30
        unsigned long rhash; /* this is a better hash */
 
31
        dns_cent_t    *data;
 
32
} dns_hash_ent_t;
 
33
 
 
34
/* Redefine this if you want another hash size. Should work ;-). The number of hash buckets is computed as power of two;
 
35
 * so, eg HASH_SZ set to 10 yields 1024 hash rows (2^10 or 1<<10). Only powers of two are possible conveniently. 
 
36
 * If you modify HASH_NUM_BUCKETS, also change HASH_SZ! HASH_SZ may not be bigger than 32 (if you set it even close to
 
37
 * that value, you are nuts.)*/ 
 
38
#define HASH_NUM_BUCKETS 1024
 
39
#define HASH_SZ            10
 
40
 
 
41
#define HASH_BITMASK     (HASH_NUM_BUCKETS-1)
 
42
 
 
43
/*
 
44
 * The hash structures are the same for an ip and an dns hash, so we use
 
45
 * an additional element in debug mode to report misuse.
 
46
 */
 
47
typedef struct {
 
48
        dns_hash_ent_t *(buckets[HASH_NUM_BUCKETS]);
 
49
} dns_hash_t;
 
50
 
 
51
/* A type for position specification for fetch_first and fetch_next */
 
52
typedef struct {
 
53
        int            bucket;     /* bucket chain we are in */
 
54
        dns_hash_ent_t *ent;       /* entry */
 
55
} dns_hash_pos_t;
 
56
 
 
57
void mk_hash_ctable(void);
 
58
void mk_dns_hash(dns_hash_t *hash);
 
59
void add_dns_hash(dns_hash_t *hash,unsigned char *key, dns_cent_t *data);
 
60
dns_cent_t *del_dns_hash(dns_hash_t *hash, unsigned char *key);
 
61
dns_cent_t *dns_lookup(dns_hash_t *hash, unsigned char *key);
 
62
void free_dns_hash(dns_hash_t *hash);
 
63
 
 
64
dns_cent_t *fetch_first(dns_hash_t *hash, dns_hash_pos_t *pos);
 
65
dns_cent_t *fetch_next(dns_hash_t *hash, dns_hash_pos_t *pos);
 
66
 
 
67
#ifdef DBGHASH
 
68
void dumphash(dns_hash_t *hash);
 
69
#endif
 
70
 
 
71
#endif