Datum
test_chash(PG_FUNCTION_ARGS)
{
+ uint32 i;
hentry e;
- bool ok;
-
- e.key = 1;
- e.val = 0;
- ok = CHashSearch(chash, &e);
- if (ok)
- elog(LOG, "search 1: found (value = %d)", e.val);
- else
- elog(LOG, "search 1: not found");
-
- e.key = 1;
- e.val = 2;
- ok = CHashInsert(chash, &e);
- if (ok)
- elog(LOG, "insert 1: done");
- else
- elog(LOG, "insert 1: collision (value = %d)", e.val);
-
- e.key = 1;
- e.val = 0;
- ok = CHashSearch(chash, &e);
- if (ok)
- elog(LOG, "search 1: found (value = %d)", e.val);
- else
- elog(LOG, "search 1: not found");
-
- e.key = 1;
- e.val = 3;
- ok = CHashInsert(chash, &e);
- if (ok)
- elog(LOG, "insert 1: done");
- else
- elog(LOG, "insert 1: collision (value = %d)", e.val);
-
- e.key = 1;
- e.val = 0;
- ok = CHashSearch(chash, &e);
- if (ok)
- elog(LOG, "search 1: found (value = %d)", e.val);
- else
- elog(LOG, "search 1: not found");
+
+ for (i = 0; i < 1000000; ++i)
+ {
+ bool ok;
+
+ e.key = i;
+ e.val = i * 31;
+ ok = CHashInsert(chash, &e);
+ if (!ok)
+ elog(LOG, "insert %u: failed", i);
+ }
+
+ for (i = 0; i < 1000000; ++i)
+ {
+ bool ok;
+
+ e.key = i;
+ ok = CHashSearch(chash, &e);
+ if (!ok)
+ elog(LOG, "search %u: not found", i);
+ else if (e.val != e.key * 31)
+ elog(LOG, "search %u: found %u", i, e.val);
+ }
PG_RETURN_VOID();
}