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
3.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1992.
  5. //
  6. // File: WIDARR.CXX
  7. //
  8. // Contents: Work ID array
  9. //
  10. // Classes: CWidArray
  11. //
  12. // History: 28-Oct-91 BartoszM Created
  13. //
  14. //----------------------------------------------------------------------------
  15. #include <pch.cxx>
  16. #pragma hdrstop
  17. #include <doclist.hxx>
  18. #include "widarr.hxx"
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Member: CWidArray::CWidArray, public
  22. //
  23. // Synopsis: Allocates empty array of cnt elements
  24. //
  25. // Arguments: [cnt] -- size of array
  26. //
  27. // History: 20-Oct-91 BartoszM Created.
  28. //
  29. //----------------------------------------------------------------------------
  30. CWidArray::CWidArray ( unsigned cnt )
  31. : _count(cnt)
  32. {
  33. _table = new WORKID[_count];
  34. }
  35. //+---------------------------------------------------------------------------
  36. //
  37. // Member: CWidArray::CWidArray, public
  38. //
  39. // Synopsis: Copies these wids from DocList that correspond
  40. // to pidAll and whose status is SUCCESS or PENDING
  41. // and sorts them
  42. //
  43. // Arguments: [DocList] -- list of documents
  44. //
  45. // History: 20-Oct-91 BartoszM Created.
  46. //
  47. // Notes: Elements are sorted for the binary search to work
  48. //
  49. //----------------------------------------------------------------------------
  50. CWidArray::CWidArray ( CDocList& DocList )
  51. : _table (0), _count(0)
  52. {
  53. unsigned max = DocList.Count();
  54. for ( unsigned i = 0; i < max; i++ )
  55. {
  56. STATUS status = DocList.Status(i);
  57. if ( status == SUCCESS || status == PENDING )
  58. _count++;
  59. }
  60. // create a table of wid's
  61. unsigned j = 0;
  62. if ( _count > 0 )
  63. {
  64. _table = new WORKID [ _count ];
  65. for ( i = 0; i < max; i++ )
  66. {
  67. STATUS status = DocList.Status(i);
  68. if ( status == SUCCESS || status == PENDING )
  69. _table[j++] = DocList.Wid(i);
  70. }
  71. }
  72. #if CIDBG==1
  73. // check to make sure it's sorted.
  74. if ( _count > 0 )
  75. for ( i = 0; i < _count - 1; i++ )
  76. {
  77. ciAssert( _table[i+1]==widInvalid || _table[i] < _table[i+1] );
  78. }
  79. #endif // CIDBG
  80. }
  81. //+---------------------------------------------------------------------------
  82. //
  83. // Member: CWidArray::Find, public
  84. //
  85. // Synopsis: Finds given work id
  86. //
  87. // Arguments: [wid] -- work id to search for
  88. //
  89. // History: 20-Oct-91 BartoszM Created.
  90. //
  91. // Notes: Uses binary search
  92. //
  93. //----------------------------------------------------------------------------
  94. BOOL CWidArray::Find ( WORKID wid ) const
  95. {
  96. int low = 0;
  97. int high = _count-1;
  98. while ( high >= low )
  99. {
  100. int mid = (low + high)/2;
  101. WORKID widMid = _table[mid];
  102. if ( widMid == wid )
  103. return TRUE;
  104. else if ( wid < widMid )
  105. high = mid-1;
  106. else // wid > widMid
  107. low = mid+1;
  108. }
  109. return FALSE;
  110. }