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