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.

123 lines
3.1 KiB

  1. /*****************************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1987-1999 **/
  4. /*****************************************************************************/
  5. /*****************************************************************************
  6. File : idict.hxx
  7. Title : index based dictionary simulation
  8. History :
  9. 04-Aug-1991 VibhasC Created
  10. *****************************************************************************/
  11. #ifndef __IDICT_HXX__
  12. #define __IDICT_HXX__
  13. #include "common.hxx"
  14. #if 0
  15. Notes
  16. -----
  17. This implementation is a glorified implementation of an array, which is
  18. a data structure which returns an element upon presentation of an index. Thus,
  19. for this data structure, we assume that the index is the key. The difference
  20. is that this array is dynamically sized. It starts out with a fixed size, and
  21. when more and more additions are made, a new array is allocated with a larger
  22. size and the old one is copied. A different implementation could be that we
  23. allocate fixed size blocks and add more such blocks as needed, linking the
  24. blocks together, in order to save the copying. A roughly similar implementation
  25. is the buffermanager class, but it does not have a method for returning a
  26. pointer, given an index. When that is implemented this one will go away and
  27. be replaced by the buffermanager.
  28. Keep in mind:
  29. -------------
  30. . The block size is in increments of IDICT_INCREMENT. This is tunable.
  31. . Caveat :
  32. This implementation is to be used when you dont intend to delete elements
  33. out of the array. MIDL stores the key value in its data structures, so
  34. once entered in the array, the array CANNOT change.
  35. #endif // 0
  36. #define IDICT_INCREMENT (512)
  37. typedef int IDICTKEY;
  38. typedef void * IDICTELEMENT;
  39. class IDICT
  40. {
  41. private:
  42. short CurrentSize;
  43. short iNextIndex;
  44. short IDictIncrement;
  45. IDICTELEMENT (*pArray);
  46. IDICTELEMENT * GetArray()
  47. {
  48. return pArray;
  49. };
  50. void SetArray( IDICTELEMENT *p )
  51. {
  52. pArray = p;
  53. };
  54. void ExpandArray();
  55. IDICTKEY SetNewElement( IDICTELEMENT );
  56. public:
  57. IDICT( short, short );
  58. ~IDICT()
  59. {
  60. delete pArray;
  61. };
  62. IDICTELEMENT GetElement( IDICTKEY Key );
  63. IDICTKEY AddElement( IDICTELEMENT );
  64. void SetElement( IDICTKEY, IDICTELEMENT );
  65. short GetCurrentSize()
  66. {
  67. return CurrentSize;
  68. }
  69. short GetNumberOfElements()
  70. {
  71. return iNextIndex;
  72. }
  73. BOOL IsElementPresent( IDICTELEMENT );
  74. };
  75. typedef IDICT * PIDICT;
  76. class ISTACK
  77. {
  78. private:
  79. short MaxElements;
  80. short CurrentElement;
  81. IDICTELEMENT (*pStack);
  82. void InitNew( short MaxDepth );
  83. public:
  84. ISTACK( short MaxDepth );
  85. IDICTELEMENT Push( IDICTELEMENT Elem );
  86. IDICTELEMENT Pop();
  87. IDICTELEMENT GetTop()
  88. {
  89. if( CurrentElement >= 1 )
  90. return pStack[ CurrentElement - 1 ];
  91. else
  92. return (IDICTELEMENT) 0;
  93. }
  94. IDICTELEMENT GetBottom()
  95. {
  96. return (IDICTELEMENT) pStack[ 0 ];
  97. }
  98. };
  99. #endif // __IDICT_HXX__