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.

89 lines
2.6 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. //
  4. // File: qwiklist.h
  5. //
  6. // Description: Provides a quick paged/growable list implementation.
  7. //
  8. // Author: Mike Swafford (MikeSwa)
  9. //
  10. // History:
  11. // 6/15/98 - MikeSwa Created
  12. // 9/9/98 - MikeSwa Modified to include functionality to delete entries
  13. //
  14. // Copyright (C) 1998 Microsoft Corporation
  15. //
  16. //-----------------------------------------------------------------------------
  17. #ifndef __QWIKLIST_H__
  18. #define __QWIKLIST_H__
  19. #include <aqincs.h>
  20. #include <listmacr.h>
  21. #define QUICK_LIST_SIG 'tsLQ'
  22. #define QUICK_LIST_SIG_DELETE 'slQ!'
  23. const DWORD QUICK_LIST_PAGE_SIZE = 16; //must be a power of 2
  24. //Mask used to quickly determine if a given index is on the current page
  25. const DWORD QUICK_LIST_INDEX_MASK = ~(QUICK_LIST_PAGE_SIZE-1);
  26. //When m_cItems is set to this value... we know this is not the head page.
  27. const DWORD QUICK_LIST_LEAF_PAGE = 0xFFFF7EAF;
  28. class CQuickList
  29. {
  30. protected:
  31. DWORD m_dwSignature;
  32. DWORD m_dwCurrentIndexStart;
  33. LIST_ENTRY m_liListPages;
  34. DWORD m_cItems;
  35. PVOID m_rgpvData[QUICK_LIST_PAGE_SIZE];
  36. inline BOOL fIsIndexOnThisPage(DWORD dwIndex);
  37. public:
  38. static CPool s_QuickListPool;
  39. void *operator new(size_t size);
  40. void operator delete(void *p, size_t size);
  41. CQuickList(); //initialize entry as head
  42. CQuickList(CQuickList *pqlstHead); //initialize as new page in list
  43. ~CQuickList();
  44. DWORD dwGetCount() {return m_cItems;};
  45. PVOID pvGetItem(IN DWORD dwIndex, IN OUT PVOID *ppvContext);
  46. PVOID pvDeleteItem(IN DWORD dwIndex, IN OUT PVOID *ppvContext);
  47. HRESULT HrAppendItem(IN PVOID pvData, OUT DWORD *pdwIndex);
  48. HRESULT Clone (CQuickList **ppqlClone);
  49. };
  50. //---[ CQuickList::fIsIndexOnThisPage ]----------------------------------------
  51. //
  52. //
  53. // Description:
  54. // Returns TRUE is the given index is on this page
  55. // Parameters:
  56. // dwIndex - Index to check for
  57. // Returns:
  58. // TRUE if index is on this page... FALSE otherwise
  59. // History:
  60. // 6/15/98 - MikeSwa Created
  61. //
  62. //-----------------------------------------------------------------------------
  63. BOOL CQuickList::fIsIndexOnThisPage(DWORD dwIndex)
  64. {
  65. return ((dwIndex & QUICK_LIST_INDEX_MASK) == m_dwCurrentIndexStart);
  66. }
  67. inline void *CQuickList::operator new(size_t size)
  68. {
  69. return s_QuickListPool.Alloc();
  70. }
  71. inline void CQuickList::operator delete(void *p, size_t size)
  72. {
  73. s_QuickListPool.Free(p);
  74. }
  75. #endif //__QWIKLIST_H__