YAP 7.1.0
hash.h
1/*
2Copyright (C) 2004,2005,2006 (Nuno A. Fonseca) <nuno.fonseca@gmail.com>
3
4This program is free software; you can redistribute it and/or
5modify it under the terms of the GNU General Public License
6as published by the Free Software Foundation; either
7version 2 of the License, or (at your option) any later
8version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19
20Last rev: $Id: hash.h,v 1.2 2006-06-04 19:02:07 nunofonseca Exp $
21*/
22#ifndef HASH
23#define HASH
24#include <stdlib.h>
25#if defined (__cplusplus) || (defined (__STDC__) && __STDC__)
26#define __ptr_t void *
27#else /* Not C++ or ANSI C. */
28#define __ptr_t char *
29#endif /* C++ or ANSI C. */
30
31#ifndef ulong
32#define ulong unsigned long int
33#endif
34
35#ifndef NULL
36#define NULL 0
37#endif
38
39
40struct bucket {
41 struct bucket *next;
42 ulong value; /* Value >=0 used as key in the hashing*/
43 __ptr_t obj; /* pointer to a object*/
44};
45typedef struct bucket hashnode;
46
47
49 hashnode **buckets; //
50 ulong size; // number of buckets
51 ulong last_bucket; // used in searchs/ hash traversals
52 ulong n_entries; // number of entries in the hashtable
53 hashnode* last_node;
54};
55
56//typedef hashnode **hashtable;
57typedef struct hashtable_s* hashtable;
58
59/* functions */
60hashtable new_hashtable(ulong hashsize);
61__ptr_t get_next_object(hashtable,ulong);
62__ptr_t delete(hashtable,ulong);
63__ptr_t replace_object(hashtable,ulong,__ptr_t);
64__ptr_t get_object(hashtable,ulong);
65int insere(hashtable,ulong,__ptr_t);
66void free_hashtable(hashtable);
67
68void init_hash_traversal(hashtable table);
69__ptr_t next_hash_object(hashtable table);
70__ptr_t next_hashnode(hashtable table);
71#endif
Definition: hash.h:40