dict.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. ** SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
  3. ** Copyright (C) [dates of first publication] Silicon Graphics, Inc.
  4. ** All Rights Reserved.
  5. **
  6. ** Permission is hereby granted, free of charge, to any person obtaining a copy
  7. ** of this software and associated documentation files (the "Software"), to deal
  8. ** in the Software without restriction, including without limitation the rights
  9. ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  10. ** of the Software, and to permit persons to whom the Software is furnished to do so,
  11. ** subject to the following conditions:
  12. **
  13. ** The above copyright notice including the dates of first publication and either this
  14. ** permission notice or a reference to http://oss.sgi.com/projects/FreeB/ shall be
  15. ** included in all copies or substantial portions of the Software.
  16. **
  17. ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  18. ** INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  19. ** PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL SILICON GRAPHICS, INC.
  20. ** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  21. ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
  22. ** OR OTHER DEALINGS IN THE SOFTWARE.
  23. **
  24. ** Except as contained in this notice, the name of Silicon Graphics, Inc. shall not
  25. ** be used in advertising or otherwise to promote the sale, use or other dealings in
  26. ** this Software without prior written authorization from Silicon Graphics, Inc.
  27. */
  28. /*
  29. ** Author: Eric Veach, July 1994.
  30. */
  31. #ifndef DICT_LIST_H
  32. #define DICT_LIST_H
  33. typedef void *DictKey;
  34. typedef struct Dict Dict;
  35. typedef struct DictNode DictNode;
  36. Dict *dictNewDict( TESSalloc* alloc, void *frame, int (*leq)(void *frame, DictKey key1, DictKey key2) );
  37. void dictDeleteDict( TESSalloc* alloc, Dict *dict );
  38. /* Search returns the node with the smallest key greater than or equal
  39. * to the given key. If there is no such key, returns a node whose
  40. * key is NULL. Similarly, Succ(Max(d)) has a NULL key, etc.
  41. */
  42. DictNode *dictSearch( Dict *dict, DictKey key );
  43. DictNode *dictInsertBefore( Dict *dict, DictNode *node, DictKey key );
  44. void dictDelete( Dict *dict, DictNode *node );
  45. #define dictKey(n) ((n)->key)
  46. #define dictSucc(n) ((n)->next)
  47. #define dictPred(n) ((n)->prev)
  48. #define dictMin(d) ((d)->head.next)
  49. #define dictMax(d) ((d)->head.prev)
  50. #define dictInsert(d,k) (dictInsertBefore((d),&(d)->head,(k)))
  51. /*** Private data structures ***/
  52. struct DictNode {
  53. DictKey key;
  54. DictNode *next;
  55. DictNode *prev;
  56. };
  57. struct Dict {
  58. DictNode head;
  59. void *frame;
  60. struct BucketAlloc *nodePool;
  61. int (*leq)(void *frame, DictKey key1, DictKey key2);
  62. };
  63. #endif