PLplot 5.15.0
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
20struct hashtable;
21typedef struct hashtable hashtable;
22
23//* Copies a key. The key must be able to be deallocated by free().
24//
25typedef void* ( *ht_keycp )( void* );
26
27//* Returns 1 if two keys are equal, 0 otherwise.
28//
29typedef int ( *ht_keyeq )( void*, void* );
30
31//* Converts key to an unsigned integer (not necessarily unique).
32//
33typedef 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//
43
44//* Create a hash table of specified size and key type.
45//
46hashtable* ht_create_d1( int size ); // double[1]
47hashtable* ht_create_d2( int size ); // double[2]
48hashtable* 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//
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//
66void* 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//
75void* 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//
85void* 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//
93void ht_process( hashtable* table, void ( *func )( void* ) );
94
95#endif // _HASH_H
int(* ht_keyeq)(void *, void *)
Definition hash.h:29
hashtable * ht_create_d2(int size)
Definition hash.c:401
hashtable * ht_create(int size, ht_keycp cp, ht_keyeq eq, ht_key2hash hash)
Definition hash.c:54
hashtable * ht_create_d1(int size)
Definition hash.c:396
void * ht_find(hashtable *table, void *key)
Definition hash.c:210
hashtable * ht_create_str(int size)
Definition hash.c:406
unsigned int(* ht_key2hash)(void *)
Definition hash.h:33
void ht_destroy(hashtable *table)
Definition hash.c:102
void ht_process(hashtable *table, void(*func)(void *))
Definition hash.c:290
void * ht_insert(hashtable *table, void *key, void *data)
Definition hash.c:135
void * ht_delete(hashtable *table, void *key)
Definition hash.c:233
void *(* ht_keycp)(void *)
Definition hash.h:25
ht_bucket ** table
Definition hash.c:47
ht_keyeq eq
Definition hash.c:45
ht_keycp cp
Definition hash.c:44
int size
Definition hash.c:40
ht_key2hash hash
Definition hash.c:46