hashtab.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Westwood Library *
  23. * *
  24. * $Archive:: /Commando/Code/Library/hashtab.h $*
  25. * *
  26. * Author:: Greg Hjelstrom *
  27. * *
  28. * $Modtime:: 7/30/98 10:07a $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #ifndef HASHTAB_H
  36. #define HASHTAB_H
  37. #if 0
  38. template <class Object,class Key> class NamedObjectHashTableClass
  39. {
  40. public:
  41. HashTableClass(int initialsize,int growthrate,HashCalculatorClass<Key> * hasher);
  42. ~HashTableClass(void);
  43. void Add(Object * new_item,Key * key);
  44. void Remove(Object * item,Key * key);
  45. int Count(void) const { return Items.Count(); }
  46. Object * Find(const Key & key) const
  47. private:
  48. enum { NO_ITEM = 0xFFFFFFFF };
  49. class HashItem
  50. {
  51. public:
  52. T * Item;
  53. int NextHashIndex;
  54. bool operator == (const HashItem & that) { return ((Item == that.Item) && (NextHashIndex == that.NextHashIndex)); }
  55. bool operator != (const HashItem & that) { return !(*this == that); }
  56. };
  57. // Dynamic Vector of the unique items:
  58. DynamicVectorClass<HashItem> Items;
  59. // Hash table:
  60. int HashTableSize;
  61. int * HashTable;
  62. // object which does the hashing for the type
  63. HashCalculatorClass<T> * HashCalculator;
  64. friend class VectorClass;
  65. friend class DynamicVectorClass;
  66. };
  67. template <class Object,class Key>
  68. HashTableClass<Object,Key>::HashTableClass
  69. (
  70. int initialsize,
  71. int growthrate,
  72. HashCalculatorClass<Object> * hasher
  73. )
  74. {
  75. }
  76. template <class Object,class Key>
  77. HashTableClass<Object,Key>::~HashTableClass(void)
  78. {
  79. }
  80. template <class Object,class Key>
  81. Object * HashTableClass<Object,Key>::Find(Key * key) const
  82. {
  83. // compute where in the hash table this key would go.
  84. HashCalculator->Compute_Hash(key);
  85. int hashval = HashCalculator->Get_Hash_Value(0);
  86. // now try to find an object which has the same key
  87. int test_item_index = HashTable[hash];
  88. while (test_item_index != 0xFFFFFFFF) {
  89. if (HashCalculator->Items_Match(Items[test_item_index].Item,new_item)) {
  90. return Items[test_item_index].Object;
  91. }
  92. test_item_index = Items[test_item_index].NextHashIndex;
  93. }
  94. // couldn't find it
  95. return NULL;
  96. }
  97. #endif
  98. #endif