dict.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #ifndef __dict_list_h_
  35. #define __dict_list_h_
  36. /* Use #define's so that another heap implementation can use this one */
  37. #define DictKey DictListKey
  38. #define Dict DictList
  39. #define DictNode DictListNode
  40. #define dictNewDict(frame,leq) __gl_dictListNewDict(frame,leq)
  41. #define dictDeleteDict(dict) __gl_dictListDeleteDict(dict)
  42. #define dictSearch(dict,key) __gl_dictListSearch(dict,key)
  43. #define dictInsert(dict,key) __gl_dictListInsert(dict,key)
  44. #define dictInsertBefore(dict,node,key) __gl_dictListInsertBefore(dict,node,key)
  45. #define dictDelete(dict,node) __gl_dictListDelete(dict,node)
  46. #define dictKey(n) __gl_dictListKey(n)
  47. #define dictSucc(n) __gl_dictListSucc(n)
  48. #define dictPred(n) __gl_dictListPred(n)
  49. #define dictMin(d) __gl_dictListMin(d)
  50. #define dictMax(d) __gl_dictListMax(d)
  51. typedef void *DictKey;
  52. typedef struct Dict Dict;
  53. typedef struct DictNode DictNode;
  54. Dict *dictNewDict(
  55. void *frame,
  56. int (*leq)(void *frame, DictKey key1, DictKey key2) );
  57. void dictDeleteDict( Dict *dict );
  58. /* Search returns the node with the smallest key greater than or equal
  59. * to the given key. If there is no such key, returns a node whose
  60. * key is NULL. Similarly, Succ(Max(d)) has a NULL key, etc.
  61. */
  62. DictNode *dictSearch( Dict *dict, DictKey key );
  63. DictNode *dictInsertBefore( Dict *dict, DictNode *node, DictKey key );
  64. void dictDelete( Dict *dict, DictNode *node );
  65. #define __gl_dictListKey(n) ((n)->key)
  66. #define __gl_dictListSucc(n) ((n)->next)
  67. #define __gl_dictListPred(n) ((n)->prev)
  68. #define __gl_dictListMin(d) ((d)->head.next)
  69. #define __gl_dictListMax(d) ((d)->head.prev)
  70. #define __gl_dictListInsert(d,k) (dictInsertBefore((d),&(d)->head,(k)))
  71. /*** Private data structures ***/
  72. struct DictNode {
  73. DictKey key;
  74. DictNode *next;
  75. DictNode *prev;
  76. };
  77. struct Dict {
  78. DictNode head;
  79. void *frame;
  80. int (*leq)(void *frame, DictKey key1, DictKey key2);
  81. };
  82. #endif