Leaked source code of windows server 2003
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.

83 lines
2.1 KiB

  1. /* (C) 1997-1999 Microsoft Corp.
  2. *
  3. * file : SList.h
  4. * authors : Christos Tsollis, Erik Mavrinac
  5. *
  6. * description: Interface definition to a dynamically-resizing list/queue
  7. * data type. The "key" values in the list are unsigned ints of whatever the
  8. * default word size is, so the elements of the array will be word-aligned.
  9. * These elements can be cast into whatever form is needed. Associated is
  10. * a void * for data asssociated with the "key".
  11. */
  12. #ifndef __SLIST_H
  13. #define __SLIST_H
  14. #define SListDefaultNumEntries 4
  15. /*
  16. * Types
  17. */
  18. typedef struct
  19. {
  20. UINT_PTR Key;
  21. void *Value;
  22. } _SListNode;
  23. typedef struct
  24. {
  25. unsigned NEntries; // current # of entries in the list
  26. unsigned MaxEntries; // max # of entries that the array can hold
  27. unsigned HeadOffset; // Offset of the 1st entry in the circular array
  28. unsigned CurrOffset; // Iterator value
  29. _SListNode *Entries; // Circular array of entries
  30. } _SListHeader;
  31. typedef struct
  32. {
  33. _SListHeader Hdr;
  34. _SListNode InitialList[SListDefaultNumEntries];
  35. } SList, *PSList;
  36. /*
  37. * API prototypes.
  38. */
  39. BOOLEAN SListAppend(PSList, UINT_PTR, void *);
  40. void SListDestroy(PSList);
  41. BOOLEAN SListGetByKey(PSList, UINT_PTR, void **);
  42. void SListInit(PSList, unsigned);
  43. BOOLEAN SListIterate(PSList, UINT_PTR *, void **);
  44. BOOLEAN SListPrepend(PSList, UINT_PTR, void *);
  45. void SListRemove(PSList, UINT_PTR, void **);
  46. void SListRemoveFirst(PSList, UINT_PTR *, void **);
  47. void SListRemoveLast(PSList, UINT_PTR *, void **);
  48. /*
  49. * API functions implemented as macros.
  50. */
  51. // void SListResetIteration(PSList); // Resets iteration counter.
  52. #define SListResetIteration(pSL) (pSL)->Hdr.CurrOffset = 0xFFFFFFFF
  53. // unsigned SListGetEntries(PSList); // Ret. # entries in list.
  54. #define SListGetEntries(pSL) ((pSL)->Hdr.NEntries)
  55. // void SListClear(PSList);
  56. #define SListClear(pSL) { \
  57. (pSL)->Hdr.NEntries = (pSL)->Hdr.HeadOffset = 0; \
  58. (pSL)->Hdr.CurrOffset = 0xFFFFFFFF; \
  59. }
  60. // BOOLEAN SListIsEmpty(PSList);
  61. #define SListIsEmpty(pSL) ((pSL)->Hdr.NEntries == 0)
  62. #endif // !defined(__SLIST_H)