Exemple #1
0
static void _init_history(sw_history_t *hist)
{
  bitset_alloc(&hist->match_scores_mask, 256);
  hist->hits_capacity = 256;
  size_t mem = hist->hits_capacity * sizeof(*(hist->sorted_match_indices));
  hist->sorted_match_indices = malloc(mem);
}
Exemple #2
0
/* Obtain and set a PID for the new process.
 * O(1) in average case, O(N) degenerate case (more than PID_MAX procs)
 * Uses hardware FFS instruction, so runs in very quick N/32 time */
static int _set_pid(process_create_data *data) {
    // Try to increment _last_pid.
    int err;
    sos_pcb *pcb = data->pcb;
    int cur_pid = _last_pid + 1;
    sos_pcb *taken = NULL;

    if (!pids) {
        dprintf(6, "Allocating PID set...\n");
        bitset_alloc(&pids, SOS_PID_MAX - SOS_PID_MIN);
    }

    dprintf(1, "bs size: %d\n", pids->size);

    if (bitset_test(pids, cur_pid)) {
        dprintf(6, "\tPID %d is already taken.\n", cur_pid);
        // cur_pid is taken
        cur_pid = bitset_ffz(pids);
        dprintf(6, "\tfirst free PID: %d\n", cur_pid);
        if (cur_pid < 0 || cur_pid > pids->size) {
            return SOS_PROCESS_MAXPROC;
        }
    }

    // cur_pid is known to be free
    bitset_set(pids, cur_pid);
    pcb->pid = cur_pid + SOS_PID_MIN;
    _last_pid = cur_pid;
    HASH_ADD_INT(_process_table, pid, pcb);
    return SOS_PROCESS_SUCCESS;
}
Exemple #3
0
static void conv_highlight_keywords(struct conv *conv)
{
    int key_index = 0;
    scheme *sc = conv->proc->sc;
    pointer sym = conv->proc->code;
    
    assert(sc);
    assert(sym);

    if (sym == sc->NIL) {
        warn("%s: conv proc not a symbol", __FUNCTION__);
        return;
    }

    pointer ifc = sc->vptr->find_slot_in_env(sc, sc->envir, sym, 1);
    if (! scm_is_pair(sc, ifc)) {
        warn("%s: conv '%s' has no value", __FUNCTION__, scm_sym_val(sc, sym));
        return;
    }

    pointer clos = scm_cdr(sc, ifc);
    if (! scm_is_closure(sc, clos)) {
        warn("%s: conv '%s' not a closure", __FUNCTION__, scm_sym_val(sc, sym));
        return;
    }

    pointer env = scm_cdr(sc, clos);
    pointer vtable = scm_cdr(sc, scm_car(sc, scm_car(sc, env)));

    conv->n_keywords = scm_len(sc, vtable);

    if (!(conv->keywords = (char**)calloc(conv->n_keywords, sizeof(char*)))) {
        warn("%s: failed to allocate keyword array size %d", __FUNCTION__, conv->n_keywords);
        return;
    }

    if (!(conv->marked = bitset_alloc(conv->n_keywords))) {
        warn("%s: failed to allocate bitset array size %d", __FUNCTION__, conv->n_keywords);
        return;
    }

    while (scm_is_pair(sc, vtable)) {
        pointer binding = scm_car(sc, vtable);
        vtable = scm_cdr(sc, vtable);
        pointer var = scm_car(sc, binding);
        if (conv_add_keyword(conv, scm_sym_val(sc, var), key_index)) {
            return;
        }
        key_index++;
    }

    conv_sort_keywords(conv);
}
Exemple #4
0
int main(int argc, char * argv[]) {
  struct bitset_t * b = bitset_alloc(65);
  bitset_set_bit(b, 0);
  bitset_set_bit(b, 5);
  bitset_set_bit(b, 3);
  bitset_set_bit(b, 10);
  bitset_set_bit(b, 59);
  bitset_reset_bit(b, 10);
  fprintf(stdout, "bitset = ");
  bitset_print(b, stdout);
  fputs("\n", stdout);
  return 0;
}
Exemple #5
0
// ascii test
int main()
{
	// create a bitset capable of representing any ascii char
	bitset_t set = bitset_alloc(128);

	char str1[255];

	printf("\033[1;34mplease enter characters to set:\033[0m ");
	fgets(str1, 255, stdin);

	char* p = str1;
	while(*p != '\0' && *p != '\n')
	{
		bitset_set(set, (int)(*p), 1);
		++p;
	}

	printf("\n\033[1;34mbitset looks like:\n\033[1;36m");
	bitset_print(set);
	print_bitset_chars(set);

	printf("\033[1;34mplease enter characters to delete:\033[0m ");
	fgets(str1, 255, stdin);
	p = str1;
	while(*p != '\0' && *p != '\n')
	{
		bitset_set(set, (int)(*p), 0);
		++p;
	}

	printf("\n\033[1;34mbitset looks like:\n\033[1;36m");
	bitset_print(set);
	print_bitset_chars(set);

	printf("\033[0m\n");
	return 0;
}