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.

126 lines
2.3 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1990 - 1999
  6. //
  7. // File: sset.cxx
  8. //
  9. //--------------------------------------------------------------------------
  10. /* --------------------------------------------------------------------
  11. File : sset.cxx
  12. Title : Simple set implementation.
  13. Description :
  14. History :
  15. -------------------------------------------------------------------- */
  16. #include <precomp.hxx>
  17. #include <sset.hxx>
  18. #include <memory.h>
  19. SIMPLE_SET::SIMPLE_SET (
  20. )
  21. {
  22. cSetSlots = INITIALSETSLOTS;
  23. iNextItem = 0;
  24. SetSlots = InitialSetSlots;
  25. memset(SetSlots, 0, sizeof(void *) * cSetSlots);
  26. }
  27. SIMPLE_SET::~SIMPLE_SET (
  28. )
  29. {
  30. delete SetSlots;
  31. }
  32. int
  33. SIMPLE_SET::Insert (
  34. void * Item
  35. )
  36. {
  37. int iSetSlots;
  38. void * * NewSetSlots;
  39. for (iSetSlots = 0; iSetSlots < cSetSlots; iSetSlots++)
  40. {
  41. if (SetSlots[iSetSlots] == 0)
  42. {
  43. SetSlots[iSetSlots] = Item;
  44. return(0);
  45. }
  46. }
  47. NewSetSlots = (void * *) new
  48. unsigned char[sizeof(void *) * cSetSlots * 2];
  49. if (NewSetSlots == 0)
  50. return(-1);
  51. memset(NewSetSlots, 0, sizeof(void *) * cSetSlots * 2);
  52. memcpy((void *)NewSetSlots, (void *)SetSlots, sizeof(void *) * cSetSlots);
  53. NewSetSlots[cSetSlots] = Item;
  54. if (SetSlots != InitialSetSlots)
  55. delete SetSlots;
  56. SetSlots = NewSetSlots;
  57. return(0);
  58. }
  59. int
  60. SIMPLE_SET::Delete (
  61. void * Item
  62. )
  63. {
  64. int iSetSlots;
  65. for (iSetSlots = 0; iSetSlots < cSetSlots; iSetSlots++)
  66. {
  67. if (SetSlots[iSetSlots] == Item)
  68. {
  69. SetSlots[iSetSlots] = 0;
  70. return(0);
  71. }
  72. }
  73. return(-1);
  74. }
  75. int
  76. SIMPLE_SET::MemberP (
  77. void * Item
  78. )
  79. {
  80. int iSetSlots;
  81. for (iSetSlots = 0; iSetSlots < cSetSlots; iSetSlots++)
  82. {
  83. if (SetSlots[iSetSlots] == Item)
  84. {
  85. return(1);
  86. }
  87. }
  88. return(0);
  89. }
  90. void *
  91. SIMPLE_SET::Next (
  92. )
  93. {
  94. for ( ; iNextItem < cSetSlots; iNextItem++)
  95. {
  96. if (SetSlots[iNextItem])
  97. {
  98. iNextItem++;
  99. return(SetSlots[iNextItem-1]);
  100. }
  101. }
  102. iNextItem = 0;
  103. return(0);
  104. }