Пример #1
0
/*
 * Add bits of given value to the signature.
 */
void
signValue(BloomState *state, SignType *sign, Datum value, int attno)
{
	uint32		hashVal;
	int			nBit,
				j;

	/*
	 * init generator with "column's" number to get "hashed" seed for new
	 * value. We don't want to map the same numbers from different columns
	 * into the same bits!
	 */
	mySrand(attno);

	/*
	 * Init hash sequence to map our value into bits. the same values in
	 * different columns will be mapped into different bits because of step
	 * above
	 */
	hashVal = DatumGetInt32(FunctionCall1(&state->hashFn[attno], value));
	mySrand(hashVal ^ myRand());

	for (j = 0; j < state->opts.bitSize[attno]; j++)
	{
		/* prevent mutiple evaluation */
		nBit = myRand() % (state->opts.bloomLength * BITSIGNTYPE);
		SETBIT(sign, nBit);
	}
}
Пример #2
0
int main(int argc, char* argv[])
{
  int i, raw = 0, count = 100;
  char* outname = NULL;

  mySrand(time(NULL));

  for (i = 1; i < argc; i++)
  {
    if (!strcmp(argv[i], "-raw"))
    {
      raw = 1;
      continue;
    }
    else if (!strcmp(argv[i], "-o"))
    {
      if (i + 1 < argc)
      {
        ++i;
        outname = argv[i];
        continue;
      }
    }
    else if (!strcmp(argv[i], "-seed"))
    {
      if (i + 1 < argc)
      {
        ++i;
        mySeed = strtoul(argv[i], NULL, 0);
        continue;
      }
    }
    else if (!strcmp(argv[i], "-count"))
    {
      if (i + 1 < argc)
      {
        ++i;
        count = strtol(argv[i], NULL, 0);
        continue;
      }
    }

    fprintf(stderr, "Invalid or unsupported command line option '%s'\n", argv[i]);
    return EXIT_FAILURE;
  }

  if (outname)
    freopen(outname, "w", stdout);

  if (!raw)
  {
    printf("#include <limits.h>\n");
    printf("#include <stdio.h>\n");
    printf("#include <stdlib.h>\n\n");
    printf("// Ensure:\n");
    printf("// - expected type sizes\n");
    printf("extern char StAtIcAsSeRt[(CHAR_BIT == 8) ? 1 : -1];\n");
    printf("extern char StAtIcAsSeRt[(sizeof(int) == 4) ? 1 : -1];\n");
    printf("\n");
  }
  printf("int errors = 0;\n\n");
  for (i = 1; i <= count; i++)
    GenTestCase(i);
  printf("int main(void)\n{\n");
  for (i = 1; i <= count; i++)
    printf("  test%d();\n", i);
  printf("  if (errors)\n    { printf(\"%%d test(s) failed\\n\", errors); ");
  if (!raw)
    printf("return EXIT_FAILURE; ");
  else
    printf("return 1; ");
  printf("}\n");
  printf("  printf(\"All tests passed\\n\");\n");
  printf("  return 0;\n}\n");
  return 0;
}