hashcalc.h 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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:: /G/wwlib/hashcalc.h $*
  25. * *
  26. * Author:: Greg Hjelstrom *
  27. * *
  28. * $Modtime:: 4/02/99 11:59a $*
  29. * *
  30. * $Revision:: 3 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if _MSC_VER >= 1000
  36. #pragma once
  37. #endif // _MSC_VER >= 1000
  38. #ifndef HASHCALC_H
  39. #define HASHCALC_H
  40. /*
  41. ** HashCalculatorClass
  42. ** The hash calculator is used to abstract the process of computing a hash
  43. ** value for an object. Also, when dealing with floating point values, you
  44. ** may need to have a fudge factor and therefore have several valid hash
  45. ** values for a particular object (generated by adding and subtracting an
  46. ** epsilon to the number(s)). This class lets you define any number
  47. ** of hash values. This class is used by the UniqueArrayClass and the HashTableClass
  48. ** templates. Basically, you give one of these to the UniqueArrayClass at
  49. ** construction time. It will call the Num_Hash_Bits function in order to
  50. ** properly allocate its hash table. Then, for each object you pass into the
  51. ** Add function, it will call Compute_Hash, then it will loop through
  52. ** Num_Hash_Values, calling Get_Hash_Value for each index and see if the object
  53. ** is found in the indicated slot. Also, when it is checking to see if it has
  54. ** the object you "Added", the Items_Match function is called. This again
  55. ** allows you to do epsilon tests. Make sense?
  56. */
  57. template <class T> class HashCalculatorClass
  58. {
  59. public:
  60. virtual bool Items_Match(const T & a, const T & b) = 0;
  61. virtual void Compute_Hash(const T & item) = 0;
  62. virtual int Num_Hash_Bits(void) = 0;
  63. virtual int Num_Hash_Values(void) = 0;
  64. virtual int Get_Hash_Value(int index = 0) = 0;
  65. };
  66. #endif