PLplot  5.10.0
hash.h
Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 //
00003 // File:           hash.h
00004 //
00005 // Purpose:        Hash table header
00006 //
00007 // Author:         Jerry Coffin
00008 //
00009 // Description:    Public domain code by Jerry Coffin, with improvements by
00010 //                 HenkJan Wolthuis.
00011 //                 Date last modified: 05-Jul-1997
00012 //
00013 // Revisions:      18-09-2002 -- modified by Pavel Sakov
00014 //
00015 //--------------------------------------------------------------------------
00016 
00017 #ifndef _HASH_H
00018 #define _HASH_H
00019 
00020 struct hashtable;
00021 typedef struct hashtable   hashtable;
00022 
00023 //* Copies a key. The key must be able to be deallocated by free().
00024 //
00025 typedef void* ( *ht_keycp )( void* );
00026 
00027 //* Returns 1 if two keys are equal, 0 otherwise.
00028 //
00029 typedef int ( *ht_keyeq )( void*, void* );
00030 
00031 //* Converts key to an unsigned integer (not necessarily unique).
00032 //
00033 typedef unsigned int ( *ht_key2hash )( void* );
00034 
00035 //* Creates a hash table of specified size.
00036 //
00037 // @param size Size of hash table for output points
00038 // @param cp Key copy function
00039 // @param eq Key equality check function
00040 // @param hash Hash value calculation function
00041 //
00042 hashtable* ht_create( int size, ht_keycp cp, ht_keyeq eq, ht_key2hash hash );
00043 
00044 //* Create a hash table of specified size and key type.
00045 //
00046 hashtable* ht_create_d1( int size );      // double[1]
00047 hashtable* ht_create_d2( int size );      // double[2]
00048 hashtable* ht_create_str( int size );     // char*
00049 
00050 //* Destroys a hash table.
00051 // (Take care of deallocating data by ht_process() prior to destroying the
00052 // table if necessary.)
00053 //
00054 // @param table Hash table to be destroyed
00055 //
00056 void ht_destroy( hashtable* table );
00057 
00058 //* Inserts a new entry into the hash table.
00059 //
00060 // @param table The hash table
00061 // @param key Ponter to entry's key
00062 // @param data Pointer to associated data
00063 // @return Pointer to the old data associated with the key, NULL if the key
00064 //         wasn't in the table previously
00065 //
00066 void* ht_insert( hashtable* table, void* key, void* data );
00067 
00068 //* Returns a pointer to the data associated with a key.  If the key has
00069 // not been inserted in the table, returns NULL.
00070 //
00071 // @param table The hash table
00072 // @param key The key
00073 // @return The associated data or NULL
00074 //
00075 void* ht_find( hashtable* table, void* key );
00076 
00077 //* Deletes an entry from the table.  Returns a pointer to the data that
00078 // was associated with the key so that the calling code can dispose it
00079 // properly.
00080 //
00081 // @param table The hash table
00082 // @param key The key
00083 // @return The associated data or NULL
00084 //
00085 void* ht_delete( hashtable* table, void* key );
00086 
00087 //* For each entry, calls a specified function with corresponding data as a
00088 // parameter.
00089 //
00090 // @param table The hash table
00091 // @param func The action function
00092 //
00093 void ht_process( hashtable* table, void ( *func )( void* ) );
00094 
00095 #endif                          // _HASH_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines