Пример #1
0
ContextTree *ctw_create(uint32_t depth) {
  ContextTree *tree = (ContextTree *) malloc(sizeof(ContextTree));
  tree->depth = depth;
  tree->root = ctw_node_create();
  tree->history = bv_create();
  tree->context = ctw_list_create();
  return tree;
}
Пример #2
0
BitVector *ctw_gen_random_symbols_and_update(ContextTree *tree, uint64_t n) {
  BitVector *symbols = bv_create();
  uint64_t i;
  for (i = 0; i < n; i++) {
    double p = ((double) rand()) / ((double) RAND_MAX);
    bool symbol;
    if (p < ctw_predict_symbol(tree, true)) {
      symbol = true;
    } else {
      symbol = false;
    }
    bv_push(symbols, symbol);
    ctw_update_symbol(tree, symbol);
  }
  return symbols;
}
Пример #3
0
BITVEC *reads_not_in_set(CJOB *settings, char *sfafname, char *fbvfname, READSET *set) {
    char *sbvfname = get_bvfname_from_one_fafname(settings, sfafname);
    int i = 0;

    BITVEC *sbv = bv_read_from_file(sbvfname);
    BITVEC *diff = bv_create(sbv->num_bits);
    int j = 0;
    for(j = 0; j < set->num_files; j++) {
        if(j != i) {
            char *isbvfname = get_bvfname_of_index_and_search(settings, set->filenames[j], set->filenames[i]);
            BITVEC *isbv = bv_copy(bv_read_from_file(isbvfname));
            bv_ior(diff, isbv);
        }
    }
    bv_inot(diff);
    bv_iand(diff, sbv);
    return diff;
}
Пример #4
0
BITVEC *reads_elsewhere_in_set(CJOB *settings, READSET *set, int i) {
    char *sbvfname = get_bvfname_from_one_fafname(settings, set->filenames[i]);
    BITVEC *sbv = bv_read_from_file(sbvfname);
    BITVEC *others = bv_create(sbv->num_bits);

    int j = 0;
    for(j = 0; j < set->num_files; j++) {
        if(j != i) {
            char *isbvfname = get_bvfname_of_index_and_search(settings, set->filenames[j], set->filenames[i]);
            BITVEC *isbv = bv_copy(bv_read_from_file(isbvfname));
            bv_ior(others, isbv);
        }
    }

    bv_iand(others, sbv);
    bv_destroy(sbv);
    free(sbvfname);
    return others;
}
Пример #5
0
static void ensure_allocate_imagebuffer()
{
    if (edgebuf == NULL)
    {
        edgebuf = bv_create(viewport_height * viewport_width, 1);
        if (edgebuf != NULL)
            memset(edgebuf->ptr, 0, edgebuf->ptrLen);
    }
    if (conf.edge_overlay_filter && (smbuf == NULL))
    {
        smbuf = (unsigned char*)malloc(viewport_byte_width*3);
        if (smbuf != NULL)
            memset(smbuf, 0, viewport_byte_width*3);
        else
        {
            // Disable filtering if we do not have enough memory for it
            conf.edge_overlay_filter = 0;
        }
    }
}
Пример #6
0
int main( int argc, char *argv[] ) {
	//srand(time(NULL));
	if( argc > 2 ) {
		const int LEN
			= atoi(argv[1]);
		const int INI
			= atoi(argv[2]);
		struct boolean_vector *v
			= bv_create( LEN, INI );
		if( v ) {
			int n;
			bool state = false, _3arg = false;
			/**
			  * Every argument must be a /([CcSs]|[0-9]+)/
			  * Perform a command-line-specified series of operations
			  * on the boolean_vector, then...
			  */
			for(int i = 3; i < argc; i++ ) {
				const char *arg = argv[i];
				if( isdigit( arg[0] ) ) {
					const int flag = atoi(arg);
					if( _3arg ) {
						v->setstate( v, flag, state );
					} else {
						if( state )
							v->set( v, flag );
						else
							v->clr( v, flag );
					}
				} else {
					switch( arg[0] ) {
					case 's':
						state = true;
						_3arg = false;
						break;
					case 'c':
						state = false;
						_3arg = false;
						break;
					case 'S':
						state = true;
						_3arg = true;
						break;
					case 'C':
						state = false;
						_3arg = true;
						break;
					default:
						abort();
					}
				}
			}

			/**
			  * ...dump the results by .write as well as .pop.
			  */

			n = v->popcount(v);

			if( n > 0 ) {
				uint32_t *arr;
				printf( "Set bits (accessed by .write):\n" );
				arr = alloca( n * sizeof(uint32_t));
				v->write(v, arr, n );
				printf( "%d", arr[0] );
				for(int i = 1; i < n; i++ )
					printf( ",%d", arr[i] );

				printf( "\nSet bits (accessed by .pop):\n" );
				printf( "%d", v->pop(v) );
				while( (n = v->pop(v)) >= 0 )
					printf( ",%d", n );
				putchar( '\n' );
			} else
				puts( "no bits set" );

			assert( v->popcount(v) == 0 ); // exhausted by .pop above.

			v->destroy( v );
		}
	} else
		errx( -1, "%s <len> <init_set> bit1 [ bit2 bit3 ... ]\n", argv[0] );
	return EXIT_SUCCESS;
}