void BlockHashIndex::CalcHash(size_t current, void* source_void) { #ifdef HAVE_CMPH cmph_io_adapter_t* source = (cmph_io_adapter_t*) source_void; cmph_config_t *config = cmph_config_new(source); cmph_config_set_algo(config, CMPH_CHD); cmph_t* hash = cmph_new(config); PairedPackedArray<> *pv = new PairedPackedArray<>(source->nkeys, m_orderBits, m_fingerPrintBits); size_t i = 0; source->rewind(source->data); std::string lastKey = ""; while(i < source->nkeys) { unsigned keylen; char* key; source->read(source->data, &key, &keylen); std::string temp(key, keylen); source->dispose(source->data, key, keylen); if(lastKey > temp) { if(source->nkeys != 2 || temp != "###DUMMY_KEY###") { std::cerr << "ERROR: Input file does not appear to be sorted with LC_ALL=C sort" << std::endl; std::cerr << "1: " << lastKey << std::endl; std::cerr << "2: " << temp << std::endl; abort(); } } lastKey = temp; size_t fprint = GetFprint(temp.c_str()); size_t idx = cmph_search(hash, temp.c_str(), (cmph_uint32) temp.size()); pv->Set(idx, i, fprint, m_orderBits, m_fingerPrintBits); i++; } cmph_config_destroy(config); #ifdef WITH_THREADS boost::mutex::scoped_lock lock(m_mutex); #endif if(m_hashes.size() <= current) { m_hashes.resize(current + 1, 0); m_arrays.resize(current + 1, 0); m_clocks.resize(current + 1, 0); } m_hashes[current] = (void*)hash; m_arrays[current] = pv; m_clocks[current] = clock(); m_queue.push(-current); #endif }
void BlockHashIndex::CalcHash(size_t current, void* source_void) { #ifdef HAVE_CMPH cmph_io_adapter_t* source = (cmph_io_adapter_t*) source_void; cmph_config_t *config = cmph_config_new(source); cmph_config_set_algo(config, CMPH_CHD); cmph_t* hash = cmph_new(config); PairedPackedArray<> *pv = new PairedPackedArray<>(source->nkeys, m_orderBits, m_fingerPrintBits); size_t i = 0; source->rewind(source->data); while(i < source->nkeys) { unsigned keylen; char* key; source->read(source->data, &key, &keylen); std::string temp(key, keylen); size_t fprint = GetFprint(temp.c_str()); size_t idx = cmph_search(hash, temp.c_str(), (cmph_uint32) temp.size()); pv->Set(idx, i, fprint, m_orderBits, m_fingerPrintBits); i++; } cmph_config_destroy(config); #ifdef WITH_THREADS boost::mutex::scoped_lock lock(m_mutex); #endif if(m_hashes.size() <= current) { m_hashes.resize(current + 1, 0); m_arrays.resize(current + 1, 0); m_clocks.resize(current + 1, 0); } m_hashes[current] = (void*)hash; m_arrays[current] = pv; m_clocks[current] = clock(); m_queue.push(-current); #endif }