1 /* This file is part of the Project Athena Zephyr Notification System.
2 * It is one of the source files comprising zwgc, the Zephyr WindowGram
5 * Created by: Marc Horowitz <marc@athena.mit.edu>
9 * Copyright (c) 1989 by the Massachusetts Institute of Technology.
10 * For copying and distribution information, see the file
14 #ifndef TYPE_T_dictionary_TYPE
15 #define TYPE_T_dictionary_TYPE
17 typedef struct _TYPE_T_dictionary_binding {
18 struct _TYPE_T_dictionary_binding *next; /* PRIVATE */
19 char *key; /* READ-ONLY */
21 } TYPE_T_dictionary_binding;
23 typedef struct _TYPE_T_dictionary { /* PRIVATE */
25 TYPE_T_dictionary_binding **slots;
29 * TYPE_T_dictionary TYPE_T_dictionary_Create(int size):
31 * Effects: Returns a new empty dictionary containing no bindings.
32 * The returned dictionary must be destroyed using
33 * TYPE_T_dictionary_Destroy. Size is a time vs space
34 * parameter. For this implementation, space used is
35 * proportional to size and time used is proportional
36 * to number of bindings divided by size. It is preferable
37 * that size is a prime number.
40 extern TYPE_T_dictionary TYPE_T_dictionary_Create(int);
43 * void TYPE_T_dictionary_Destroy(TYPE_T_dictionary d):
44 * Requires: d is a non-destroyed TYPE_T_dictionary
46 * Effects: Destroys dictionary d freeing up the space it consumes.
47 * Dictionary d should never be referenced again. Note that
48 * free is NOT called on the values of the bindings. If
49 * this is needed, the client must do this first using
50 * TYPE_T_dictionary_Enumerate.
53 extern void TYPE_T_dictionary_Destroy(TYPE_T_dictionary);
56 * void TYPE_T_dictionary_Enumerate(TYPE_T_dictionary d;
57 * void (*proc)(TYPE_T_dictionary_binding *b)):
58 * Requires: proc is a void procedure taking 1 argument, a
59 * TYPE_T_dictionary_binding pointer, which does not
60 * make any calls using dictionary d.
61 * Effects: Calls proc once with each binding in dictionary d.
62 * Order of bindings passed is undefined. Note that
63 * only the value field of the binding should be considered
67 extern void TYPE_T_dictionary_Enumerate(TYPE_T_dictionary, void (*)(TYPE_T_dictionary_binding *));
70 * TYPE_T_dictionary_binding *TYPE_T_dictionary_Lookup(TYPE_T_dictionary d,
72 * Effects: If key is not bound in d, returns 0. Othersize,
73 * returns a pointer to the binding that binds key.
74 * Note the access restrictions on bindings...
77 extern TYPE_T_dictionary_binding *TYPE_T_dictionary_Lookup(TYPE_T_dictionary,
81 * TYPE_T_dictionary_binding *TYPE_T_dictionary_Define(TYPE_T_dictionary d,
83 * int *already_existed):
85 * Effects: If key is bound in d, returns a pointer to the binding
86 * that binds key. Otherwise, adds a binding of key to
87 * d and returns its address. If already_existed is non-zero
88 * then *already_existed is set to 0 if key was not
89 * previously bound in d and 1 otherwise.
90 * Note the access restrictions on bindings... Note also
91 * that the value that key is bounded to if a binding is
92 * created is undefined. The caller should set the value
96 extern TYPE_T_dictionary_binding *TYPE_T_dictionary_Define(TYPE_T_dictionary,
100 * void TYPE_T_dictionary_Delete(TYPE_T_dictionary d,
101 * TYPE_T_dictionary_binding *b):
102 * Requires: *b is a binding in d.
104 * Effects: Removes the binding *b from d. Note that if
105 * b->value needs to be freed, it should be freed
106 * before making this call.
109 extern void TYPE_T_dictionary_Delete(TYPE_T_dictionary,
110 TYPE_T_dictionary_binding *);