Perhaps the hash table itself will report the number of detected collectors without exposing its internal implementation at all.
For hash tables using sensing (of any type), the number of columns is equal to the number of elements located at an index that does not match their hash code (that is, because the position in which they were usually stored was already taken).
For hash tables using a chain, the number of columns is equal to the number of elements in the hash table, minus the number of buckets occupied (in other words, count all inserted elements except the first in each bucket). It is also quite intuitive.
So, what would I do in your shoes is to give each hash table the count_colissions()
method, which calculates the number of columns in O (n) time using the appropriate method and returns it.
source share