PLplot
5.15.0
Toggle main menu visibility
Loading...
Searching...
No Matches
hash.h
Go to the documentation of this file.
1
//--------------------------------------------------------------------------
2
//
3
// File: hash.h
4
//
5
// Purpose: Hash table header
6
//
7
// Author: Jerry Coffin
8
//
9
// Description: Public domain code by Jerry Coffin, with improvements by
10
// HenkJan Wolthuis.
11
// Date last modified: 05-Jul-1997
12
//
13
// Revisions: 18-09-2002 -- modified by Pavel Sakov
14
//
15
//--------------------------------------------------------------------------
16
17
#ifndef _HASH_H
18
#define _HASH_H
19
20
struct
hashtable
;
21
typedef
struct
hashtable
hashtable
;
22
23
//* Copies a key. The key must be able to be deallocated by free().
24
//
25
typedef
void
* ( *ht_keycp )(
void
* );
26
27
//* Returns 1 if two keys are equal, 0 otherwise.
28
//
29
typedef
int ( *
ht_keyeq
)(
void
*,
void
* );
30
31
//* Converts key to an unsigned integer (not necessarily unique).
32
//
33
typedef
unsigned
int ( *
ht_key2hash
)(
void
* );
34
35
//* Creates a hash table of specified size.
36
//
37
// @param size Size of hash table for output points
38
// @param cp Key copy function
39
// @param eq Key equality check function
40
// @param hash Hash value calculation function
41
//
42
hashtable
*
ht_create
(
int
size
,
ht_keycp
cp
,
ht_keyeq
eq
,
ht_key2hash
hash
);
43
44
//* Create a hash table of specified size and key type.
45
//
46
hashtable
*
ht_create_d1
(
int
size
);
// double[1]
47
hashtable
*
ht_create_d2
(
int
size
);
// double[2]
48
hashtable
*
ht_create_str
(
int
size
);
// char*
49
50
//* Destroys a hash table.
51
// (Take care of deallocating data by ht_process() prior to destroying the
52
// table if necessary.)
53
//
54
// @param table Hash table to be destroyed
55
//
56
void
ht_destroy
(
hashtable
*
table
);
57
58
//* Inserts a new entry into the hash table.
59
//
60
// @param table The hash table
61
// @param key Ponter to entry's key
62
// @param data Pointer to associated data
63
// @return Pointer to the old data associated with the key, NULL if the key
64
// wasn't in the table previously
65
//
66
void
*
ht_insert
(
hashtable
*
table
,
void
* key,
void
* data );
67
68
//* Returns a pointer to the data associated with a key. If the key has
69
// not been inserted in the table, returns NULL.
70
//
71
// @param table The hash table
72
// @param key The key
73
// @return The associated data or NULL
74
//
75
void
*
ht_find
(
hashtable
*
table
,
void
* key );
76
77
//* Deletes an entry from the table. Returns a pointer to the data that
78
// was associated with the key so that the calling code can dispose it
79
// properly.
80
//
81
// @param table The hash table
82
// @param key The key
83
// @return The associated data or NULL
84
//
85
void
*
ht_delete
(
hashtable
*
table
,
void
* key );
86
87
//* For each entry, calls a specified function with corresponding data as a
88
// parameter.
89
//
90
// @param table The hash table
91
// @param func The action function
92
//
93
void
ht_process
(
hashtable
*
table
,
void
( *func )(
void
* ) );
94
95
#endif
// _HASH_H
ht_keyeq
int(* ht_keyeq)(void *, void *)
Definition
hash.h:29
ht_create_d2
hashtable * ht_create_d2(int size)
Definition
hash.c:401
ht_create
hashtable * ht_create(int size, ht_keycp cp, ht_keyeq eq, ht_key2hash hash)
Definition
hash.c:54
ht_create_d1
hashtable * ht_create_d1(int size)
Definition
hash.c:396
ht_find
void * ht_find(hashtable *table, void *key)
Definition
hash.c:210
ht_create_str
hashtable * ht_create_str(int size)
Definition
hash.c:406
ht_key2hash
unsigned int(* ht_key2hash)(void *)
Definition
hash.h:33
ht_destroy
void ht_destroy(hashtable *table)
Definition
hash.c:102
ht_process
void ht_process(hashtable *table, void(*func)(void *))
Definition
hash.c:290
ht_insert
void * ht_insert(hashtable *table, void *key, void *data)
Definition
hash.c:135
ht_delete
void * ht_delete(hashtable *table, void *key)
Definition
hash.c:233
ht_keycp
void *(* ht_keycp)(void *)
Definition
hash.h:25
hashtable
Definition
hash.c:39
hashtable::table
ht_bucket ** table
Definition
hash.c:47
hashtable::eq
ht_keyeq eq
Definition
hash.c:45
hashtable::cp
ht_keycp cp
Definition
hash.c:44
hashtable::size
int size
Definition
hash.c:40
hashtable::hash
ht_key2hash hash
Definition
hash.c:46
lib
nn
hash.h
Generated on
for PLplot by
1.17.0