Esempio n. 1
0
File: example.c Progetto: cap/sort_r
int main()
{
  /* sort 1..19, 30..20, 30..100 */
  #define LEN 18
  int arr[LEN] = {1, 5, 28, 4, 3, 2, 10, 20, 18, 25, 21, 29, 34, 35, 14, 100, 27, 19};
  int ans[LEN] = {1, 2, 3, 4, 5, 10, 14, 18, 19, 29, 28, 27, 25, 21, 20, 34, 35, 100};
  int tmp[LEN];

  /* Region to invert: 20-30 (inclusive) */
  int interval[2] = {20, 30};
  int i, res = 1;
  const int tlen = 100000;
  int *tarray = NULL;

  printf("Test 1:\n");
  printf("sort_r\n");
  memcpy(tmp, arr, LEN*sizeof(int));
  print_list(tmp, LEN);
  sort_r(tmp, LEN, sizeof(int), sort_r_cmp, interval);
  print_list(tmp, LEN);
  res &= check_list(tmp, ans, LEN);

  printf("sort_r_simple\n");
  memcpy(tmp, arr, LEN*sizeof(int));
  print_list(tmp, LEN);
  sort_r_simple(tmp, LEN, sizeof(int), sort_r_cmp, interval);
  print_list(tmp, LEN);
  res &= check_list(tmp, ans, LEN);

  printf("Test 2:\n");
  tarray = malloc(tlen * sizeof(int));
  for(i = 0; i < tlen; i++) tarray[i] = i;
  /* sort integers */
  sort_r(tarray, tlen, sizeof(tarray[0]), cmp_int, NULL);
  for(i = 0; i < tlen && tarray[i] == i; i++) {}
  res &= (i == tlen);
  sort_r_simple(tarray, tlen, sizeof(tarray[0]), cmp_int, NULL);
  for(i = 0; i < tlen && tarray[i] == i; i++) {}
  res &= (i == tlen);
  /* reverse sort integers */
  sort_r(tarray, tlen, sizeof(tarray[0]), cmpr_int, NULL);
  for(i = 0; i < tlen && tarray[i] == tlen-i-1; i++) {}
  res &= (i == tlen);
  sort_r_simple(tarray, tlen, sizeof(tarray[0]), cmpr_int, NULL);
  for(i = 0; i < tlen && tarray[i] == tlen-i-1; i++) {}
  res &= (i == tlen);
  free(tarray);

  printf("return: %s\n", res ? "PASS" : "FAIL");
  return res ? EXIT_SUCCESS : EXIT_FAILURE;
}
Esempio n. 2
0
void smith_waterman_align2(const char *a, const char *b,
                           size_t len_a, size_t len_b,
                           const scoring_t *scoring, sw_aligner_t *sw)
{
  aligner_t *aligner = &sw->aligner;
  sw_history_t *hist = &sw->history;
  aligner_align(aligner, a, b, len_a, len_b, scoring, 1);

  size_t arr_size = aligner->score_width * aligner->score_height;
  _ensure_history_capacity(hist, arr_size);

  // Set number of hits
  memset(hist->match_scores_mask.b, 0, (hist->match_scores_mask.l+31)/32);
  hist->num_of_hits = hist->next_hit = 0;

  size_t pos;
  for(pos = 0; pos < arr_size; pos++) {
    if(aligner->match_scores[pos] > 0)
      hist->sorted_match_indices[hist->num_of_hits++] = pos;
  }

  // Now sort matched hits
  MatrixSort tmp_struct = {aligner->match_scores, aligner->score_width};
  sort_r(hist->sorted_match_indices, hist->num_of_hits,
         sizeof(size_t), sort_match_indices, &tmp_struct);
}
Esempio n. 3
0
static int
dict_order(Word dict, int ex ARG_LD)
{ Functor data = (Functor)dict;
  int arity = arityFunctor(data->definition);

  assert(arity%2 == 1);

  sort_r(data->arguments+1, arity/2, sizeof(word)*2,
	 compare_dict_entry, LD);

  return dict_ordered(data->arguments+1, arity/2, ex PASS_LD) == TRUE;
}
Esempio n. 4
0
File: sort.c Progetto: alakasame/Ls
t_l		*sort(t_l *list, char *flag, char *path)
{
	t_l	*base;

	base = list;
	sor(list);
	if (isflag(flag, 't'))
		list = sort_t(list, flag, base, path);
	else if (isflag(flag, 'r'))
		list = sort_r(list, base);
	return (list);
}
Esempio n. 5
0
File: sort.c Progetto: alakasame/Ls
t_l		*sort_r(t_l *list, t_l *base)
{
	t_l		*tmp;
	char	*mtp;

	tmp = list;
	list = list->next;
	while (list)
	{
		ft_putstr(list->str);
		if (ft_strcmp(list->str, tmp->str) > 0)
		{
			mtp = tmp->str;
			tmp->str = list->str;
			list->str = mtp;
			return (sort_r(base, base));
		}
		tmp = list;
		list = list->next;
	}
	return (base);	
}
Esempio n. 6
0
int
dict_order_term_refs(term_t *av, int *indexes, int count ARG_LD)
{ order_term_refs ctx;

  ctx.ld = LD;
  ctx.av = av;

  sort_r(indexes, count, sizeof(int), compare_term_refs, &ctx);
  if ( count > 1 )
  { word k = *valTermRef(av[indexes[0]*2]);
    int i;

    for(i=1; i<count; i++)
    { word k2 = *valTermRef(av[indexes[i]*2]);

      if ( k == k2 )
	return i;
      k = k2;
    }
  }

  return 0;
}
Esempio n. 7
0
int
permute_trans (permute_t *perm, state_info_t *state, perm_cb_f cb, void *ctx)
{
    perm->call_ctx = ctx;
    perm->real_cb = cb;
    perm->state = state;
    perm->nstored = perm->start_group_index = 0;
    int                 count = 0;
    state_data_t        data = state_info_pins_state (state);

    if (inhibit) {
        int N = dm_nrows (perm->inhibit_matrix);
        int class_count[N];
        for (int i = 0; i < N; i++) {
            class_count[i] = 0;
            if (is_inhibited(perm, class_count, i)) continue;
            if (perm->class_label >= 0) {
                class_count[i] = GBgetTransitionsMatching (perm->model, perm->class_label, i, data, permute_one, perm);
            } else if (perm->class_matrix != NULL) {
                class_count[i] = GBgetTransitionsMarked (perm->model, perm->class_matrix, i, data, permute_one, perm);
            } else {
                Abort ("inhibit set, but no known classification found.");
            }
            count += class_count[i];
        }
    } else {
        count = GBgetTransitionsAll (perm->model, data, permute_one, perm);
    }

    switch (perm->permutation) {
    case Perm_Otf:
        randperm (perm->pad, perm->nstored, state->ref + perm->shiftorder);
        for (size_t i = 0; i < perm->nstored; i++)
            perm_do (perm, perm->pad[i]);
        break;
    case Perm_Random:
        for (size_t i = 0; i < perm->nstored; i++)
            perm_do (perm, perm->rand[perm->nstored][i]);
        break;
    case Perm_Dynamic:
        sort_r (perm->tosort, perm->nstored, sizeof(int), dyn_cmp, perm);
        perm_do_all (perm);
        break;
    case Perm_RR:
        sort_r (perm->tosort, perm->nstored, sizeof(int), rr_cmp, perm);
        perm_do_all (perm);
        break;
    case Perm_SR:
        sort_r (perm->tosort, perm->nstored, sizeof(int), rand_cmp, perm);
        perm_do_all (perm);
        break;
    case Perm_Sort:
        sort_r (perm->tosort, perm->nstored, sizeof(int), sort_cmp, perm);
        perm_do_all (perm);
        break;
    case Perm_Shift:
        perm_do_all (perm);
        break;
    case Perm_Shift_All:
        for (size_t i = 0; i < perm->nstored; i++) {
            size_t j = (perm->start_group_index + i);
            j = j < perm->nstored ? j : 0;
            perm_do (perm, j);
        }
        break;
    case Perm_None:
        break;
    default:
        Abort ("Unknown permutation!");
    }
    return count;
}