diff options
author | Carl Dong <contact@carldong.me> | 2022-06-30 23:10:55 -0400 |
---|---|---|
committer | Carl Dong <contact@carldong.me> | 2022-08-03 12:02:31 -0400 |
commit | 08dbc6ef72db48168dc03991f5f838dae42c8dfd (patch) | |
tree | f78f5551eea5874f068a05f3bbab1a9563f01493 /src/cuckoocache.h | |
parent | 0dbce4b1034b53d19b88af332385a006098b6d48 (diff) |
cuckoocache: Return approximate memory size
Returning the approximate total size eliminates the need for
InitS*Cache() to do nElems*sizeof(uint256). The cuckoocache has a better
idea of this information.
Diffstat (limited to 'src/cuckoocache.h')
-rw-r--r-- | src/cuckoocache.h | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/cuckoocache.h b/src/cuckoocache.h index d0dc61c7e6..5fc852439f 100644 --- a/src/cuckoocache.h +++ b/src/cuckoocache.h @@ -336,8 +336,8 @@ public: uint32_t setup(uint32_t new_size) { // depth_limit must be at least one otherwise errors can occur. - depth_limit = static_cast<uint8_t>(std::log2(static_cast<float>(std::max((uint32_t)2, new_size)))); size = std::max<uint32_t>(2, new_size); + depth_limit = static_cast<uint8_t>(std::log2(static_cast<float>(size))); table.resize(size); collection_flags.setup(size); epoch_flags.resize(size); @@ -357,12 +357,16 @@ public: * * @param bytes the approximate number of bytes to use for this data * structure - * @returns the maximum number of elements storable (see setup() - * documentation for more detail) + * @returns A pair of the maximum number of elements storable (see setup() + * documentation for more detail) and the approxmiate total size of these + * elements in bytes. */ - uint32_t setup_bytes(size_t bytes) + std::pair<uint32_t, size_t> setup_bytes(size_t bytes) { - return setup(bytes/sizeof(Element)); + auto num_elems = setup(bytes/sizeof(Element)); + + size_t approx_size_bytes = num_elems * sizeof(Element); + return std::make_pair(num_elems, approx_size_bytes); } /** insert loops at most depth_limit times trying to insert a hash |