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.

129 lines
2.3 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. fixtable.h
  5. Abstract:
  6. Include file for fixed size table that always allows insertion - oldest
  7. element is replaced when table is full
  8. Author:
  9. Rob Leitman (robleit) 10-Jul-2001
  10. Revision History:
  11. --*/
  12. #ifndef _FIXTABLE_H_
  13. #define _FIXTABLE_H_
  14. #define FIXED_SIZE_TABLE_SIZE 256
  15. typedef struct
  16. {
  17. WCHAR *wszName;
  18. BOOL fMachineAccount;
  19. } FixedSizeTableNode;
  20. typedef struct
  21. {
  22. FixedSizeTableNode *m_array[FIXED_SIZE_TABLE_SIZE];
  23. int m_tail;
  24. } FixedSizeTable;
  25. typedef int (*PFNFixedSizeTableCompare)(FixedSizeTableNode *pNode1,FixedSizeTableNode *pNode2);
  26. ////////////////////////////////////////////////////////////
  27. //
  28. // FixedSizeTable Methods
  29. //
  30. void FixedSizeTableInit(FixedSizeTable *pFst)
  31. /*++
  32. Routine Description:
  33. Initializer
  34. Arguments:
  35. Return Value:
  36. NA
  37. --*/
  38. {
  39. //
  40. // Initialize the table indices.
  41. //
  42. pFst->m_tail = 0;
  43. memset(pFst,0,FIXED_SIZE_TABLE_SIZE*sizeof(FixedSizeTableNode *));
  44. }
  45. BOOL FixedSizeTableInsert(FixedSizeTable *pFst, FixedSizeTableNode *pNode)
  46. /*++
  47. Routine Description:
  48. Add an element to the table.
  49. Arguments:
  50. pNode - Data to be added to the queue.
  51. Return Value:
  52. TRUE if the new element could be successfully queued. FALSE,
  53. otherwise.
  54. --*/
  55. {
  56. if (NULL != pFst->m_array[pFst->m_tail])
  57. {
  58. LocalFree(pFst->m_array[pFst->m_tail]->wszName);
  59. LocalFree(pFst->m_array[pFst->m_tail]);
  60. }
  61. pFst->m_array[pFst->m_tail] = pNode;
  62. pFst->m_tail = (pFst->m_tail + 1) % FIXED_SIZE_TABLE_SIZE;
  63. return TRUE;
  64. }
  65. FixedSizeTableNode *FixedSizeTableSearch(FixedSizeTable *pFst, FixedSizeTableNode *pNode, PFNFixedSizeTableCompare pfn)
  66. /*++
  67. Routine Description:
  68. Search for an element in the table.
  69. Arguments:
  70. pNode - Data to be added to the queue.
  71. pfn - Function to compare two node pointers
  72. Return Value:
  73. pNode if found. NULL otherwise.
  74. --*/
  75. {
  76. int n;
  77. for (n = 0; NULL != pFst->m_array[n] && n < FIXED_SIZE_TABLE_SIZE; n++)
  78. {
  79. if (0 == pfn(pNode, pFst->m_array[n]))
  80. return pFst->m_array[n];
  81. }
  82. return NULL;
  83. }
  84. #endif // _FIXTABLE_H_