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.

114 lines
3.4 KiB

  1. /******************************Module*Header**********************************\
  2. *
  3. * *******************
  4. * * D3D SAMPLE CODE *
  5. * *******************
  6. *
  7. * Module Name: d3dstrct.h
  8. *
  9. * Content: Internal D3D structure management headers and macros
  10. *
  11. * Copyright (c) 1994-1999 3Dlabs Inc. Ltd. All rights reserved.
  12. * Copyright (c) 1995-2003 Microsoft Corporation. All rights reserved.
  13. \*****************************************************************************/
  14. #ifndef __D3DSTRCT_H
  15. #define __D3DSTRCT_H
  16. //-----------------------------------------------------------------------------
  17. //
  18. // Array functions and structures
  19. //
  20. //-----------------------------------------------------------------------------
  21. typedef void (*PA_DestroyCB)(struct tagPointerArray* pTable,
  22. void* pData,
  23. void* pExtra);
  24. typedef struct tagPointerArray
  25. {
  26. ULONG_PTR* pPointers;
  27. DWORD dwNumPointers;
  28. PA_DestroyCB pfnDestroyCallback;
  29. } PointerArray;
  30. PointerArray* PA_CreateArray();
  31. BOOL PA_DestroyArray(PointerArray* pArray, VOID* pExtra);
  32. void* PA_GetEntry(PointerArray* pArray, DWORD dwNum);
  33. BOOL PA_SetEntry(PointerArray* pArray, DWORD dwNum, void* pData);
  34. void PA_SetDataDestroyCallback(PointerArray* pArray,
  35. PA_DestroyCB DestroyCallback);
  36. //-----------------------------------------------------------------------------
  37. //
  38. // Hashing functions and structures
  39. //
  40. //-----------------------------------------------------------------------------
  41. #define HASH_SIZE 4096 // this many entries in the hash table
  42. #define HT_HASH_OF(i) ((i) & 0xFFF)
  43. typedef struct tagHashSlot
  44. {
  45. void* pData;
  46. ULONG_PTR dwHandle;
  47. struct tagHashSlot* pNext;
  48. struct tagHashSlot* pPrev;
  49. } HashSlot;
  50. typedef void (*DataDestroyCB)(struct tagHashTable* pTable,
  51. void* pData,
  52. void*pExtra);
  53. typedef struct tagHashTable
  54. {
  55. HashSlot* Slots[HASH_SIZE];
  56. DataDestroyCB pfnDestroyCallback;
  57. } HashTable;
  58. // Helper functions
  59. static __inline HashSlot* HT_GetSlotFromHandle(HashTable* pTable,
  60. ULONG_PTR dwHandle)
  61. {
  62. HashSlot* pBase = NULL;
  63. ASSERTDD(pTable != NULL,"ERROR: HashTable passed in is not valid!");
  64. pBase = pTable->Slots[HT_HASH_OF(dwHandle)];
  65. while (pBase != NULL)
  66. {
  67. if (pBase->dwHandle == dwHandle)
  68. return pBase;
  69. pBase = pBase->pNext;
  70. }
  71. return NULL;
  72. } // HT_GetSlotFromHandle
  73. static __inline void* HT_GetEntry(HashTable* pTable, ULONG_PTR dwHandle)
  74. {
  75. HashSlot* pEntry = HT_GetSlotFromHandle(pTable, dwHandle);
  76. if (pEntry)
  77. {
  78. return pEntry->pData;
  79. }
  80. return NULL;
  81. } /// HT_GetEntry
  82. // Public interfaces
  83. HashTable* HT_CreateHashTable();
  84. void HT_ClearEntriesHashTable(HashTable* pHashTable, VOID* pExtra);
  85. void HT_DestroyHashTable(HashTable* pHashTable, VOID* pExtra);
  86. void HT_SetDataDestroyCallback(HashTable* pTable,
  87. DataDestroyCB DestroyCallback);
  88. BOOL HT_SwapEntries(HashTable* pTable, DWORD dwHandle1, DWORD dwHandle2);
  89. BOOL HT_AddEntry(HashTable* pTable, ULONG_PTR dwHandle, void* pData);
  90. BOOL HT_RemoveEntry(HashTable* pTable, ULONG_PTR dwHandle, VOID* pExtra);
  91. #endif // __D3DSTRCT_H