|
|
00001 #include "new_string.h" 00002 #ifndef string_dictionary_TYPE 00003 #define string_dictionary_TYPE 00004 00005 /* 00006 * Copyright (c) 1989 by the Massachusetts Institute of Technology. 00007 * For copying and distribution information, see the file 00008 * "mit-copyright.h". 00009 * 00010 * Modified for jwgc by Daniel Henninger. 00011 */ 00012 00013 #include "mit-copyright.h" 00014 00015 typedef struct _string_dictionary_binding { 00016 struct _string_dictionary_binding *next; /* PRIVATE */ 00017 char *key; /* READ-ONLY */ 00018 string value; 00019 } string_dictionary_binding; 00020 00021 typedef struct _string_dictionary { /* PRIVATE */ 00022 int size; 00023 string_dictionary_binding **slots; 00024 } *string_dictionary; 00025 00026 /* 00027 * string_dictionary string_dictionary_Create(int size): 00028 * Requires: size > 0 00029 * Effects: Returns a new empty dictionary containing no bindings. 00030 * The returned dictionary must be destroyed using 00031 * string_dictionary_Destroy. Size is a time vs space 00032 * parameter. For this implementation, space used is 00033 * proportional to size and time used is proportional 00034 * to number of bindings divided by size. It is preferable 00035 * that size is a prime number. 00036 */ 00037 00038 extern string_dictionary string_dictionary_Create(/* int size */); 00039 00040 /* 00041 * void string_dictionary_Destroy(string_dictionary d): 00042 * Requires: d is a non-destroyed string_dictionary 00043 * Modifies: d 00044 * Effects: Destroys dictionary d freeing up the space it consumes. 00045 * Dictionary d should never be referenced again. Note that 00046 * free is NOT called on the values of the bindings. If 00047 * this is needed, the client must do this first using 00048 * string_dictionary_Enumerate. 00049 */ 00050 00051 extern void string_dictionary_Destroy(/* string_dictionary d */); 00052 00053 /* 00054 * void string_dictionary_Enumerate(string_dictionary d; void (*proc)()): 00055 * Requires: proc is a void procedure taking 1 argument, a 00056 * string_dictionary_binding pointer, which does not 00057 * make any calls using dictionary d. 00058 * Effects: Calls proc once with each binding in dictionary d. 00059 * Order of bindings passed is undefined. Note that 00060 * only the value field of the binding should be considered 00061 * writable by proc. 00062 */ 00063 00064 extern void string_dictionary_Enumerate(/* string_dictionary d, 00065 void (*proc)() */); 00066 00067 /* 00068 * string_dictionary_binding *string_dictionary_Lookup(string_dictionary d, 00069 * char *key): 00070 * Effects: If key is not bound in d, returns 0. Othersize, 00071 * returns a pointer to the binding that binds key. 00072 * Note the access restrictions on bindings... 00073 */ 00074 00075 extern string_dictionary_binding *string_dictionary_Lookup(/* d, key */); 00076 00077 /* 00078 * string_dictionary_binding *string_dictionary_Define(string_dictionary d, 00079 * char *key, 00080 * int *already_existed): 00081 * Modifies: d 00082 * Effects: If key is bound in d, returns a pointer to the binding 00083 * that binds key. Otherwise, adds a binding of key to 00084 * d and returns its address. If already_existed is non-zero 00085 * then *already_existed is set to 0 if key was not 00086 * previously bound in d and 1 otherwise. 00087 * Note the access restrictions on bindings... Note also 00088 * that the value that key is bounded to if a binding is 00089 * created is undefined. The caller should set the value 00090 * in this case. 00091 */ 00092 00093 extern string_dictionary_binding *string_dictionary_Define(); 00094 00095 /* 00096 * void string_dictionary_Delete(string_dictionary d, 00097 * string_dictionary_binding *b): 00098 * Requires: *b is a binding in d. 00099 * Modifies: d 00100 * Effects: Removes the binding *b from d. Note that if 00101 * b->value needs to be freed, it should be freed 00102 * before making this call. 00103 */ 00104 00105 extern void string_dictionary_Delete(); 00106 00107 #endif
Last updated at Tue Dec 18 21:07:42 PST 2007. | This site and project hosted by... |