/*************************************************************************** * * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved * $Id: bsl_test_hash_qa.h,v 1.5 2008/12/15 09:57:00 xiaowei Exp $ * **************************************************************************/ /** * @file bsl_test_hash_qa.h * @author xiaowei(com@baidu.com) * @date 2008/11/13 19:54:05 * @version $Revision: 1.5 $ * @brief * **/ #ifndef __BSL_TEST_HASH_QA_H_ #define __BSL_TEST_HASH_QA_H_ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define __XASSERT(flag, fmt, arg...) \ {\ bool ___bsl_flag = flag; \ if (!(___bsl_flag)) { \ fprintf(stdout, "\n[error][%s:%d][%s]"fmt"\n", __FILE__, __LINE__, #flag, ##arg); \ return false; \ }\ } #define __XASSERT2(flag) __XASSERT(flag, "") bool test_hash_qa () { { bsl::hashmap h; __XASSERT2(h.create((1UL<<10UL) - 1UL) == 0); } if (0) { bsl::hashmap h; if (sizeof(void *) == sizeof(char)*4) { __XASSERT2(h.create(1<<30) != 0); } else { __XASSERT2(h.create(1<<30) == 0); } } return true; } bool test_hash_qa2 () { bsl::phashmap v; std::map h; int num = 10; for (int i=0; i::iterator iter=v.begin(); iter != v.end(); ++iter) { std::cout<first<<" "<second<, bsl::bsl_cpsalloc > > vs; __XASSERT2(vs.create(1000, 10, cmpstr) == 0); vs.set("hello"); vs.set("hell3"); vs.set("hell2"); vs.set("hello"); __XASSERT2(vs.size() == 3); vs.erase("hello"); __XASSERT2(vs.size() == 2); vs.clear(); return true; } void * _fun_ (void *param) { bsl::bsl_rwhashset *vs = (bsl::bsl_rwhashset *)param; for (int i=0; i<100; ++i) vs->set(0); return NULL; } bool test_hash_qa4 () { bsl::bsl_rwhashset vs; __XASSERT2(vs.create(1000) == 0); pthread_t pid[10]; for (size_t i=0; i struct type_t { char data[size]; }; // htt template void set_type(type_t & __key, int n) { assert (size >= sizeof(int)); int * dat = (int *)__key.data; *dat = n; } // htt template struct hash_key { size_t operator () (const type_t &__key)const { assert (size >= sizeof(int)); return *((int *)__key.data); } }; template struct hash_equal { bool operator () (const type_t &__key1, const type_t &__key2)const { for(int i = 0; i < (int)size; i++){ if(__key1.data[i] != __key2.data[i]){ return false; } } return true; } }; template bool test_hash_qa5() { std::cout<<"bsl_readset"<, hash_key ,hash_equal > rm_t; //./.bench --hash_bucket=2000000 --hash_datanum=1000000 --thread_num=1 --value_size=128 --query_loop=1 int hash_bucket = 2000000; int hash_datanum = 1000000; rm_t hash; hash.create(hash_bucket); std::cout< > vec; type_t v; for (int i=0; i<(int)hash_datanum; ++i) { set_type(v, i); vec.push_back(v); } std::cout<<"Time stamp(ass): "< >(hash, p); for (int i=0; i()); } }; #endif //__BSL_TEST_HASH_QA_H_ /* vim: set ts=4 sw=4 sts=4 tw=100 */