aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2015-04-01 11:21:27 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-04-01 11:21:27 -0700
commitfb8307c6b78bfbaa5e969a9df0c007c232d6251d (patch)
tree47400bafcc39e94f512810bb4b0011db228475a0
parent1865900525b6c6df19824813c0d3222ad6a90da2 (diff)
Add SkTHashSet::find()
-rw-r--r--src/core/SkTHash.h6
-rw-r--r--tests/HashTest.cpp10
2 files changed, 15 insertions, 1 deletions
diff --git a/src/core/SkTHash.h b/src/core/SkTHash.h
index 967b9be878..c4bd3b6161 100644
--- a/src/core/SkTHash.h
+++ b/src/core/SkTHash.h
@@ -231,7 +231,11 @@ public:
void add(const T& item) { fTable.set(item); }
// Is this item in the set?
- bool contains(const T& item) const { return SkToBool(fTable.find(item)); }
+ bool contains(const T& item) const { return SkToBool(this->find(item)); }
+
+ // If an item equal to this is in the set, return a pointer to it, otherwise null.
+ // This pointer remains valid until the next call to add().
+ const T* find(const T& item) const { return fTable.find(item); }
private:
struct Traits {
diff --git a/tests/HashTest.cpp b/tests/HashTest.cpp
index 5abf3db50a..d2acafe08b 100644
--- a/tests/HashTest.cpp
+++ b/tests/HashTest.cpp
@@ -1,3 +1,10 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
#include "SkChecksum.h"
#include "SkString.h"
#include "SkTHash.h"
@@ -61,6 +68,9 @@ DEF_TEST(HashSet, r) {
REPORTER_ASSERT(r, set.contains(SkString("World")));
REPORTER_ASSERT(r, !set.contains(SkString("Goodbye")));
+ REPORTER_ASSERT(r, set.find(SkString("Hello")));
+ REPORTER_ASSERT(r, *set.find(SkString("Hello")) == SkString("Hello"));
+
set.reset();
REPORTER_ASSERT(r, set.count() == 0);
}