HashStatistic.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // HashStatistic.cpp
  3. //
  4. // $Id: //poco/1.4/Foundation/src/HashStatistic.cpp#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Hashing
  8. // Module: HashStatistic
  9. //
  10. // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #include "Poco/HashStatistic.h"
  16. #include <sstream>
  17. namespace Poco {
  18. HashStatistic::HashStatistic(
  19. UInt32 tableSize,
  20. UInt32 numEntries,
  21. UInt32 numZeroEntries,
  22. UInt32 maxEntry,
  23. std::vector<UInt32> details):
  24. _sizeOfTable(tableSize),
  25. _numberOfEntries(numEntries),
  26. _numZeroEntries(numZeroEntries),
  27. _maxEntriesPerHash(maxEntry),
  28. _detailedEntriesPerHash(details)
  29. {
  30. }
  31. HashStatistic::~HashStatistic()
  32. {
  33. }
  34. std::string HashStatistic::toString() const
  35. {
  36. std::ostringstream str;
  37. str << "HashTable of size " << _sizeOfTable << " containing " << _numberOfEntries << " entries:\n";
  38. str << " NumberOfZeroEntries: " << _numZeroEntries << "\n";
  39. str << " MaxEntry: " << _maxEntriesPerHash << "\n";
  40. str << " AvgEntry: " << avgEntriesPerHash() << ", excl Zero slots: " << avgEntriesPerHashExclZeroEntries() << "\n";
  41. str << " DetailedStatistics: \n";
  42. for (int i = 0; i < _detailedEntriesPerHash.size(); ++i)
  43. {
  44. // 10 entries per line
  45. if (i % 10 == 0)
  46. {
  47. str << "\n " << i << ":";
  48. }
  49. str << " " << _detailedEntriesPerHash[i];
  50. }
  51. str << "\n";
  52. str.flush();
  53. return str.str();
  54. }
  55. } // namespace Poco