示例#1
0
文件: lab07.c 项目: 0lumide/cs
int main()
{
  //LOCAL DECLARATION
  int input; //This is the number entered by the user received from getInput
  int num; //This is the variable to be used in the for loop to find the firt prime number
  int count; //This is the vaue recieved from calcPrime function
  int sec_num; //This is the second number that fulfils the condition of adding to the first number to give double the input
  int count2 = 1; //This counts the amount of pairs of prime numbers that have been found

  //EXECUTABLE STATEMENTS
  input = getInput();
  for (num = 1; num <= input; num++)
  {
    count = calcPrime(num);
    if (count == 2)
    {
      sec_num = input * 2 - num;
      count = calcPrime(sec_num);
      if (count == 2)
      {
        printOut(num, sec_num, & count2);
        count2++;
      }
    }
  }
  if (count2 == 1)
  {
    printf("\nNo prime pairs found.");
  }
  printf("\n\n");
  return(0);
}
示例#2
0
int Hash::EvalHashSize(uint32_t uSize, const uint32_t uNodeSize) {
	//计算前就大于最大bucket, 直接返回
	if (maxBucket < uSize) {
		return -1;
	}

	//先去计算bucket大小
	calcPrime(uSize, localHashInfo.uBucket);

	//计算后发现大于最大bucket, 直接返回
	if (maxBucket < localHashInfo.uBucket) {
		return -2;
	}

	localHashInfo.uNodeSize = uNodeSize;
	localHashInfo.uShmSize = localHashInfo.uBucket * localHashInfo.uNodeSize
			+ sizeof(HashInfo);

	return localHashInfo.uShmSize;
}
示例#3
0
sym_fd_t symOpen(int hash_size)
{
	sym_fd_t		sd;
	sym_tabent_t	*tp;

	a_assert(hash_size > 2);

/*
 *	Create a new handle for this symbol table
 */
	if ((sd = hAlloc((void***) &sym)) < 0) {
		return -1;
	}

/*
 *	Create a new symbol table structure and zero
 */
	if ((tp = (sym_tabent_t*) balloc(B_L, sizeof(sym_tabent_t))) == NULL) {
		symMax = hFree((void***) &sym, sd);
		return -1;
	}
	memset(tp, 0, sizeof(sym_tabent_t));
	if (sd >= symMax) {
		symMax = sd + 1;
	}
	a_assert(0 <= sd && sd < symMax);
	sym[sd] = tp;

/*
 *	Now create the hash table for fast indexing.
 */
	tp->hash_size = calcPrime(hash_size);
	tp->hash_table = (sym_t**) balloc(B_L, tp->hash_size * sizeof(sym_t*));
	a_assert(tp->hash_table);
	memset(tp->hash_table, 0, tp->hash_size * sizeof(sym_t*));

	return sd;
}