Version bump

This commit is contained in:
Davi de Castro Reis 2012-06-02 22:29:46 -03:00
parent c7b77ae329
commit e808f82311
4 changed files with 51 additions and 60 deletions

View File

@ -1,7 +1,7 @@
dnl Process this file with autoconf to produce a configure script. dnl Process this file with autoconf to produce a configure script.
AC_INIT AC_INIT
AC_CONFIG_SRCDIR([Makefile.am]) AC_CONFIG_SRCDIR([Makefile.am])
AM_INIT_AUTOMAKE(cmph, 1.0) AM_INIT_AUTOMAKE(cmph, 2.0)
AC_CONFIG_HEADERS([config.h]) AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_MACRO_DIR([m4])
@ -34,7 +34,7 @@ LDFLAGS="$LIBM $LDFLAGS"
CFLAGS="-Wall" CFLAGS="-Wall"
AC_PROG_CXX 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 AC_ENABLE_CXXMPH
if test x$cxxmph = xtrue; then if test x$cxxmph = xtrue; then
AC_COMPILE_STDCXX_0X AC_COMPILE_STDCXX_0X

View File

@ -11,6 +11,7 @@
namespace cxxmph { namespace cxxmph {
using namespace cxxmph;
using namespace std; using namespace std;
template <template<typename...> class map_type> template <template<typename...> class map_type>
@ -24,8 +25,9 @@ struct MapTester {
static bool large_insert() { static bool large_insert() {
map_type<int64_t, int64_t> m; map_type<int64_t, int64_t> m;
// Start counting from 1 to not touch default constructed value bugs // 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)); int nkeys = 12 * 256 * 256;
return m.size() == 12 * 256 * 256 - 1; for (int i = 1; i < nkeys; ++i) m.insert(make_pair(i, i));
return static_cast<int>(m.size()) == nkeys - 0;
} }
static bool small_search() { static bool small_search() {
map_type<int64_t, int64_t> m; map_type<int64_t, int64_t> m;
@ -54,7 +56,7 @@ struct MapTester {
int nkeys = 10 * 1000; int nkeys = 10 * 1000;
vector<string> keys; vector<string> keys;
for (int i = 0; i < nkeys; ++i) { for (int i = 0; i < nkeys; ++i) {
keys.push_back(cxxmph::format("%v", i)); keys.push_back(format("%v", i));
} }
map_type<string, int64_t> m; map_type<string, int64_t> m;
for (int i = 0; i < nkeys; ++i) m.insert(make_pair(keys[i], i)); for (int i = 0; i < nkeys; ++i) m.insert(make_pair(keys[i], i));
@ -65,6 +67,42 @@ struct MapTester {
} }
return true; return true;
} }
static bool rehash_zero() {
map_type<int64_t, int64_t> m;
m.rehash(0);
return m.size() == 0;
}
static bool rehash_size() {
map_type<int64_t, int64_t> 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<int64_t, int64_t> 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<int>(m.size()) != i) return false;
}
return true;
}
static bool erase_value() {
map_type<int64_t, int64_t> 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<int>(m.size()) != i) return false;
}
return true;
}
}; };
} // namespace cxxxmph } // namespace cxxxmph

View File

@ -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(default_search, Tester::default_search);
CXXMPH_CXX_TEST_CASE(large_search, Tester::large_search); CXXMPH_CXX_TEST_CASE(large_search, Tester::large_search);
CXXMPH_CXX_TEST_CASE(string_search, Tester::string_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);

View File

@ -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(default_search, Tester::default_search);
CXXMPH_CXX_TEST_CASE(large_search, Tester::large_search); CXXMPH_CXX_TEST_CASE(large_search, Tester::large_search);
CXXMPH_CXX_TEST_CASE(string_search, Tester::string_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);
using std::make_pair; CXXMPH_CXX_TEST_CASE(erase_value, Tester::erase_value);
using std::string; CXXMPH_CXX_TEST_CASE(erase_iterator, Tester::erase_iterator);
using cxxmph::mph_map;
int main(int argc, char** argv) {
mph_map<int64_t, int64_t> 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<string, int> h;
h.insert(std::make_pair("-1",-1));
mph_map<string, int>::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);
}
}
}
*/