PLplot  5.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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 //
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