Update `seq-let' documentation
[emacs.git] / oldXMenu / XLookAssoc.c
blobfad960d7a4c934144648a923aac6bfc89a3fee41
1 /* Copyright Massachusetts Institute of Technology 1985 */
3 #include "copyright.h"
5 #include <config.h>
6 #include <X11/Xlib.h>
7 #include <X11/Xresource.h>
8 #include "X10.h"
10 #ifndef NULL
11 #define NULL 0
12 #endif
15 * XLookUpAssoc - Retrieve the data stored in an XAssocTable by its XId.
16 * If an appropriately matching XId can be found in the table the routine will
17 * return apointer to the data associated with it. If the XId can not be found
18 * in the table the routine will return a NULL pointer. All XId's are relative
19 * to the currently active Display.
21 caddr_t XLookUpAssoc(Display *dpy,
22 XAssocTable *table, /* XAssocTable to search in. */
23 XID x_id) /* XId to search for. */
25 int hash;
26 register XAssoc *bucket;
27 register XAssoc *Entry;
29 /* Hash the XId to get the bucket number. */
30 hash = x_id & (table->size - 1);
31 /* Look up the bucket to get the entries in that bucket. */
32 bucket = &table->buckets[hash];
33 /* Get the first entry in the bucket. */
34 Entry = bucket->next;
36 /* Scan through the entries in the bucket for the right XId. */
37 for (; Entry != bucket; Entry = Entry->next) {
38 if (Entry->x_id == x_id) {
39 /* We have the right XId. */
40 if (Entry->display == dpy) {
41 /* We have the right display. */
42 /* We have the right entry! */
43 return(Entry->data);
45 /* Oops, identical XId's on different displays! */
46 continue;
48 if (Entry->x_id > x_id) {
49 /* We have gone past where it should be. */
50 /* It is apparently not in the table. */
51 return(NULL);
54 /* It is apparently not in the table. */
55 return(NULL);