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.

89 lines
2.1 KiB

  1. /*===================================================================
  2. Microsoft Denali
  3. Microsoft Confidential.
  4. Copyright 1996 Microsoft Corporation. All Rights Reserved.
  5. Component: Hash table for Script Manager
  6. File: LinkHash.h
  7. Owner: DGottner
  8. This is the Link list and Hash table for use by any classes which
  9. also need LRU access to items. (This includes cache manager,
  10. script manager, and session deletion code)
  11. ===================================================================*/
  12. #ifndef LINKHASH_H
  13. #define LINKHASH_H
  14. #include "hashing.h"
  15. #include "DblLink.h"
  16. /* C L r u L i n k E l e m
  17. *
  18. * CLruLink is a CLinkElem with extra links to maintain a circular LRU queue
  19. *
  20. * NOTE: Both the CLinkElem list and the CDblLink lists are intrusive.
  21. * therefore, we need to use multiple inheritance to make sure that
  22. * downcasts from CLruLinkElem will work on both CLinkElem pointers
  23. * and CDblLink pointers. See the ARM, p. 221
  24. */
  25. class CLruLinkElem : public CLinkElem, public CDblLink
  26. {
  27. };
  28. /*
  29. * C L i n k H a s h
  30. *
  31. * CLinkHash differs from CHashTable in that it maintains some extra pointers to
  32. * maintain a threaded lru queue.
  33. */
  34. class CLinkHash : public CHashTable
  35. {
  36. public:
  37. CLinkHash(HashFunction = DefaultHash);
  38. CLruLinkElem *AddElem(CLruLinkElem *pElem, BOOL fTestDups = TRUE);
  39. CLruLinkElem *FindElem(const void *pvKey, int cbKeyLen);
  40. CLruLinkElem *DeleteElem(const void *pvKey, int cbKeyLen);
  41. CLruLinkElem *RemoveElem(CLruLinkElem *pElem);
  42. // you CANNOT compare LRU nodes to NULL to know if you are at the end
  43. // of the list! Instead use this member.
  44. //
  45. BOOL FLruElemIsEmpty(CLruLinkElem *pElem)
  46. {
  47. pElem->AssertValid();
  48. return pElem == &m_lruHead;
  49. }
  50. CLruLinkElem *Begin() // return pointer to last referenced item
  51. {
  52. return static_cast<CLruLinkElem *>(m_lruHead.PNext());
  53. }
  54. CLruLinkElem *End() // return pointer to least recently accessed item
  55. {
  56. return static_cast<CLruLinkElem *>(m_lruHead.PPrev());
  57. }
  58. void AssertValid() const;
  59. protected:
  60. CDblLink m_lruHead;
  61. };
  62. #ifndef DBG
  63. inline void CLinkHash::AssertValid() const {}
  64. #endif
  65. #endif // LINKHASH_H