diff --git a/configure.ac b/configure.ac index 2b4964c..a149229 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]) @@ -50,9 +50,11 @@ if test x$cxxmph = xtrue; then AC_SUBST([CXXMPH], "cxxmph") fi -PKG_CHECK_MODULES([CHECK], [check >= 0.9.8]) +PKG_CHECK_MODULES([CHECK], [check >= 0.9.8], [HAVE_LIBCHECK=1], [HAVE_LIBCHECK=]) if test "x$CHECK_LIBS" = "x" ; then - AC_MSG_WARN([Testing library not found, make check will fail.]) + if test "x$cxxmph" = "xtrue"; then + AC_MSG_WARN([Testing library not found, make check will fail.]) + fi fi AC_SUBST(CHECK_LIBS) AC_SUBST(CHECK_CFLAGS) diff --git a/cxxmph/Makefile.am b/cxxmph/Makefile.am index 08cdc44..06d90a5 100644 --- a/cxxmph/Makefile.am +++ b/cxxmph/Makefile.am @@ -4,14 +4,17 @@ noinst_PROGRAMS = bm_index bm_map bin_PROGRAMS = cxxmph cxxmph_includedir = $(includedir)/cxxmph/ -cxxmph_include_HEADERS = mph_map.h mph_index.h MurmurHash3.h trigraph.h seeded_hash.h stringpiece.h hollow_iterator.h +cxxmph_include_HEADERS = mph_bits.h mph_map.h mph_index.h MurmurHash3.h trigraph.h seeded_hash.h stringpiece.h hollow_iterator.h string_util.h -noinst_LTLIBRARIES = libcxxmph_test.la +check_LTLIBRARIES = libcxxmph_test.la +noinst_LTLIBRARIES = libcxxmph_bm.la lib_LTLIBRARIES = libcxxmph.la -libcxxmph_la_SOURCES = MurmurHash3.h MurmurHash3.cpp trigragh.h trigraph.cc mph_bits.h mph_bits.cc mph_index.h mph_index.cc seeded_hash.h stringpiece.h benchmark.h benchmark.cc string_util.cc +libcxxmph_la_SOURCES = MurmurHash3.cpp trigraph.cc mph_bits.cc mph_index.cc benchmark.h benchmark.cc string_util.cc libcxxmph_la_LDFLAGS = -version-info 0:0:0 libcxxmph_test_la_SOURCES = test.h test.cc libcxxmph_test_la_LIBADD = libcxxmph.la +libcxxmph_bm_la_SOURCES = benchmark.h benchmark.cc bm_common.h bm_common.cc +libcxxmph_bm_la_LIBADD = libcxxmph.la test_test_SOURCES = test_test.cc test_test_LDADD = libcxxmph_test.la $(CHECK_LIBS) @@ -22,14 +25,14 @@ mph_map_test_SOURCES = mph_map_test.cc mph_index_test_LDADD = libcxxmph.la mph_index_test_SOURCES = mph_index_test.cc -bm_index_LDADD = libcxxmph.la -lcmph -bm_index_SOURCES = bm_common.cc bm_index.cc - trigraph_test_LDADD = libcxxmph.la trigraph_test_SOURCES = trigraph_test.cc -bm_map_LDADD = libcxxmph.la -bm_map_SOURCES = bm_common.cc bm_map.cc +bm_index_LDADD = libcxxmph_bm.la -lcmph +bm_index_SOURCES = bm_index.cc + +bm_map_LDADD = libcxxmph_bm.la +bm_map_SOURCES = bm_map.cc cxxmph_LDADD = libcxxmph.la cxxmph_SOURCES = cxxmph.cc diff --git a/cxxmph/hollow_iterator.h b/cxxmph/hollow_iterator.h index 54fba74..3e6e76c 100644 --- a/cxxmph/hollow_iterator.h +++ b/cxxmph/hollow_iterator.h @@ -26,7 +26,7 @@ struct hollow_iterator_base : public std::iterator { public: - typedef hollow_iterator_base& self_type; + typedef hollow_iterator_base self_type; typedef self_type& self_reference; typedef typename iterator::reference reference; typedef typename iterator::pointer pointer; 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); diff --git a/src/Makefile.am b/src/Makefile.am index 0ab079a..a7c2cff 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,7 +3,7 @@ noinst_PROGRAMS = bm_numbers lib_LTLIBRARIES = libcmph.la include_HEADERS = cmph.h cmph_types.h cmph_time.h chd_ph.h libcmph_la_SOURCES = hash.h hash.c \ - jenkins_hash.h jenkins_hash.c MurmurHash2.h\ + jenkins_hash.h jenkins_hash.c \ hash_state.h debug.h \ vstack.h vstack.c vqueue.h vqueue.c\ graph.h graph.c bitbool.h \