diff options
author | mtklein <mtklein@chromium.org> | 2015-08-07 09:33:37 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-07 09:33:37 -0700 |
commit | 469a3fe6edb3fb29acf6c03de662a6f00f6804b8 (patch) | |
tree | e3ed4991f9b28075e32fcafd0db742d48d050427 | |
parent | 3848427d884b72114854c8eef9662691f23fae7b (diff) |
Add approxBytesUsed to hashes.
BUG=skia:
Review URL: https://codereview.chromium.org/1280653003
-rw-r--r-- | include/private/SkTHash.h | 9 | ||||
-rw-r--r-- | tests/HashTest.cpp | 2 |
2 files changed, 11 insertions, 0 deletions
diff --git a/include/private/SkTHash.h b/include/private/SkTHash.h index ffcdea5329..561fc89b59 100644 --- a/include/private/SkTHash.h +++ b/include/private/SkTHash.h @@ -35,6 +35,9 @@ public: // How many entries are in the table? int count() const { return fCount; } + // Approximately how many bytes of memory do we use beyond sizeof(*this)? + size_t approxBytesUsed() const { return fCapacity * sizeof(Slot); } + // !!!!!!!!!!!!!!!!! CAUTION !!!!!!!!!!!!!!!!! // set(), find() and foreach() all allow mutable access to table entries. // If you change an entry so that it no longer has the same key, all hell @@ -199,6 +202,9 @@ public: // How many key/value pairs are in the table? int count() const { return fTable.count(); } + // Approximately how many bytes of memory do we use beyond sizeof(*this)? + size_t approxBytesUsed() const { return fTable.approxBytesUsed(); } + // N.B. The pointers returned by set() and find() are valid only until the next call to set(). // Set key to val in the table, replacing any previous value with the same key. @@ -259,6 +265,9 @@ public: // How many items are in the set? int count() const { return fTable.count(); } + // Approximately how many bytes of memory do we use beyond sizeof(*this)? + size_t approxBytesUsed() const { return fTable.approxBytesUsed(); } + // Copy an item into the set. void add(const T& item) { fTable.set(item); } diff --git a/tests/HashTest.cpp b/tests/HashTest.cpp index 848986162d..f53faaf864 100644 --- a/tests/HashTest.cpp +++ b/tests/HashTest.cpp @@ -23,6 +23,8 @@ DEF_TEST(HashMap, r) { map.set(3, 4.0); REPORTER_ASSERT(r, map.count() == 1); + REPORTER_ASSERT(r, map.approxBytesUsed() > 0); + double* found = map.find(3); REPORTER_ASSERT(r, found); REPORTER_ASSERT(r, *found == 4.0); |