simDictionary.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _SIMDICTIONARY_H_
  23. #define _SIMDICTIONARY_H_
  24. #ifndef _PLATFORM_H_
  25. #include "platform/platform.h"
  26. #endif
  27. #ifndef _STRINGTABLE_H_
  28. #include "core/stringTable.h"
  29. #endif
  30. #ifndef _PLATFORMMUTEX_H_
  31. #include "platform/threads/mutex.h"
  32. #endif
  33. class SimObject;
  34. //----------------------------------------------------------------------------
  35. /// Map of names to SimObjects
  36. ///
  37. /// Provides fast lookup for name->object and
  38. /// for fast removal of an object given object*
  39. class SimNameDictionary
  40. {
  41. enum
  42. {
  43. DefaultTableSize = 29
  44. };
  45. SimObject **hashTable; // hash the pointers of the names...
  46. S32 hashTableSize;
  47. S32 hashEntryCount;
  48. void *mutex;
  49. public:
  50. void insert(SimObject* obj);
  51. void remove(SimObject* obj);
  52. SimObject* find(StringTableEntry name);
  53. SimNameDictionary();
  54. ~SimNameDictionary();
  55. };
  56. class SimManagerNameDictionary
  57. {
  58. enum
  59. {
  60. DefaultTableSize = 29
  61. };
  62. SimObject **hashTable; // hash the pointers of the names...
  63. S32 hashTableSize;
  64. S32 hashEntryCount;
  65. void *mutex;
  66. public:
  67. void insert(SimObject* obj);
  68. void remove(SimObject* obj);
  69. SimObject* find(StringTableEntry name);
  70. SimManagerNameDictionary();
  71. ~SimManagerNameDictionary();
  72. };
  73. //----------------------------------------------------------------------------
  74. /// Map of ID's to SimObjects.
  75. ///
  76. /// Provides fast lookup for ID->object and
  77. /// for fast removal of an object given object*
  78. class SimIdDictionary
  79. {
  80. enum
  81. {
  82. DefaultTableSize = 4096,
  83. TableBitMask = 4095
  84. };
  85. SimObject *table[DefaultTableSize];
  86. void *mutex;
  87. public:
  88. void insert(SimObject* obj);
  89. void remove(SimObject* obj);
  90. SimObject* find(S32 id);
  91. SimIdDictionary();
  92. ~SimIdDictionary();
  93. };
  94. #endif //_SIMDICTIONARY_H_