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.

81 lines
2.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: sglookup.hxx
  7. //
  8. // Contents: A class for doing a quick lookup of a segment based on the
  9. // key. It will do a binary search and locate the segment.
  10. // This is useful for doing row insertions into a large table
  11. // when keys are not coming in any specific order.
  12. //
  13. //
  14. // Classes: CSegmentArray
  15. //
  16. // Functions:
  17. //
  18. // History: 10-20-95 srikants Created
  19. //
  20. //----------------------------------------------------------------------------
  21. #pragma once
  22. #include <tableseg.hxx>
  23. class CTableSegList;
  24. class CTableKeyCompare;
  25. class CSegmentArray : public CDynArrayInPlace<CTableSegment *>
  26. {
  27. enum { eMinSegments = 16, eMaxSegments = 1024 };
  28. public:
  29. CSegmentArray();
  30. CTableSegment * LookUp( CTableRowKey & key );
  31. void Append( CTableSegment * pSeg );
  32. void InsertAfter( const CTableSegment * pMarker, CTableSegment * pSeg );
  33. void InsertBefore( const CTableSegment * pMarker, CTableSegment * pSeg );
  34. void Replace( const CTableSegment * pOld, CTableSegment * pNew );
  35. void Replace( const CTableSegment * pSrc, CTableSegList & segList );
  36. void RemoveEntry( const CTableSegment * pSegment );
  37. void SetComparator( CTableKeyCompare * pComparator )
  38. {
  39. Win4Assert( 0 == _pComparator && 0 != pComparator );
  40. _pComparator = pComparator;
  41. }
  42. BOOL IsFound( const CTableSegment * pSeg )
  43. {
  44. return _FindSegment( pSeg ) >= 0;
  45. }
  46. #if CIDBG==1
  47. void TestInSync( CTableSegList & list );
  48. #else
  49. void TestInSync( CTableSegList & list ) {}
  50. #endif // CIDBG
  51. private:
  52. CTableKeyCompare * _pComparator;
  53. int _FindSegment( const CTableSegment * pSeg );
  54. void _MoveEntries( unsigned iStart, unsigned cEntries );
  55. unsigned _iHint; // the last hint used
  56. };