Example #1
0
bool
forth(const char * const output_file, int size)
{
    assert(NULL != output_file && size > 0 && size <= MAXSIZE);
    if (NULL == output_file || size <= 0 || size > MAXSIZE)
        return false;

    FILE *fp = fopen(output_file, "w+");
    if (NULL == fp)
        return false;

    BitVector bv;
    bv.ptr = NULL;
    bv.size = 0;
    init_bit_vector(&bv, MAXSIZE);
    clear_allbits(&bv);

    int seed;
    while (size--) {
        seed = generate_random(seed, &bv);
        fprintf(fp, "%d\n", seed);
    }

    fclose(fp);

    return true;
}
Example #2
0
void fetchFromPipe(PipeMatcherRec* mrec)
{
	bit_vector tmp_val;
	init_bit_vector(&tmp_val, mrec->_value->width);
	
	read_bit_vector_from_pipe(mrec->_pipe_name, &tmp_val);
	assignValue(mrec, &tmp_val);
}
Example #3
0
void sendToPipe(PipeMatcherRec* mrec)
{
	bit_vector tmp_val;
	init_bit_vector(&tmp_val, mrec->_value->width);

	getValue(mrec, &tmp_val);
	write_bit_vector_to_pipe(mrec->_pipe_name, &tmp_val);
}
Example #4
0
void
second()
{
    BitVector bv;
    bv.ptr = NULL;
    bv.size = 0;

    if (init_bit_vector(&bv, MAXSIZE)){
        clear_allbits(&bv);
        // to do
        free_bit_vector(&bv);
    }
}
Example #5
0
void Rtl2AaSignalTransferMatcher(void* sig_val)
{
	SignalMatcherRec* mrec = (SignalMatcherRec*) sig_val;
	bit_vector tmp_val;
	init_bit_vector(&tmp_val, mrec->_value->width);

	while(1)
	{
		getSignalValue(mrec, &tmp_val);
		write_bit_vector_to_pipe(mrec->_signal_name, &tmp_val);
		PTHREAD_YIELD();
	}
}
Example #6
0
// signal to be communicated..
void Aa2RtlSignalTransferMatcher(void* sig_val)
{
	SignalMatcherRec* mrec = (SignalMatcherRec*) sig_val;
	bit_vector tmp_val;
	init_bit_vector(&tmp_val, mrec->_value->width);

	while(1)
	{
	
		read_bit_vector_from_pipe(mrec->_signal_name, &tmp_val);
		assignSignalValue(mrec, &tmp_val);
		PTHREAD_YIELD();
	}
}
Example #7
0
void
third(const char * const input_file, const char * const output_file)
{
    assert(NULL != input_file && NULL != output_file);
    if (NULL == output_file || NULL == input_file)
        return;

    FILE *fp_in = fopen(input_file, "r");
    FILE *fp_out = fopen(output_file, "w+");
    if (NULL == fp_in || NULL == fp_out)
        return;

    BitVector bv;
    bv.ptr = NULL;
    bv.size = 0;

    if (!init_bit_vector(&bv, MAXSIZE))
        return;

    clear_allbits(&bv);

    int cnt = 0;
    int tmp = 0;
    while (EOF != fscanf(fp_in, "%d\n", &tmp)){
        set_bit(bv.ptr, tmp);
        cnt++;
    }

    fclose(fp_in);

    int i = 0;
    while (i < MAXSIZE) {
        if (get_bit(bv.ptr, i)){
            fprintf(fp_out, "%d\n", i);
            if (0 == cnt--)
                break;
        }
        i++;
    }

    fclose(fp_out);
    free_bit_vector(&bv);
}
Example #8
0
int main() {
  init_bit_vector(0);
  {for (unsigned i = 0; i < 1600; i++) {
    BitVector bv;
    bv.set_bit(i, true);
    BitVectorIter iter(&bv);
    if (!iter.is_valid()) {
      fprintf(stderr, "ERROR: %d\n", i);
      continue;
    }
    size_t val = iter.current();
    if (val != i) {
      fprintf(stderr, "ERROR: %d\n", i);
      continue;
    }
    if (bv.count() != 1) {
      fprintf(stderr, "ERROR: %d\n", i);
      continue;
    }
    iter.next();
    if (iter.is_valid()) {
      fprintf(stderr, "ERROR: %d\n", i);
      continue;
    }
  }}
  
  {for (unsigned i = 24; i < 160; i++) {
    BitVector bv;
    bv.set_bit(i, true);
    for (unsigned j = 32; j < 160; j++) {
      if (j > 0 && j != i+1) bv.set_bit(j-1, false);
      if (i == j) continue;
      bv.set_bit(j, true);
      BitVectorIter iter(&bv);
      if (!iter.is_valid()) {
	fprintf(stderr, "ERROR: %d %d\n", i, j);
	continue;
      }

      size_t val = iter.current();
      if (bv.count() != 2) {
	fprintf(stderr, "ERROR: %d %d\n", i, j);
	continue;
      }
      iter.next();
      size_t val2 = iter.current();
      if (!iter.is_valid()) {
	fprintf(stderr, "ERROR: %d %d\n", i, j);
	continue;
      }
      if (!((val == i && val2 == j) ||
	    (val == j && val2 == i))) {
	fprintf(stderr, "ERROR: %d %d\n", i, j);
	continue;
      }
      iter.next();
      if (iter.is_valid()) {
	fprintf(stderr, "ERROR: %d %d\n", i, j);
	continue;
      }
    }
  }}


  return(0);
}