Annotation of libwww/Library/src/HTHash.html, revision 1.2
1.1 frystyk 1: <HTML>
2: <HEAD>
3: <TITLE>W3C Sample Code Library libwww Hash Table Class</TITLE>
4: </HEAD>
5: <BODY>
6: <H1>
7: Hash Table Class
8: </H1>
9: <P>
10: <STRONG>Written and integrated into libwww by John Punin - thanks!</STRONG>
11: <P>
12: This module is implemented by <A HREF="HTHash.c">HTHash.c</A>, and is a part
13: of the <A HREF="http://www.w3.org/Library/"> W3C Sample Code Library</A>.
14: <P>
15: This HashTable class implements a simple hash table to keep objects associated
16: with key words.
17: <PRE>
18: #ifndef HTHASH_H
19: #define HTHASH_H
20:
21: #include "HTList.h"
22:
23: typedef struct _HTHashtable HTHashtable;
24:
25: struct _HTHashtable {
26: void **table;
27: int count;
28: int size;
29: };
30:
31: typedef struct _keynode keynode;
32:
33: struct _keynode {
34: char *key;
35: void *object;
36: };
37: </PRE>
38: <H2>
39: Creation and Deletion Methods
40: </H2>
41: <P>
42: These methods create and deletes a Hash Table
43: <PRE>
44: extern HTHashtable * HTHashtable_new (int size);
45:
46: extern BOOL HTHashtable_delete (HTHashtable *me);
47: </PRE>
48: <H2>
49: Add an Element to a HashTable
50: </H2>
51: <PRE>
1.2 ! kahan 52: extern BOOL HTHashtable_addObject (HTHashtable *me, const char *key, void *newObject);
! 53: </PRE>
! 54: <H2>
! 55: Remove an Element from a HashTable
! 56: </H2>
! 57: <PRE>
! 58: extern BOOL HTHashtable_removeObject (HTHashtable *me, const char *key);
1.1 frystyk 59: </PRE>
60: <H2>
61: Search for an Element in a Hash Table
62: </H2>
63: <PRE>
64: extern void * HTHashtable_object (HTHashtable * me, const char *key);
65: </PRE>
66: <H2>
67: Size of a Hash Table
68: </H2>
69: <PRE>
70: extern int HTHashtable_count (HTHashtable *me);
71: </PRE>
72: <H2>
1.2 ! kahan 73: Walk all the elements in a Hash Table
! 74: </H2>
! 75: <P>
! 76: Walking the hashtable calls the specified function pointer with each key
! 77: and object that is in the hash table. If the callback function returns 0,
! 78: the walking stops. If it returns a negative number, the current element
! 79: is removed from the hash table. Return a positive number to keep going.
! 80: <P>
! 81: Note that it is legal for the walkFunc to call HTHashtable_removeObject()
! 82: on any element in the current hash table <STRONG>except</STRONG> the current
! 83: one (if you intend to keep going, that is). The only legal way to delete the
! 84: current element while continuing to walk the table is to use the negative
! 85: return value.
! 86: <PRE>
! 87: extern BOOL HTHashtable_walk (HTHashtable *me, int (*walkFunc)(HTHashtable *, char *, void *));
! 88: </PRE>
! 89: <H2>
1.1 frystyk 90: Extract in a dynamic array all keys of the Hash Table
91: </H2>
92: <PRE>
93: extern HTArray * HTHashtable_keys (HTHashtable *me);
94: </PRE>
95: <H2>
96: Print the keys of the Hash Table
97: </H2>
98: <PRE>
99: extern void HTHashtable_print (HTHashtable *me);
100: </PRE>
101: <PRE>
102: #endif
103: </PRE>
104: <P>
105: <HR>
106: <ADDRESS>
1.2 ! kahan 107: @(#) $Id: HTHash.html,v 1.1 1999/04/18 20:20:35 frystyk Exp $
1.1 frystyk 108: </ADDRESS>
109: </BODY></HTML>
Webmaster