Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.1 KiB

  1. /*
  2. ** Copyright 1994, Silicon Graphics, Inc.
  3. ** All Rights Reserved.
  4. **
  5. ** This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6. ** the contents of this file may not be disclosed to third parties, copied or
  7. ** duplicated in any form, in whole or in part, without the prior written
  8. ** permission of Silicon Graphics, Inc.
  9. **
  10. ** RESTRICTED RIGHTS LEGEND:
  11. ** Use, duplication or disclosure by the Government is subject to restrictions
  12. ** as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13. ** and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14. ** successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15. ** rights reserved under the Copyright Laws of the United States.
  16. **
  17. ** Author: Eric Veach, July 1994.
  18. */
  19. #include <stddef.h>
  20. #ifdef NT
  21. #include "dict-lis.h"
  22. #else
  23. #include "dict-list.h"
  24. #endif
  25. #include "memalloc.h"
  26. Dict *dictNewDict( void *frame,
  27. int (*leq)(void *frame, DictKey key1, DictKey key2) )
  28. {
  29. Dict *dict = (Dict *) memAlloc( sizeof( Dict ));
  30. DictNode *head = &dict->head;
  31. head->key = NULL;
  32. head->next = head;
  33. head->prev = head;
  34. dict->frame = frame;
  35. dict->leq = leq;
  36. return dict;
  37. }
  38. void dictDeleteDict( Dict *dict )
  39. {
  40. DictNode *node;
  41. for( node = dict->head.next; node != &dict->head; node = node->next ) {
  42. memFree( node );
  43. }
  44. memFree( dict );
  45. }
  46. DictNode *dictInsertBefore( Dict *dict, DictNode *node, DictKey key )
  47. {
  48. DictNode *newNode;
  49. do {
  50. node = node->prev;
  51. } while( node->key != NULL && ! (*dict->leq)(dict->frame, node->key, key));
  52. newNode = (DictNode *) memAlloc( sizeof( DictNode ));
  53. newNode->key = key;
  54. newNode->next = node->next;
  55. node->next->prev = newNode;
  56. newNode->prev = node;
  57. node->next = newNode;
  58. return newNode;
  59. }
  60. void dictDelete( Dict *dict, DictNode *node ) /*ARGSUSED*/
  61. {
  62. node->next->prev = node->prev;
  63. node->prev->next = node->next;
  64. memFree( node );
  65. }
  66. DictNode *dictSearch( Dict *dict, DictKey key )
  67. {
  68. DictNode *node = &dict->head;
  69. do {
  70. node = node->next;
  71. } while( node->key != NULL && ! (*dict->leq)(dict->frame, key, node->key));
  72. return node;
  73. }