Beispiel #1
0
int solve (int sud[9][9], int cur_d_i,int cur_d_j){
	int i, j;

	if(cur_d_j = 8)
		cur_d_j = 0;

	for (i = cur_d_i; i < 9; i++){
		for(j = cur_d_j; j < 9; j++){
			if(sud[i][j] == 0){//Initiation of recursion. Recursion enter point.

				if(next_value(sud, i, j) == -1){
					sud[i][j] = 0;
					return -1;
				}else
					sud[i][j] = next_value(sud, i, j);

				while (solve(sud, i, j) == -1){
					if(next_value(sud, i, j) == -1){
						sud[i][j] = 0;
						return -1;
					}else
						sud[i][j] = next_value(sud, i, j);
				}
			}

		}
	}
	return 0;
}
Beispiel #2
0
static void read_miscloop(param_t p)
{
  FILE *f = parfile("miscloop", p->use_dna_params);
  p->Extrapolation_for_large_loops = next_value(f);
  p->prelog = 10.79f;
  p->maximum_correction = next_value(f);
  p->fm_array_first_element = next_value(f);
  int_t tmp[3];
  look_for_arrow(f);
  read_next_values(f, tmp, 3);
  p->a = p->multibranched_loop_offset = tmp[0];
  p->b = p->multibranched_loop_per_nuc_penalty = tmp[1];
  p->c = p->multibranched_loop_helix_penalty = tmp[2];
  p->a_2c = p->a + 2*p->c;
  p->a_2b_2c = p->a + 2*p->b + 2*p->c;
  look_for_arrow(f); /* skip efn2 params */
  look_for_arrow(f); /* skip multiloop asym */
  look_for_arrow(f); /* skip multiloop strain */
  p->terminal_AU_penalty = next_value(f);
  p->bonus_for_GGG_hairpin = next_value(f);
  p->c_hairpin_slope = next_value(f);
  p->c_hairpin_intercept = next_value(f);
  p->c_hairpin_of_3 = next_value(f);
  look_for_arrow(f); /* skip Intermolecular initiation */
  p->Bonus_for_Single_C_bulges_adjacent_to_C = next_value(f);
  fclose(f);
}
Beispiel #3
0
 ifilter_iterator<Operator, List0>::ifilter_iterator(Operator _op,
                                                     List0 &_seq)
     : op(_op), iter(_seq.begin()), iter_end(_seq.end())
 {
   if (!test_filter(std::is_same<types::none_type, Operator>()))
     next_value();
 }
Beispiel #4
0
void destroy_Elimination(Elimination elim){

  word w;
  Iterator iter;

  if(elim){
    destroy_Map(elim->ordering);
    if(elim->cliques){
      iter = get_Iterator(elim->cliques);
      while(!is_empty(iter)){
        w = next_value(iter);
        destroy_Map((Map) w.v);
      }
      destroy_Map(elim->cliques);
    }
    if(elim->fill_ins){
      if(elim->fill_ins[0]){
        free(elim->fill_ins[0]);
      }
      free(elim->fill_ins);
    }
    if(elim->node_map){
      iter = get_Iterator(elim->node_map);
      while(!is_empty(iter)){
        w = next_key(iter);
        if(w.v){
          destroy_Node((Node) w.v);
        }
      }
      destroy_Map(elim->node_map);
    }
    free(elim);
  }
}
Beispiel #5
0
 ifilter_iterator<ResultType, Operator, List0>::ifilter_iterator(Operator _op, List0 _seq) :
     op(_op),
     iter(const_cast<sequence_type&>(_seq).begin()),
     iter_end(const_cast<sequence_type &>(_seq).end())
 {
     if (!test_filter(std::is_same<types::none_type, Operator>()))
         next_value();
 }
Beispiel #6
0
static void*
next_ptr(uintptr_t** sp)
{
	void* voidptr = (void*) next_value(sp);
	if(check_uptr(voidptr))
		return voidptr;
	else
		return NULL;
}
int main(int argc, char *argv[])
{
  char line[1000];

  fgets(line, sizeof(line), stdin);

  printf("Length of string %d\n", length(line));

  next_value();
  return 0;

}
Beispiel #8
0
int main(int argc, char** argv) {
    if (argc != 2) {
        printf("Wrong usage! Try this way: ./deque <number-of-items>\n");
        return 1;
    }

    blocking_deque<int> d;

    std::atomic<int> next_value(0);
    std::atomic<bool> finished(false);
    int total = std::stoi(argv[1]);

    std::thread producer([&]() {
        while (total > 0) {
            bool front = rand() % 2 == 0;
            int value = next_value++;
            if (front)
                d.push_front(value);
            else
                d.push_back(value);
            printf("stored %d on front? %d\n", value, (int)front);

            total--;
            std::this_thread::sleep_for(std::chrono::microseconds(rand() % 1000));
        }

        finished.store(true);
        printf("--> producer finished!\n");
    });

    std::thread consumer([&]() {
        while (!finished.load() || d.size() > 0) {
            bool front = rand() % 2 == 0;
            bool success = false;
            int element = 0;
            if (front)
                success = d.pop_front(&element);
            else
                success = d.pop_back(&element);
            printf("front? %d success? %d value = %d\n", (int)front, (int)success, element);

            std::this_thread::sleep_for(std::chrono::microseconds(rand() % 1000));
        }

        printf("--> consumer finished!\n");
    });

    producer.join();
    consumer.join();

    return 0;
}
Beispiel #9
0
TEST_F(HistogramUtilsTest, NextValueBruteForce) {
  const pmr_string supported_characters{"abcd"};
  constexpr size_t prefix_length{3u};
  constexpr auto max = 84ul;

  EXPECT_EQ(convert_string_to_number_representation("", supported_characters, prefix_length), 0ul);
  EXPECT_EQ(convert_string_to_number_representation("ddd", supported_characters, prefix_length), max);

  for (auto number = 1u; number <= max; number++) {
    const auto number_string = convert_number_representation_to_string(number, supported_characters, prefix_length);
    const auto next_value_of_previous_number =
        next_value(convert_number_representation_to_string(number - 1, supported_characters, prefix_length),
                   supported_characters, prefix_length);
    EXPECT_EQ(number_string, next_value_of_previous_number);
  }
}
Beispiel #10
0
void fiber_value(struct fbr_context *fiber_context, void *_arg)
{
	struct client_context *cc;
	struct my_value *value;
	struct me_cli_value *mv;
	int retval;
	ev_tstamp t1, t2, diff;
	cc = fbr_container_of(fiber_context, struct client_context, fbr);
	for (;;) {
		value = new_value(cc);
		record_value(cc, value);
		assert(value->buf);
		assert(value->buf->ptr);
		for (;;) {
			if (value->nreceived > 0)
				break;
			mv = me_cli_value_new(cc->conn);
			mv->data = (uint8_t *)value->buf->ptr;
			mv->data_len = value->buf->size;
			value->nsent++;
			ev_now_update(cc->loop);
			t1 = ev_now(cc->loop);
			retval = me_cli_value_submit(mv,
					cc->args_info.instance_timeout_arg);
			if (0 == retval) {
				value->latency = mv->latency;
				cc->last_iid = mv->iid;
				t2 = ev_now(cc->loop);
				diff = cc->args_info.each_arg - (t2 - t1);
				if (diff > 0)
					fbr_sleep(&cc->fbr, diff);
				if (value->nreceived > 0)
					break;
				next_value(cc, value, mv->iid);
				me_cli_value_processed(mv);
				me_cli_value_dispose(mv);
				break;
			}
			me_cli_value_processed(mv);
			me_cli_value_dispose(mv);
			cc->stats.timeouts++;
			assert(value->buf);
			assert(value->buf->ptr);
		}
	}
}
Beispiel #11
0
int is_clique_heuristic(int node, Map * adj_list){

  word w;
  unsigned long size;
  Iterator iter;

  size = get_size_Map(adj_list[node]);
  iter = get_Iterator(adj_list[node]);

  while(!is_empty(iter)){
    w = next_value(iter);
    if(get_size_Map(adj_list[((Node) w.v)->index]) < size){
      return 0;
    }
  }
  return 1;
}
Beispiel #12
0
STATIC int
pf_gametype_new(char *text, void *_context)
{
	GameTypeContext *context = (GameTypeContext *)_context;
	char *token;
	int key;

	token = first_token(text);
	if (token == NULL) {
		return (0);
	}

	if (strcmp(token, "end") == 0) {
		add_config_type(context->gametype);
		parse_func = pf_top_level;
		parse_context = NULL;
		return (0);
	}

	key = get_config_key(token, new_keys);

	if (key <= 0) {
		return (key);
	}

	token = next_token();
	if (strcmp(token, "=") != 0) {
		REPORT_ERROR((stderr, "Expecting \"=\", found \"%s\"", token));
		return (-1);
	}

	token = next_value();
	if ((token == NULL) && ((key != CK_MASTER_PROTOCOL) && (key != CK_MASTER_QUERY))) {
		REPORT_ERROR((stderr, "Missing value after \"=\""));
		return (-1);
	}

	if (debug) {
		printf("%d %s = <%s>\n", key, new_keys[key - 1].key_name, token ? token : "");
	}

	return (set_game_type_value(context->gametype, key, token));
}
Beispiel #13
0
STATIC int
pf_gametype_modify(char *text, void *_context)
{
	GameTypeContext *context = (GameTypeContext *)_context;
	char *token;
	int key;

	token = first_token(text);
	if (token == NULL) {
		return (0);
	}

	if (strcmp(token, "end") == 0) {
		parse_func = pf_top_level;
		parse_context = NULL;
		return (0);
	}

	key = get_config_key(token, modify_keys);

	token = next_token();

	if (strcmp(token, "=") != 0) {
		REPORT_ERROR((stderr, "Expecting \"=\", found \"%s\"", token));
		return (-1);
	}

	token = next_value();
	if (token == NULL) {
		REPORT_ERROR((stderr, "Missing value after \"=\""));
		return (-1);
	}

	if (debug) {
		printf("%d %s = <%s>\n", key, modify_keys[key - 1].key_name,
		    token ? token : "");
	}

	return (modify_game_type_value(context->gametype, key, token));
}
Beispiel #14
0
int is_clique(int node, Map * adj_list, int size){

  word w, w2;
  Map map = create_Map(size, compare, hash_int, empty(), 1);
  Iterator iter = get_Iterator(adj_list[node]);

  while(!is_empty(iter)){
    w = next_value(iter);
    w2.i = ((Node) w.v)->index;
    put(map, w2, w);
  }
  while(get_size_Map(map) > 0){
    iter = get_Iterator(map);
    w = next_key(iter);
    rem(map, w);
    if(!is_subset_of(map, adj_list[w.i])){
      destroy_Map(map);
      return 0;
    }
  }
  destroy_Map(map);
  return 1;
}
Beispiel #15
0
static void
syscall_handler (struct intr_frame* frame) 
{
	// -------- System Call Handler Overview -------- 
	// Get system call number
	// switch statement using system call number
	// collect arguments for system call function if necessary
	// call system call function
	// set frame->eax to return value if necessary
	// ----------------------------------------------
	uintptr_t* kpaddr_sp = (uintptr_t*) frame->esp;
	int syscall_num = -1;
	if(check_uptr(kpaddr_sp))
		syscall_num = next_value(&kpaddr_sp);
	else
		sysexit(-1);

	switch(syscall_num)
	{
		case SYS_HALT:                   
			{
				// Terminates Pintos
				shutdown_power_off();
			}
			break;
		case SYS_EXIT:                 
			{
				uintptr_t status = -1;
				if(check_uptr(kpaddr_sp))
					status = next_value(&kpaddr_sp);
				sysexit(status);
			}
			break;
		case SYS_EXEC:  //pid_t exec (const char *file);
			{
				const char* file =  next_charptr(&kpaddr_sp);
				if(file == NULL)
					sysexit(-1);

				unsigned len = strlen(file);
				if(!check_buffer(file, len))
					sysexit(-1);
				else
					sysexec(frame, file);
			}
			break;
		case SYS_WAIT:  //int wait (pid_t);
			{
				uintptr_t childid = -1;
				if(check_uptr(kpaddr_sp))
					childid = next_value(&kpaddr_sp);
				else
					sysexit(childid);
			
				int retval = process_wait((tid_t) childid);
				frame->eax = retval;
			}
			break;
		case SYS_CREATE:	//bool create (const char *file, unsigned initial_size);
			{
				const char* file =  next_charptr(&kpaddr_sp);
				if(file == NULL)
					sysexit(-1);

				unsigned len = strlen(file);
				if(!check_buffer(file, len))
					sysexit(-1);

				uintptr_t size = 0;
				if(check_uptr(kpaddr_sp))
					size = next_value(&kpaddr_sp);
				else
					sysexit(-1);

				syscreate(frame, file, size);
			}
			break;
		case SYS_REMOVE:	//bool remove (const char *file);
			{
				const char* file =  next_charptr(&kpaddr_sp);
				if(file == NULL)
					sysexit(-1);

				unsigned len = strlen(file);
				if(!check_buffer(file, len))
					sysexit(-1);

				sysremove(frame, file);
			}
			break;
		case SYS_OPEN:          
			{
				//int open (const char *file);
				const char* file =  next_charptr(&kpaddr_sp);
				if(file == NULL)
					sysexit(-1);

				unsigned len = strlen(file);
				if(!check_buffer(file, len))
					sysexit(-1);

	      		sysopen(frame, file);
			}
			break;
		case SYS_FILESIZE:     
			{
				//int filesize (int fd);
	      		int fd = 0;
	      		if (check_uptr(kpaddr_sp))
					fd = (int) next_value(&kpaddr_sp);
	      		else
					sysexit(-1);

	      		sysfilesize(frame, fd);
			}
			break;
		case SYS_READ:        
			{
				//int read (int fd, void *buffer, unsigned length);
				int fd = 0;
				if (check_uptr(kpaddr_sp))
					fd = (int) next_value(&kpaddr_sp);
				else
					sysexit(-1);

				const char* file =  next_charptr(&kpaddr_sp);
				if(file == NULL)
					sysexit(-1);

				unsigned len = strlen(file);
				if(!check_buffer(file, len))
					sysexit(-1);

				unsigned length = 0;
				if (check_uptr(kpaddr_sp))
					length = (unsigned) next_value(&kpaddr_sp);
				else
					sysexit(-1);

				sysread(frame, fd, (void*) file, length);
			}
			break;
		case SYS_WRITE:      
			{
				//int write (int fd, const void *buffer, unsigned length);
				uintptr_t fd = 0;
				if(check_uptr(kpaddr_sp))
					fd = next_value(&kpaddr_sp);
				else
					sysexit(-1);

				const char* file =  next_charptr(&kpaddr_sp);
				if(file == NULL)
					sysexit(-1);

				unsigned len = strlen(file);
				if(!check_buffer(file, len))
					sysexit(-1);

				uintptr_t length = 0;
				if(check_uptr(kpaddr_sp))
					length = next_value(&kpaddr_sp);
				else
					sysexit(-1);

				if(fd == CONSOLEWRITE) // Write to Console
				{
					while(length > 0)
					{
						if(length > MAX_SIZE)
						{
							putbuf (file, MAX_SIZE);
							file += MAX_SIZE;
							length -= MAX_SIZE;
						}
						else
						{
							putbuf (file, length);
							length = 0;
						}
					}
				}
				else
				{
					syswrite(frame, fd, file, length);
				}
			}
			break;
		case SYS_SEEK:
			{
				//void seek (int fd, unsigned position);
				int fd = 0;
				if (check_uptr(kpaddr_sp))
					fd = (int) next_value(&kpaddr_sp);
				else
					sysexit(-1);

				unsigned position = 0;
				if (check_uptr(kpaddr_sp))
					position = (unsigned) next_value(&kpaddr_sp);
				else
					sysexit(-1);

				sysseek(fd, position);
			}
			break;
		case SYS_TELL:
			{
				//unsigned tell (int fd);
				int fd = 0;
				if (check_uptr(kpaddr_sp))
					fd = (int) next_value(&kpaddr_sp);
				else
					sysexit(-1);

				systell(frame, fd);
			}
			break;
		case SYS_CLOSE:    
			{
				//void close (int fd);
				int fd = 0;
				if (check_uptr(kpaddr_sp))
					fd = (int) next_value(&kpaddr_sp);
				else
					sysexit(-1);

				sysclose(fd);
			}
			break;
		default:
			{
				printf("Unrecognized System Call\n");
				sysexit(-1);
			}
			break;
	}
}
Beispiel #16
0
 ifilter_iterator<ResultType, Operator, List0>& ifilter_iterator<ResultType, Operator, List0>::operator++()
 {
     next_value();
     return *this;
 }
