HashStatistic.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // HashStatistic.h
  3. //
  4. // $Id: //poco/1.4/Foundation/include/Poco/HashStatistic.h#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Hashing
  8. // Module: HashStatistic
  9. //
  10. // Definition of the HashStatistic class.
  11. //
  12. // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
  13. // and Contributors.
  14. //
  15. // SPDX-License-Identifier: BSL-1.0
  16. //
  17. #ifndef Foundation_HashStatistic_INCLUDED
  18. #define Foundation_HashStatistic_INCLUDED
  19. #include "Poco/Foundation.h"
  20. #include <vector>
  21. namespace Poco {
  22. //@ deprecated
  23. class Foundation_API HashStatistic
  24. /// HashStatistic class bundles statistical information on the current state of a HashTable
  25. {
  26. public:
  27. HashStatistic(
  28. UInt32 tableSize,
  29. UInt32 numEntries,
  30. UInt32 numZeroEntries,
  31. UInt32 maxEntry,
  32. std::vector<UInt32> details = std::vector<UInt32>());
  33. /// Creates the HashStatistic.
  34. virtual ~HashStatistic();
  35. /// Destroys the HashStatistic.
  36. UInt32 maxPositionsOfTable() const;
  37. /// Returns the maximum number of different hash values possible for the table
  38. UInt32 numberOfEntries() const;
  39. /// Returns the total number of entries currently stored in the HashTable
  40. UInt32 numberOfZeroPositions() const;
  41. /// Returns the number of hash positions that contain no entry.
  42. double avgEntriesPerHash() const;
  43. /// Returns the average number of entries per position in the Hashtable, the higher this value the less efficient
  44. /// performs hashing. If a large value is returned and getNumberOfZeroPositions also returns a large value, this
  45. /// indicates an inefficient hashing function. If the number of zero entries is low, resizing the HashTable, should
  46. /// be enough to improve performance
  47. double avgEntriesPerHashExclZeroEntries() const;
  48. /// Same as getAvgEntriesPerHash but hash values that contain no entry are ignored,
  49. /// getAvgEntriesPerHashExclZeroEntries >= getAvgEntriesPerHash will always be true.
  50. UInt32 maxEntriesPerHash() const;
  51. /// Returns the maximum number of entries per hash value found in the current table.
  52. const std::vector<UInt32> detailedEntriesPerHash() const;
  53. /// Will either be an empty vector or will contain for each possible hash value, the number of entries currently stored
  54. std::string toString() const;
  55. /// Converts the whole data structure into a string.
  56. private:
  57. UInt32 _sizeOfTable;
  58. UInt32 _numberOfEntries;
  59. UInt32 _numZeroEntries;
  60. UInt32 _maxEntriesPerHash;
  61. std::vector<UInt32> _detailedEntriesPerHash;
  62. };
  63. inline UInt32 HashStatistic::maxPositionsOfTable() const
  64. {
  65. return _sizeOfTable;
  66. }
  67. inline UInt32 HashStatistic::numberOfEntries() const
  68. {
  69. return _numberOfEntries;
  70. }
  71. inline UInt32 HashStatistic::numberOfZeroPositions() const
  72. {
  73. return _numZeroEntries;
  74. }
  75. inline double HashStatistic::avgEntriesPerHash() const
  76. {
  77. return ((double) numberOfEntries()) / maxPositionsOfTable();
  78. }
  79. inline double HashStatistic::avgEntriesPerHashExclZeroEntries() const
  80. {
  81. return ((double) numberOfEntries()) / (maxPositionsOfTable() - numberOfZeroPositions());
  82. }
  83. inline UInt32 HashStatistic::maxEntriesPerHash() const
  84. {
  85. return _maxEntriesPerHash;
  86. }
  87. inline const std::vector<UInt32> HashStatistic::detailedEntriesPerHash() const
  88. {
  89. return _detailedEntriesPerHash;
  90. }
  91. } // namespace Poco
  92. #endif // Foundation_HashStatistic_INCLUDED