xref: /netbsd/external/gpl2/xcvs/dist/src/hash.h (revision a7c91847)
1*a7c91847Schristos /*
2*a7c91847Schristos  * Copyright (C) 1986-2005 The Free Software Foundation, Inc.
3*a7c91847Schristos  *
4*a7c91847Schristos  * Portions Copyright (C) 1998-2005 Derek Price, Ximbiot <http://ximbiot.com>,
5*a7c91847Schristos  *                                  and others.
6*a7c91847Schristos  *
7*a7c91847Schristos  * Portions Copyright (C) 1992, Brian Berliner and Jeff Polk
8*a7c91847Schristos  *
9*a7c91847Schristos  * You may distribute under the terms of the GNU General Public License as
10*a7c91847Schristos  * specified in the README file that comes with the CVS source distribution.
11*a7c91847Schristos  */
12*a7c91847Schristos 
13*a7c91847Schristos /*
14*a7c91847Schristos  * The number of buckets for the hash table contained in each list.  This
15*a7c91847Schristos  * should probably be prime.
16*a7c91847Schristos  */
17*a7c91847Schristos #define HASHSIZE	151
18*a7c91847Schristos 
19*a7c91847Schristos /*
20*a7c91847Schristos  * Types of nodes
21*a7c91847Schristos  */
22*a7c91847Schristos enum ntype
23*a7c91847Schristos {
24*a7c91847Schristos     NT_UNKNOWN, HEADER, ENTRIES, FILES, LIST, RCSNODE,
25*a7c91847Schristos     RCSVERS, DIRS, UPDATE, LOCK, NDBMNODE, FILEATTR,
26*a7c91847Schristos     VARIABLE, RCSFIELD, RCSCMPFLD
27*a7c91847Schristos };
28*a7c91847Schristos typedef enum ntype Ntype;
29*a7c91847Schristos 
30*a7c91847Schristos struct node
31*a7c91847Schristos {
32*a7c91847Schristos     Ntype type;
33*a7c91847Schristos     struct node *next;
34*a7c91847Schristos     struct node *prev;
35*a7c91847Schristos     struct node *hashnext;
36*a7c91847Schristos     struct node *hashprev;
37*a7c91847Schristos     char *key;
38*a7c91847Schristos     void *data;
39*a7c91847Schristos     void (*delproc) (struct node *);
40*a7c91847Schristos };
41*a7c91847Schristos typedef struct node Node;
42*a7c91847Schristos 
43*a7c91847Schristos struct list
44*a7c91847Schristos {
45*a7c91847Schristos     Node *list;
46*a7c91847Schristos     Node *hasharray[HASHSIZE];
47*a7c91847Schristos     struct list *next;
48*a7c91847Schristos };
49*a7c91847Schristos typedef struct list List;
50*a7c91847Schristos 
51*a7c91847Schristos List *getlist (void);
52*a7c91847Schristos Node *findnode (List *list, const char *key);
53*a7c91847Schristos Node *findnode_fn (List *list, const char *key);
54*a7c91847Schristos Node *getnode (void);
55*a7c91847Schristos int insert_before (List *list, Node *marker, Node *p);
56*a7c91847Schristos int addnode (List *list, Node *p);
57*a7c91847Schristos int addnode_at_front (List *list, Node *p);
58*a7c91847Schristos int walklist (List *list, int (*)(Node *n, void *closure), void *closure);
59*a7c91847Schristos int list_isempty (List *list);
60*a7c91847Schristos void removenode (Node *p);
61*a7c91847Schristos void mergelists (List *dest, List **src);
62*a7c91847Schristos void dellist (List **listp);
63*a7c91847Schristos void delnode (Node *p);
64*a7c91847Schristos void freenode (Node *p);
65*a7c91847Schristos void sortlist (List *list, int (*)(const Node *, const Node *));
66*a7c91847Schristos int fsortcmp (const Node *p, const Node *q);
67