Beispiel #17
0
 pmr_string _next_value(const pmr_string& value) { return next_value(value, _supported_characters, _prefix_length); }
Beispiel #18
0
/*
    if can find adj_list[i] that is a clique
      remove i, all edges from i;
      ordering[o++] = i;
      cliques[c++] = adj_list[i];
    else find adj_list[i] with smallest clique weight
      remove i, all edges from i;
      ordering[o++] = i;
      make adj_list[i] a clique;
      cliques[c++] = adj_list[i];
*/
Elimination elim(int size, Map * adj_list, Neighborhood * partial_order,
    Map node_map){

  Map ordering, cliques, max_cliques, trashcan;
  int i, j, clique_exists, min_node, subset, index1, index2;
  float min_weight, weight;
  word w, w2, child, child2;
  Iterator iter, iter2;
  Map nodes = create_Map(size, compare, hash_int, empty(), 1);
  Map roots = create_Map(size, compare, hash_int, empty(), 1);
  int ** fill_ins;

  fill_ins = (int **) malloc(sizeof(int *) * size);
  fill_ins[0] = (int *) malloc(sizeof(int) * size * size);

  for(i = 1; i < size; i++){
    fill_ins[i] = fill_ins[i - 1] + size;
  }
  for(i = 0; i < size; i++){
    for(j = 0; j < size; j++){
      fill_ins[i][j] = 0;
    }
  }

  for(i = 0; i < size; i++){
    w.i = i;
    put(nodes, w, w);
  }
  find_roots(partial_order, nodes, roots);

  ordering = create_Map(size + 1, compare, hash_int, empty(), 1);
  cliques = create_Map(size + 1, set_compare, hash_set, empty(), 1);

  while(get_size_Map(nodes) > 0){
    clique_exists = 0;
    iter = get_Iterator(roots);
    while(!is_empty(iter)){
      w = next_key(iter);
      if(is_clique_heuristic(w.i, adj_list) && is_clique(w.i, adj_list, size)){
        clique_exists = 1;
        break;
      }
    }
    if(!clique_exists){
      min_weight = LONG_MAX;
      iter = get_Iterator(roots);
      while(!is_empty(iter)){
        w = next_value(iter);
        weight = 0;
        iter2 = get_Iterator(adj_list[w.i]);
        while(!is_empty(iter2)){
          weight += ((Node) next_value(iter2).v)->weight;
        }
        if(weight < min_weight){
          min_weight = weight;
          min_node = w.i;
        }
      }
      w.i = min_node;
    }
    min_node = w.i;
    rem(nodes, w);
    remove_node(partial_order, w.i);
    empty_Map(roots);
    find_roots(partial_order, nodes, roots);
    put(ordering, w, w);
    child.v = adj_list[w.i];

    if(!find((Map) child.v, w)){
      child2.v = create_Node(w.i, 0);
      put(node_map, child2, child2);
      put((Map) child.v, w, child2);
    }
    child.v = copy_Map((Map) child.v);
    put(cliques, child, child);
    iter = get_Iterator(adj_list[min_node]);
    i = 0;
    while(!is_empty(iter)){
      child = next_value(iter);
      rem(adj_list[((Node) child.v)->index], w);
    }
    iter = create_Iterator(adj_list[min_node]);
    while(!is_empty(iter)){
      child = next_value(iter);
      index1 = ((Node) child.v)->index;
      w.i = index1;
      iter2 = get_Iterator(adj_list[min_node]);
      while(!is_empty(iter2)){
        child2 = next_value(iter2);
	index2 = ((Node) child2.v)->index;
	if(index1 != index2){
          w2.i = index2;
          if(index1 < index2 && !find(adj_list[index1], w2)){
            fill_ins[index1][index2] = 1;
	  }
          put(adj_list[index1], w2, child2);
        }
      }
    }
    destroy_Iterator(iter);
  }
  destroy_Map(nodes);
  destroy_Map(roots);

  max_cliques = create_Map(size, set_compare, hash_set, empty(), 2);
  trashcan = create_Map(size, set_compare, hash_set, empty(), 2);
  while(get_size_Map(cliques) > 0){
    iter = get_Iterator(cliques);
    child = next_key(iter);
    rem(cliques, child);
    subset = 0;
    while(!is_empty(iter)){
      child2 = next_key(iter);
      if(is_subset_of((Map) child2.v, (Map) child.v)){
        rem(cliques, child2);
	put(trashcan, child2, child2);
      } else if(is_subset_of((Map) child.v, (Map) child2.v)){
         subset = 1;
	 break;
      }
    }
    if(!subset){
      put(max_cliques, child, child);
    } else {
      put(trashcan, child, child);
    }
  }

  destroy_Map(cliques);
  iter = get_Iterator(trashcan);
  while(!is_empty(iter)){
    child = next_key(iter);
    destroy_Map((Map) child.v);
  }
  destroy_Map(trashcan);
  return create_Elimination(ordering, max_cliques, fill_ins, node_map);
}