void Yacht_Set_should_return_old_keys(uint8_t sz2) { yacht *y = Yacht_Init(sz2); TEST_ASSERT(y); const uint64_t other_large_prime = 4294967279L; /* (2 ** 32) - 17 */ for (int i = 0; i < (1 << (sz2 - 1)); i++) { int iv = i * other_large_prime; uintptr_t old = 0; TEST_ASSERT(Yacht_Set(y, iv, (void *)1, (void *)&old)); TEST_ASSERT_EQUAL(0, old); TEST_ASSERT(Yacht_Set(y, iv, (void *)2, (void *)&old)); TEST_ASSERT_EQUAL(1, old); uintptr_t val = 0; TEST_ASSERT(Yacht_Get(y, iv, (void *)&val)); TEST_ASSERT_EQUAL(2, val); for (int j = 0; j < i; j++) { int jv = j * other_large_prime; TEST_ASSERT(Yacht_Member(y, jv)); } } Yacht_Free(y, NULL, NULL); }
/* Check if KEY is in the table. */ bool Yacht_Member(struct yacht *y, int key) { LOG(" -- checking membership for %d\n", key); return Yacht_Get(y, key, NULL); }