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