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 typedef void *DictKey; 59 typedef struct Dict Dict; 60 typedef struct DictNode DictNode; 61 62 Dict* dictNewDict(void *frame, 63 int (*leq)(void *frame, DictKey key1, DictKey key2)); 64 void dictDeleteDict(Dict *dict); 65 66 /* Search returns the node with the smallest key greater than or equal 67 * to the given key. If there is no such key, returns a node whose 68 * key is NULL. Similarly, Succ(Max(d)) has a NULL key, etc. 69 */ 70 DictNode* dictSearch(Dict* dict, DictKey key); 71 DictNode* dictInsertBefore(Dict* dict, DictNode* node, DictKey key); 72 void dictDelete(Dict* dict, DictNode* node); 73 74 #define __gl_dictListKey(n) ((n)->key) 75 #define __gl_dictListSucc(n) ((n)->next) 76 #define __gl_dictListPred(n) ((n)->prev) 77 #define __gl_dictListMin(d) ((d)->head.next) 78 #define __gl_dictListMax(d) ((d)->head.prev) 79 #define __gl_dictListInsert(d,k) (dictInsertBefore((d),&(d)->head,(k))) 80 81 /*** Private data structures ***/ 82 83 struct DictNode 84 { 85 DictKey key; 86 DictNode* next; 87 DictNode* prev; 88 }; 89 90 struct Dict 91 { 92 DictNode head; 93 void* frame; 94 int (*leq)(void *frame, DictKey key1, DictKey key2); 95 }; 96 97 #endif /* __dict_list_h_ */ 98