diff --git a/configure.ac b/configure.ac index 2b4964c..567c844 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ dnl Process this file with autoconf to produce a configure script. AC_INIT AC_CONFIG_SRCDIR([Makefile.am]) -AM_INIT_AUTOMAKE(cmph, 1.0) +AM_INIT_AUTOMAKE(cmph, 2.0) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_MACRO_DIR([m4]) @@ -34,7 +34,7 @@ LDFLAGS="$LIBM $LDFLAGS" CFLAGS="-Wall" AC_PROG_CXX -CXXFLAGS="-Wall -Wno-unused-function -DNDEBUG -O3 -fomit-frame-pointer $CXXFLAGS" +CXXFLAGS="-Werror -Wall -Wno-unused-function -DNDEBUG -O3 -fomit-frame-pointer $CXXFLAGS" AC_ENABLE_CXXMPH if test x$cxxmph = xtrue; then AC_COMPILE_STDCXX_0X diff --git a/cxxmph/map_tester.h b/cxxmph/map_tester.h index ea2b358..d3e5972 100644 --- a/cxxmph/map_tester.h +++ b/cxxmph/map_tester.h @@ -11,6 +11,7 @@ namespace cxxmph { +using namespace cxxmph; using namespace std; template class map_type> @@ -24,8 +25,9 @@ struct MapTester { static bool large_insert() { map_type m; // Start counting from 1 to not touch default constructed value bugs - for (int i = 1; i < 12 * 256 * 256; ++i) m.insert(make_pair(i, i)); - return m.size() == 12 * 256 * 256 - 1; + int nkeys = 12 * 256 * 256; + for (int i = 1; i < nkeys; ++i) m.insert(make_pair(i, i)); + return static_cast(m.size()) == nkeys - 0; } static bool small_search() { map_type m; @@ -54,7 +56,7 @@ struct MapTester { int nkeys = 10 * 1000; vector keys; for (int i = 0; i < nkeys; ++i) { - keys.push_back(cxxmph::format("%v", i)); + keys.push_back(format("%v", i)); } map_type m; for (int i = 0; i < nkeys; ++i) m.insert(make_pair(keys[i], i)); @@ -65,6 +67,42 @@ struct MapTester { } return true; } + static bool rehash_zero() { + map_type m; + m.rehash(0); + return m.size() == 0; + } + static bool rehash_size() { + map_type m; + int nkeys = 10 * 1000; + for (int i = 0; i < nkeys; ++i) { m.insert(make_pair(i, i)); } + m.rehash(nkeys); + for (int i = 0; i < nkeys; ++i) { if (m.find(i) == m.end()) return false; } + for (int i = nkeys; i < nkeys * 2; ++i) { + if (m.find(i) != m.end()) return false; + } + return true; + } + static bool erase_iterator() { + map_type m; + int nkeys = 10 * 1000; + for (int i = 0; i < nkeys; ++i) { m.insert(make_pair(i, i)); } + for (int i = nkeys; i >= 0; --i) { + m.erase(m.find(i)); + if (static_cast(m.size()) != i) return false; + } + return true; + } + static bool erase_value() { + map_type m; + int nkeys = 10 * 1000; + for (int i = 0; i < nkeys; ++i) { m.insert(make_pair(i, i)); } + for (int i = nkeys; i >= 0; --i) { + m.erase(i); + if (static_cast(m.size()) != i) return false; + } + return true; + } }; } // namespace cxxxmph diff --git a/cxxmph/map_tester_test.cc b/cxxmph/map_tester_test.cc index d83697d..9091d0b 100644 --- a/cxxmph/map_tester_test.cc +++ b/cxxmph/map_tester_test.cc @@ -11,3 +11,7 @@ CXXMPH_CXX_TEST_CASE(small_search, Tester::small_search); CXXMPH_CXX_TEST_CASE(default_search, Tester::default_search); CXXMPH_CXX_TEST_CASE(large_search, Tester::large_search); CXXMPH_CXX_TEST_CASE(string_search, Tester::string_search); +CXXMPH_CXX_TEST_CASE(rehash_zero, Tester::rehash_zero); +CXXMPH_CXX_TEST_CASE(rehash_size, Tester::rehash_size); +CXXMPH_CXX_TEST_CASE(erase_value, Tester::erase_value); +CXXMPH_CXX_TEST_CASE(erase_iterator, Tester::erase_iterator); diff --git a/cxxmph/mph_map_test.cc b/cxxmph/mph_map_test.cc index 3310ad4..21d1b40 100644 --- a/cxxmph/mph_map_test.cc +++ b/cxxmph/mph_map_test.cc @@ -17,58 +17,7 @@ CXXMPH_CXX_TEST_CASE(small_search, Tester::small_search); CXXMPH_CXX_TEST_CASE(default_search, Tester::default_search); CXXMPH_CXX_TEST_CASE(large_search, Tester::large_search); CXXMPH_CXX_TEST_CASE(string_search, Tester::string_search); - -/* -using std::make_pair; -using std::string; -using cxxmph::mph_map; - -int main(int argc, char** argv) { - mph_map b; - int32_t num_keys = 1000*10; - for (int i = 0; i < num_keys; ++i) { - b.insert(make_pair(i, i)); - } - b.rehash(b.size()); - for (int i = 0; i < 1000000; ++i) { - auto it = b.find(i % num_keys); - if (it == b.end()) { - std::cerr << "Failed to find " << i << std::endl; - exit(-1); - } - if (it->first != it->second || it->first != i % num_keys) { - std::cerr << "Found " << it->first << " looking for " << i << std::endl; - exit(-1); - } - } - mph_map h; - h.insert(std::make_pair("-1",-1)); - mph_map::const_iterator it; - for (it = h.begin(); it != h.end(); ++it) { - if (it->second != -1) exit(-1); - } - int32_t num_valid = 100; - for (int i = 0; i < num_valid; ++i) { - char buf[10]; - snprintf(buf, 10, "%d", i); - h.insert(std::make_pair(buf, i)); - } - for (int j = 0; j < 100; ++j) { - for (int i = 1000; i > 0; --i) { - char buf[10]; - snprintf(buf, 10, "%d", i - 1); - auto it = h.find(buf); - if (i < num_valid && it->second != i - 1) exit(-1); - } - } - for (int j = 0; j < 100; ++j) { - for (int i = 1000; i > 0; --i) { - char buf[10]; - int key = i*100 - 1; - snprintf(buf, 10, "%d", key); - auto it = h.find(buf); - if (key < num_valid && it->second != key) exit(-1); - } - } -} -*/ +CXXMPH_CXX_TEST_CASE(rehash_zero, Tester::rehash_zero); +CXXMPH_CXX_TEST_CASE(rehash_size, Tester::rehash_size); +CXXMPH_CXX_TEST_CASE(erase_value, Tester::erase_value); +CXXMPH_CXX_TEST_CASE(erase_iterator, Tester::erase_iterator);