int hhsetput(HHSet *S, ulong x) {
  if (x == 0) return 0;
  ulong h = S->hash(x);
  if (hunt(S, h, x, 0)) return 1;
  if (hhashput(S->T, h, x)) return 1;
  if (!resize(S)) return 0;
  return hhashput(S->T, h, x);
}
Example #2
0
ulong fill(HHash *T) {
  ulong m = 0;
  for (ulong i = 0; i < 100; ++i) {
    ulong x = rand() % T->n;
    if (hhashsucc(T, x, 0) < 0)
      if (hhashput(T, x, x)) ++m;
  }
  return m;
}
int hhsetcopy(HHSet *S, HHSet *T) {
  for (int i = 0; i < S->T->n; ++i) {
    ulong x = S->T->V[i];
    if (x) {
      ulong h = T->hash(x);
      if (!hhashput(T->T, h, x)) return 0;
    }
  }
  return 1;
}
Example #4
0
int
main(void)
{
	uint n = 16;
	HHash *T = hhashnew(n);
	uint x = rand()%n;
	test(hhashput(T,x,1));
	uint i = hhashsucc(T,x,0);
	test(i == 0);
	hhashdel(T,x,i);
	test(hhashsucc(T,x,0) < 0);
	hhashfree(T);
	return 0;
}
Example #5
0
int
main(void)
{
	uint n = 16;
	HHash *T = hhashnew(n);
	uint x = rand()%n;
	test(hhashput(T,x,1));
	test(hhashsucc(T,x,0) == 0);
	test(hhashput(T,x,1));
	test(hhashsucc(T,x,1) == 1);
	test(hhashput(T,x,1));
	test(hhashsucc(T,x,2) == 2);
	test(hhashput(T,x,1));
	test(hhashsucc(T,x,3) == 3);
	test(!hhashput(T,x,1));
	--x;
	test(hhashput(T,x,1));
	test(hhashsucc(T,x,0) == 0);
	test(!hhashput(T,x,1));
	hhashfree(T);
	return 0;
}
Example #6
0
int
main(void)
{
	uint n = 16;
	HHash *T = hhashnew(n);
	uint x = 15;
	test(hhashput(T,x,1));
	test(hhashsucc(T,x,0) == 0);
	test(hhashput(T,x,1));
	test(hhashsucc(T,x,1) == 1);
	test(hhashput(T,x,1));
	test(hhashsucc(T,x,2) == 2);
	test(T->m == 3);
	x = 14;
	test(hhashput(T,x,1));
	test(hhashsucc(T,x,0) == 0);
	test(hhashput(T,x,1));
	test(hhashsucc(T,x,1) == 1);
	test(!hhashput(T,x,1));
	hhashfree(T);
	return 0;
}