YAP
7.1.0
hash.h
1
/*
2
Copyright (C) 2004,2005,2006 (Nuno A. Fonseca) <nuno.fonseca@gmail.com>
3
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License
6
as published by the Free Software Foundation; either
7
version 2 of the License, or (at your option) any later
8
version.
9
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
14
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19
20
Last 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
40
struct
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
};
45
typedef
struct
bucket
hashnode
;
46
47
48
struct
hashtable_s
{
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;
57
typedef
struct
hashtable_s
*
hashtable
;
58
59
/* functions */
60
hashtable
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);
65
int
insere(
hashtable
,ulong,__ptr_t);
66
void
free_hashtable(
hashtable
);
67
68
void
init_hash_traversal(
hashtable
table);
69
__ptr_t next_hash_object(
hashtable
table);
70
__ptr_t next_hashnode(
hashtable
table);
71
#endif
bucket
Definition:
hash.h:40
hashtable_s
Definition:
hash.h:48
library
lammpi
hash.h
Generated by
1.9.3