int main(int argc, char* argv[]) { std::ifstream in; openFile(argv[1],in); auto us = readFile<std::unordered_set<std::string>>(in); std::cout << "Read " << us.size() << " words from " << argv[1] << ".\n\n"; std::cout << "Hashtable load factor is: " << us.load_factor() << ".\n"; auto bc = us.bucket_count(); std::cout << "Bucket count is: " << us.bucket_count() << ".\n"; for (int b = 0; b < bc; ++b) { if (us.bucket_size(b)) { std::cout << "Bucket " << b << " contains " << us.bucket_size(b) << " items.\n"; if (us.bucket_size(b) > 1) { std::copy(us.cbegin(b),us.cend(b), std::ostream_iterator<std::string>(std::cout," ")); std::cout << std::endl; } } } }
std::pair<typename VectorHashTable<Parms>::iterator, bool> VectorHashTable<Parms>::insert(const value_type & d) { MutableFindIterator j(this, parms_.key(d)); vector_iterator i = vector_.begin() + j.i; if (!parms_.is_multi && !j.at_end()) return std::pair<iterator,bool>(iterator(i,this),false); if (load_factor() > .92) { resize(bucket_count()*2); return insert(d); } if (parms_.is_multi) while(!j.at_end()) j.adv(); *(vector_.begin() + j.i) = d; ++size_; return std::pair<iterator,bool>(iterator(i,this),true); }
/* analyzeSong ~ Processes song lyrics into the hash table: */ void WordTable::analyzeSong(Song* song){ for (size_t i = 0; i < song->lyrics.size(); i++){ if (load_factor() > LOADMAX) expand(); //expand if necessary uint32_t hash = hashWord(alphaOnly(song->lyrics[i])); if (table[hash] == NULL){ //if word doesn't exist in table //make new wordNode wordNode *node = new wordNode; node->word = alphaOnly(song->lyrics[i]); //first songs_and_freqs index initialized node->songs_and_freqs[0].song = song; node->songs_and_freqs[0].freq = 1; node->numSongs=1; table[hash] = node; numWords++; } else duplicateWord(hash, song); //word is in table already } }
void smtlib2_hashtable_set(smtlib2_hashtable *t, intptr_t key, intptr_t val) { size_t i; uint32_t h; smtlib2_hashtable_bucket *b; if (load_factor(t) > 0.7) { rehash(t, smtlib2_vector_size(t->table_)+1); } h = t->hf_(key); i = h % smtlib2_vector_size(t->table_); b = find_bucket(t, key, i); if (b) { b->val_ = val; } else { b = (smtlib2_hashtable_bucket *)malloc( sizeof(smtlib2_hashtable_bucket)); b->next_ = (smtlib2_hashtable_bucket *)smtlib2_vector_at(t->table_, i); b->key_ = key; b->val_ = val; smtlib2_vector_at(t->table_, i) = (intptr_t)b; ++t->size_; } }
void HashMap<Key, T, Hasher, EqualKey, Alloc>:: max_load_factor(float z){ mlf_ = std::max(z, load_factor() ); }