]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/zwgc/dictionary.h
finalize -3
[1ts-debian.git] / zephyr / zwgc / dictionary.h
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
3  * client.
4  *
5  *      Created by:     Marc Horowitz <marc@athena.mit.edu>
6  *
7  *      $Id$
8  *
9  *      Copyright (c) 1989 by the Massachusetts Institute of Technology.
10  *      For copying and distribution information, see the file
11  *      "mit-copyright.h".
12  */
13
14 #ifndef TYPE_T_dictionary_TYPE
15 #define TYPE_T_dictionary_TYPE
16
17 typedef struct _TYPE_T_dictionary_binding {
18     struct _TYPE_T_dictionary_binding *next;       /* PRIVATE */
19     char *key;                                     /* READ-ONLY */
20     TYPE_T value;
21 } TYPE_T_dictionary_binding;
22
23 typedef struct _TYPE_T_dictionary {                /* PRIVATE */
24     int size;
25     TYPE_T_dictionary_binding **slots;
26 } *TYPE_T_dictionary;
27
28 /*
29  *    TYPE_T_dictionary TYPE_T_dictionary_Create(int size):
30  *        Requires: size > 0
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.
38  */
39
40 extern TYPE_T_dictionary TYPE_T_dictionary_Create(/* int size */);
41
42 /*
43  *    void TYPE_T_dictionary_Destroy(TYPE_T_dictionary d):
44  *        Requires: d is a non-destroyed TYPE_T_dictionary
45  *        Modifies: d
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.
51  */
52
53 extern void TYPE_T_dictionary_Destroy(/* TYPE_T_dictionary d */);
54
55 /*
56  *    void TYPE_T_dictionary_Enumerate(TYPE_T_dictionary d; void (*proc)()):
57  *        Requires: proc is a void procedure taking 1 argument, a
58  *                  TYPE_T_dictionary_binding pointer, which does not
59  *                  make any calls using dictionary d.
60  *        Effects: Calls proc once with each binding in dictionary d.
61  *                 Order of bindings passed is undefined.  Note that
62  *                 only the value field of the binding should be considered
63  *                 writable by proc.
64  */
65
66 extern void TYPE_T_dictionary_Enumerate(/* TYPE_T_dictionary d, 
67                                            void (*proc)() */);
68
69 /*
70  *    TYPE_T_dictionary_binding *TYPE_T_dictionary_Lookup(TYPE_T_dictionary d,
71  *                                                        char *key):
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...
75  */
76
77 extern TYPE_T_dictionary_binding *TYPE_T_dictionary_Lookup(/* d, key */);
78
79 /*
80  *    TYPE_T_dictionary_binding *TYPE_T_dictionary_Define(TYPE_T_dictionary d,
81  *                                            char *key,
82  *                                            int *already_existed):
83  *        Modifies: d
84  *        Effects: If key is bound in d, returns a pointer to the binding
85  *                 that binds key.  Otherwise, adds a binding of key to
86  *                 d and returns its address.  If already_existed is non-zero
87  *                 then *already_existed is set to 0 if key was not
88  *                 previously bound in d and 1 otherwise.
89  *                 Note the access restrictions on bindings...  Note also
90  *                 that the value that key is bounded to if a binding is
91  *                 created is undefined.  The caller should set the value
92  *                 in this case.
93  */
94
95 extern TYPE_T_dictionary_binding *TYPE_T_dictionary_Define();
96
97 /*
98  *    void TYPE_T_dictionary_Delete(TYPE_T_dictionary d,
99  *                                  TYPE_T_dictionary_binding *b):
100  *        Requires: *b is a binding in d.
101  *        Modifies: d
102  *        Effects: Removes the binding *b from d.  Note that if 
103  *                 b->value needs to be freed, it should be freed
104  *                 before making this call.
105  */
106
107 extern void TYPE_T_dictionary_Delete();
108
109 #endif