bool LinearHashDict::find(MazeState *key, MazeState *&pred) { // Returns true iff the key is found. // Returns the associated value in pred // TODO: Your code goes here... assert (key != NULL); assert (size >= 0); string keyID = key->getUniqId(); int probePoint = hash(keyID); assert (probePoint >= 0); for (int i = 1; i <= size; i++) { if (table[probePoint].key != NULL && table[probePoint].key->getUniqId() == keyID) { record_stats(i); pred = table[probePoint].data; return true; } else if (table[probePoint].key == NULL) { record_stats(i); return false; } else { probePoint = (probePoint + 1) % size; assert (probePoint >= 0); } } record_stats(size); return false; }
bool DoubleHashDict::find(MazeState *key, MazeState *&pred) { // Returns true iff the key is found. // Returns the associated value in pred std::cout << "find" << std::endl; // TODO: Your code goes here... int h = hash1(key->getUniqId())%size; int o = hash2(key->getUniqId())%size; int i = 0; for (i = 0; i < size; ++i) { //std::cout << "a" << std::endl; if (table[(h + o * i) % size].key == 0) break; if (table[(h + o * i) % size].key != 0 && table[(h + o * i) % size].key->getUniqId() == key->getUniqId()) { //found it pred = table[(h + o * i) % size].data; record_stats(++i); // off by 1? return true; } } record_stats(++i); return false; }
bool LinearHashDict::find(MazeState *key, MazeState *&pred) { // Returns true iff the key is found. // Returns the associated value in pred // TODO: Your code goes here... int probe = 0; int p = hash(key->getUniqId()) % size; for (int i=0; i<size; i++) { probe++; if (table[p].key == NULL) { record_stats(probe); return false; } if (table[p].key->getUniqId() == key->getUniqId()) { record_stats(probe); pred = table[p].data; return true; } p = (p+1)%size; } record_stats(probe); return false; }
bool AVLDict::find(MazeState *key, MazeState *&pred) { // TODO: Write this function! node * temp = root; int d = 0; while (temp != NULL) { d++; if (key->getUniqId() == temp->key->getUniqId()) { pred = temp->data; record_stats(d); return true; } else if (key->getUniqId() < temp->key->getUniqId()) { temp = temp->left; } else if (key->getUniqId() > temp->key->getUniqId()) { temp = temp->right; } } record_stats(d); return false; }
void census_record_rpc_server_stats(census_op_id op_id, const census_rpc_stats* stats) { record_stats(g_server_stats_store, op_id, stats); }
void census_record_rpc_client_stats(census_op_id op_id, const census_rpc_stats* stats) { record_stats(g_client_stats_store, op_id, stats); }