FreeWRL/FreeX3D  3.0.0
dict.h
1 /*
2  * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3  * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice including the dates of first publication and
13  * either this permission notice or a reference to
14  * http://oss.sgi.com/projects/FreeB/
15  * shall be included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20  * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  *
25  * Except as contained in this notice, the name of Silicon Graphics, Inc.
26  * shall not be used in advertising or otherwise to promote the sale, use or
27  * other dealings in this Software without prior written authorization from
28  * Silicon Graphics, Inc.
29  */
30 /*
31 ** Author: Eric Veach, July 1994.
32 **
33 */
34 
35 #ifndef __dict_list_h_
36 #define __dict_list_h_
37 
38 /* Use #define's so that another heap implementation can use this one */
39 
40 #define DictKey DictListKey
41 #define Dict DictList
42 #define DictNode DictListNode
43 
44 #define dictNewDict(frame,leq) __gl_dictListNewDict(frame,leq)
45 #define dictDeleteDict(dict) __gl_dictListDeleteDict(dict)
46 
47 #define dictSearch(dict,key) __gl_dictListSearch(dict,key)
48 #define dictInsert(dict,key) __gl_dictListInsert(dict,key)
49 #define dictInsertBefore(dict,node,key) __gl_dictListInsertBefore(dict,node,key)
50 #define dictDelete(dict,node) __gl_dictListDelete(dict,node)
51 
52 #define dictKey(n) __gl_dictListKey(n)
53 #define dictSucc(n) __gl_dictListSucc(n)
54 #define dictPred(n) __gl_dictListPred(n)
55 #define dictMin(d) __gl_dictListMin(d)
56 #define dictMax(d) __gl_dictListMax(d)
57 
58 
59 
60 typedef void *DictKey;
61 typedef struct Dict Dict;
62 typedef struct DictNode DictNode;
63 
64 Dict *dictNewDict(
65  void *frame,
66  int (*leq)(void *frame, DictKey key1, DictKey key2) );
67 
68 void dictDeleteDict( Dict *dict );
69 
70 /* Search returns the node with the smallest key greater than or equal
71  * to the given key. If there is no such key, returns a node whose
72  * key is NULL. Similarly, Succ(Max(d)) has a NULL key, etc.
73  */
74 DictNode *dictSearch( Dict *dict, DictKey key );
75 DictNode *dictInsertBefore( Dict *dict, DictNode *node, DictKey key );
76 void dictDelete( Dict *dict, DictNode *node );
77 
78 #define __gl_dictListKey(n) ((n)->key)
79 #define __gl_dictListSucc(n) ((n)->next)
80 #define __gl_dictListPred(n) ((n)->prev)
81 #define __gl_dictListMin(d) ((d)->head.next)
82 #define __gl_dictListMax(d) ((d)->head.prev)
83 #define __gl_dictListInsert(d,k) (dictInsertBefore((d),&(d)->head,(k)))
84 
85 
86 /*** Private data structures ***/
87 
88 struct DictNode {
89  DictKey key;
90  DictNode *next;
91  DictNode *prev;
92 };
93 
94 struct Dict {
95  DictNode head;
96  void *frame;
97  int (*leq)(void *frame, DictKey key1, DictKey key2);
98 };
99 
100 #endif
Definition: dict-list.h:94
Definition: Viewer.h:174