double retrieve_value(PHASH* ph, TPAIR tp) { int start_idx = hash_fun(tp) % (ph -> length); int idx = start_idx; while(!pair_equal((ph -> p)[idx].key, tp)) idx = (idx + 1) % (ph -> length); return (ph -> p)[idx].val; }
double pair_array_match(PairArray *self, PairArray *other) { int i, j, matches = 0; int sum = self->len + other->len; if (sum == 0) return 1.0; for (i = 0; i < self->len; i++) { for (j = 0; j < other->len; j++) { #if DEBUG pair_print(self->pairs[i]); putc(' ', stdout); pair_print(other->pairs[j]); printf(" -> %d\n", pair_equal(self->pairs[i], other->pairs[j])); #endif if (pair_equal(self->pairs[i], other->pairs[j])) { matches++; other->pairs[j].status = PAIR_INACTIVE; break; } } } return ((double) (2 * matches)) / sum; }
//Return the idx of the element, -1 if not exist int exist_in_hash(PHASH* ph, TPAIR tp) { int start_idx = hash_fun(tp) % (ph -> length); int idx = start_idx; TPAIR temp_pair; while(1) { temp_pair = (ph -> p)[idx].key; if(is_null_entry(temp_pair)) return -1; else if(pair_equal(temp_pair, tp)) return idx; else { idx = (idx + 1) % (ph -> length); if(idx == start_idx) return -1; } } }
/** * Tests if the first pair is greater than or equal to the second pair. */ bool_t pair_greater_equal(const pair_t* cppair_first, const pair_t* cppair_second) { return (pair_greater(cppair_first, cppair_second) || pair_equal(cppair_first, cppair_second)) ? true : false; }
/** * Tests if the first pair is less than or equal to the second pair. */ bool_t pair_less_equal(const pair_t* cppair_first, const pair_t* cppair_second) { return (pair_less(cppair_first, cppair_second) || pair_equal(cppair_first, cppair_second)) ? true : false; }
/** * Tests if the two pair are not equal. */ bool_t pair_not_equal(const pair_t* cppair_first, const pair_t* cppair_second) { return !pair_equal(cppair_first, cppair_second); }