aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMax Horn2009-09-06 12:59:07 +0000
committerMax Horn2009-09-06 12:59:07 +0000
commitae16d496b9f2b245167a8af3fdab3e124364047d (patch)
tree821b9ae1da031348b65aa430018f58e83e640262 /test
parentb51e9988e61733b5675623a598afc9ff436caf38 (diff)
downloadscummvm-rg350-ae16d496b9f2b245167a8af3fdab3e124364047d.tar.gz
scummvm-rg350-ae16d496b9f2b245167a8af3fdab3e124364047d.tar.bz2
scummvm-rg350-ae16d496b9f2b245167a8af3fdab3e124364047d.zip
COMMON: HashMap::getVal now allows specifying a default value.
A new variant of HashMap::getVal with a second 'default value' parameter has been added. This helps avoid many contains() + getVal() combos (which incur double lookup penalty), and is much lighter than using find() (which has to create an iterator). svn-id: r43983
Diffstat (limited to 'test')
-rw-r--r--test/common/hashmap.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/common/hashmap.h b/test/common/hashmap.h
index 6476005eaf..03db5518c0 100644
--- a/test/common/hashmap.h
+++ b/test/common/hashmap.h
@@ -86,6 +86,24 @@ class HashMapTestSuite : public CxxTest::TestSuite
TS_ASSERT_EQUALS(container[4], 96);
}
+ void test_lookup_with_default() {
+ Common::HashMap<int, int> container;
+ container[0] = 17;
+ container[1] = -1;
+ container[2] = 45;
+ container[3] = 12;
+ container[4] = 96;
+
+ // We take a const ref now to ensure that the map
+ // is not modified by getVal.
+ const Common::HashMap<int, int> &containerRef = container;
+
+ TS_ASSERT_EQUALS(containerRef.getVal(0), 17);
+ TS_ASSERT_EQUALS(containerRef.getVal(17), 0);
+ TS_ASSERT_EQUALS(containerRef.getVal(0, -10), 17);
+ TS_ASSERT_EQUALS(containerRef.getVal(17, -10), -10);
+ }
+
void test_iterator_begin_end() {
Common::HashMap<int, int> container;