add SkTHashTable::LookupOrNull()
This should help avoid confusion from T**.
Change-Id: I1851baa2a55714721fa935d234b6a4a1c6d6504f
Reviewed-on: https://skia-review.googlesource.com/c/182562
Commit-Queue: Mike Klein <mtklein@google.com>
Commit-Queue: Herb Derby <herb@google.com>
Auto-Submit: Mike Klein <mtklein@google.com>
Reviewed-by: Herb Derby <herb@google.com>
diff --git a/tests/HashTest.cpp b/tests/HashTest.cpp
index 667f8ea..f80bd79 100644
--- a/tests/HashTest.cpp
+++ b/tests/HashTest.cpp
@@ -177,3 +177,25 @@
// We allow copies for same-value adds for now.
REPORTER_ASSERT(r, globalCounter == 5);
}
+
+
+DEF_TEST(HashFindOrNull, r) {
+ struct Entry {
+ int key = 0;
+ int val = 0;
+ };
+
+ struct HashTraits {
+ static int GetKey(const Entry* e) { return e->key; }
+ static uint32_t Hash(int key) { return key; }
+ };
+
+ SkTHashTable<Entry*, int, HashTraits> table;
+
+ REPORTER_ASSERT(r, nullptr == table.findOrNull(7));
+
+ Entry seven = { 7, 24 };
+ table.set(&seven);
+
+ REPORTER_ASSERT(r, &seven == table.findOrNull(7));
+}