Ejemplo n.º 1
0
GSList*
g_slist_sort (GSList *list, GCompareFunc func)
{
	if (!list || !list->next)
		return list;
	return do_sort (list, func);
}
Ejemplo n.º 2
0
    std::list<T> do_sort(std::list<T>& chunk_data) {  // 9
        if (chunk_data.empty()) {
            return chunk_data;
        }

        std::list<T> result;
        result.splice(result.begin(), chunk_data, chunk_data.begin());
        const T& partition_val = *result.begin();

        typename std::list<T>::iterator divide_point =  // 10
            std::partition(chunk_data.begin(), chunk_data.end(),
                           [&](const T& val) { return val < partition_val; });

        chunk_to_sort new_lower_chunk;
        new_lower_chunk.data.splice(new_lower_chunk.data.end(), chunk_data,
                                    chunk_data.begin(), divide_point);

        std::future<std::list<T>> new_lower =
            new_lower_chunk.promises.get_future();
        chunks.push(std::move(new_lower_chunk));  // 11
        if (threads.size() < max_thread_count) {  // 12
            threads.push_back(std::thread(&sorter<T>::sort_thread, this));
        }

        std::list<T> new_higher(do_sort(chunk_data));

        result.splice(result.end(), new_higher);
        while (new_lower.wait_for(std::chrono::seconds(0)) !=
               std::future_status::ready) {  // 13
            try_sort_chunk();                // 14
        }
        result.splice(result.begin(), new_lower.get());
        return result;
    }
Ejemplo n.º 3
0
/* Sort the data by the the variable which the editor has currently
   selected */
void
psppire_data_editor_sort_descending (PsppireDataEditor *de)
{
  PsppireSheetRange range;
  psppire_sheet_get_selected_range (PSPPIRE_SHEET(de->data_sheet[0]), &range);

  do_sort (de,  range.col0, TRUE);
}
Ejemplo n.º 4
0
void sort(struct Image * img, const Context_t * ctx) {
	// Create a list of sort plan steps
	SortPlan_t * plan_steps = create_sort_plan(img, ctx);

	for(const SortPlan_t * step = plan_steps; NULL != step; step = step->next_step_ptr) {
		Pixel_t * pixels = create_pixel_list(img, step);
		do_sort(pixels, step);
		sync_pixels(img, step, pixels);
	}

	destroy_sort_plan(plan_steps);
}
Ejemplo n.º 5
0
GList*
g_list_sort (GList *list, GCompareFunc func)
{
    GList *current;
    if (!list || !list->next)
        return list;
    list = do_sort (list, func);

    /* Fixup: do_sort doesn't update 'prev' pointers */
    list->prev = NULL;
    for (current = list; current->next; current = current->next)
        current->next->prev = current;

    return list;
}
Ejemplo n.º 6
0
int main(int argc, char *const argv[])
{
    int ret = EXIT_SUCCESS;
    unsigned int err;
    FILE *infile = stdin, *outfile = stdout;

    if (argc < 4 || (strcmp(argv[1], counting_sort_str) != 0
		     && strcmp(argv[1], radix_sort_str) != 0
		     && strcmp(argv[1], quick_sort_str) != 0
		     && strcmp(argv[1], insertion_sort_str) != 0
		     && strcmp(argv[1], system_quick_sort_str) != 0)) {
	usage();
	return EXIT_FAILURE;
    }


    if (strcmp(argv[2], "-") != 0) {
	infile = fopen(argv[2], "r");
	if (!infile) {
	    perror("Failed to open input file for reading");
	    ret = EXIT_FAILURE;
	    goto out;
	}
    }

    if (strcmp(argv[3], "-") != 0) {
	outfile = fopen(argv[3], "w");
	if (!outfile) {
	    perror("Failed to open output file for writing");
	    ret = EXIT_FAILURE;
	    goto out;
	}
    }

    err = do_sort(argv[1], infile, outfile);
    if (err)
	ret = EXIT_FAILURE;

  out:

    if (outfile && outfile != stdout)
	fclose(outfile);
    if (infile && infile != stdin)
	fclose(infile);

    return ret;
}
Ejemplo n.º 7
0
void menu::sort_by(int column)
{
	const bool already_sorted = (column == sortby_);

	if(already_sorted) {
		if(sortreversed_ == false) {
			sortreversed_ = true;
		} else {
			sortreversed_ = false;
			sortby_ = -1;
		}
	} else {
		sortby_ = column;
		sortreversed_ = false;
	}

	do_sort();
	itemRects_.clear();
	set_dirty();
}
Ejemplo n.º 8
0
void sort(struct image * img, const context_t * ctx)
{
    sort_plan_t *plan_steps;

    if(ROW == ctx->orientation) {
        plan_steps = create_sort_plan(img, ctx, ROW);
    } else if(COLUMN == ctx->orientation) {
        plan_steps = create_sort_plan(img, ctx, COLUMN);
    } else {
        plan_steps = create_sort_plan(img, ctx, ROW);
        plan_steps->next_step_ptr = create_sort_plan(img, ctx, COLUMN);
    }

    for(const sort_plan_t * step = plan_steps; NULL != step; step = step->next_step_ptr) {
        pixel_t * pixels = create_pixel_list(img, step);
        do_sort(pixels, step);
        sync_pixels(img, step, pixels);
    }

    destroy_sort_plan(plan_steps);
}
Ejemplo n.º 9
0
void menu::fill_items(const std::vector<std::string>& items, bool strip_spaces)
{
	for(std::vector<std::string>::const_iterator itor = items.begin();
	    itor != items.end(); ++itor) {

		if(itor->empty() == false && (*itor)[0] == HEADING_PREFIX) {
			heading_ = utils::quoted_split(itor->substr(1),COLUMN_SEPARATOR, !strip_spaces);
			continue;
		}

		const size_t id = items_.size();
		item_pos_.push_back(id);
		const item new_item(utils::quoted_split(*itor, COLUMN_SEPARATOR, !strip_spaces),id);
		items_.push_back(new_item);

		//make sure there is always at least one item
		if(items_.back().fields.empty()) {
			items_.back().fields.push_back(" ");
		}

		//if the first character in an item is an asterisk,
		//it means this item should be selected by default
		std::string& first_item = items_.back().fields.front();
		if(first_item.empty() == false && first_item[0] == DEFAULT_ITEM) {
			selected_ = id;
			first_item.erase(first_item.begin());
		}
	}

	create_help_strings();

	if(sortby_ >= 0) {
		do_sort();
	}
	update_size();
}
Ejemplo n.º 10
0
int main(int argc, char **argv) {
    for (int c; (c = getopt(argc, argv, "SVz")) != -1;) {
        switch (c) {
        case 'S':
            options.extract_season = true;
            break;
        case 'V':
            options.extract_volume = true;
            break;
        case 'z':
            options.delimiter = L'\0';
            break;
        default:
            usage();
            break;
        }
    }

    // This should go after getopt() because it prints error messages to stderr.
    std::ios::sync_with_stdio(NULL);
    std::wcin.tie(NULL);
    std::wcout.tie(NULL);

    const int nposarg = argc - optind;
    if (nposarg != 1) {
        usage();
    }
    const char *const action = argv[optind];
    if (strcmp(action, "sort") == 0) {
        return do_sort() ? EXIT_SUCCESS : EXIT_FAILURE;
    } else if (strcmp(action, "attach") == 0) {
        return do_attach() ? EXIT_SUCCESS : EXIT_FAILURE;
    } else {
        usage();
    }
}
Ejemplo n.º 11
0
 void sort_chunk(const std::shared_ptr<chunk_to_sort>& chunk) {
     chunk->promises.set_value(do_sort(chunk->data));  // 15
 }
Ejemplo n.º 12
0
Archivo: 2.cpp Proyecto: gameworld/cpp
 void sort_chunk(std::shared_ptr<chunk_to_sort > const& chunk)
 {
     chunk->promise.set_value(do_sort(chunk->data));
 }
Ejemplo n.º 13
0
int
g_print_stats (char *file, uint32_t flags, size_t block_sz)
{
  g_setjmp (0, "g_print_stats", NULL, NULL);

  if (block_sz)
    {
      g_act_1.block_sz = block_sz;
    }

  if (g_fopen (file, "r", F_DL_FOPEN_BUFFER | flags, &g_act_1))
    {
      return 2;
    }

  if (gfl & F_OPT_LOADQ)
    {
      goto rc_end;
    }

  void *buffer = calloc (1, g_act_1.block_sz);

  pt_g_bmatch proc_match = g_bmatch;

  int r = 0;

  if (gfl & F_OPT_SORT)
    {
      if (gfl & F_OPT_NOBUFFER)
	{
	  print_str ("ERROR: %s: unable to sort with buffering disabled\n",
		     g_act_1.file);
	  goto r_end;
	}

      void *s_exec = (void*) g_act_1.exec_args.exc;

      if (l_sfo == L_STFO_SORT)
	{
	  if (g_print_do_filter (&g_act_1, s_exec))
	    {
	      goto r_end;
	    }
	}

      if (gfl & F_OPT_KILL_GLOBAL)
	{
	  goto r_end;
	}

      if (do_sort (&g_act_1, g_sort_field, g_sort_flags))
	{
	  goto r_end;
	}

      if (l_sfo == L_STFO_FILTER)
	{
	  if (g_print_do_filter (&g_act_1, s_exec))
	    {
	      goto r_end;
	    }
	}

      if (gfl & F_OPT_KILL_GLOBAL)
	{
	  goto r_end;
	}

      g_act_1.max_hits = 0;
      g_act_1.max_results = 0;

      if (g_act_1.j_offset == 2)
	{
	  g_act_1.buffer.r_pos = md_last (&g_act_1.buffer);
	}
      else
	{
	  g_act_1.buffer.r_pos = md_first (&g_act_1.buffer);
	}

      //proc_match = g_bmatch_dummy;

      md_g_free_cb (&g_act_1._match_rr, g_cl_mrr);
    }

  __d_is_wb w_d_s = g_act_1.w_d;

  g_act_1.w_d = g_act_1.w_d_pr;

  g_do_ppprint (&g_act_1, F_GH_PRE_PRINT, &g_act_1.pre_print_mech,
		g_act_1.g_proc4_pr);

  if (gfl0 & F_OPT_LOADQA)
    {
      goto r_end;
    }

  g_act_1.w_d = w_d_s;

  void *ptr;

  size_t c = 0;

  g_setjmp (F_SIGERR_CONTINUE, "g_print_stats(loop)", NULL, NULL);

  g_act_1.buffer.offset = 0;

  if (!sigsetjmp(g_sigjmp.env, 1))
    {
      while ((ptr = g_read (buffer, &g_act_1, g_act_1.block_sz)))
	{
	  if ((gfl & F_OPT_KILL_GLOBAL))
	    {
	      break;
	    }

	  if ((r = proc_match (ptr, &g_act_1, &g_act_1.buffer)))
	    {
	      if (r == -1)
		{
		  print_str ("ERROR: %s: [%d] matching record failed\n",
			     g_act_1.file, r);
		  break;
		}

	      continue;
	    }

	  c++;
	  g_act_1.g_proc4 ((void*) &g_act_1, ptr, NULL);

	}

    }
  else
    {
      print_str (
	  "ERROR: %s: an exception has occured, terminating enumeration and attempt cleanup..\n",
	  g_act_1.file);
      EXITVAL = 2;
      goto r_end;
    }

  g_act_1.w_d = g_act_1.w_d_po;

  g_do_ppprint (&g_act_1, F_GH_POST_PRINT, &g_act_1.post_print_mech,
		g_act_1.g_proc4_po);

  if (gfl & F_OPT_MODE_RAWDUMP)
    {
#ifdef HAVE_ZLIB_H
      if ((g_act_1.flags & F_GH_IO_GZIP) && g_act_1.gz_fh1)
	{
	  gzflush(g_act_1.gz_fh1, Z_FINISH);
	}
#endif
      fflush (stdout);
    }

  // g_setjmp(0, "dirlog_print_stats(2)", NULL, NULL);

  if (!(g_act_1.flags & F_GH_ISONLINE) && (gfl0 & F_OPT_STATS))
    {
      fprintf (
	  stderr,
	  "STATS: %s: processed %llu/%llu records\n",
	  file,
	  (unsigned long long int) c,
	  !g_act_1.buffer.count ?
	      (unsigned long long int) c : g_act_1.buffer.count);
    }

  if (0 == c && 0 == EXITVAL)
    {
      EXITVAL = 2;
    }

  r_end:

  free (buffer);

  rc_end:

  g_close (&g_act_1);

  return EXITVAL;
}
Ejemplo n.º 14
0
	ordered(BeginIt first, EndIt last) : container(std::move(first), std::move(last)), compare_predicate() {
		do_sort();
	}
Ejemplo n.º 15
0
static int
valsort_response( Operation *op, SlapReply *rs )
{
	slap_overinst *on;
	valsort_info *vi;
	Attribute *a;

	/* If this is not a search response, or it is a syncrepl response,
	 * or the valsort control wants raw results, pass thru unmodified.
	 */
	if ( rs->sr_type != REP_SEARCH ||
		( _SCM(op->o_sync) > SLAP_CONTROL_IGNORED ) ||
		( op->o_ctrlflag[valsort_cid] & SLAP_CONTROL_DATA0))
		return SLAP_CB_CONTINUE;
		
	on = (slap_overinst *) op->o_bd->bd_info;
	vi = on->on_bi.bi_private;

	/* And we must have something configured */
	if ( !vi ) return SLAP_CB_CONTINUE;

	/* Find a rule whose baseDN matches this entry */
	for (; vi; vi = vi->vi_next ) {
		int i, n;

		if ( !dnIsSuffix( &rs->sr_entry->e_nname, &vi->vi_dn ))
			continue;

		/* Find attr that this rule affects */
		a = attr_find( rs->sr_entry->e_attrs, vi->vi_ad );
		if ( !a ) continue;

		if (( rs->sr_flags & ( REP_ENTRY_MODIFIABLE|REP_ENTRY_MUSTBEFREED ) ) !=
			( REP_ENTRY_MODIFIABLE|REP_ENTRY_MUSTBEFREED ) )
		{
			Entry *e;

			e = entry_dup( rs->sr_entry );
			if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
				overlay_entry_release_ov( op, rs->sr_entry, 0, on );
				rs->sr_flags &= ~REP_ENTRY_MUSTRELEASE;
			} else if ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) {
				entry_free( rs->sr_entry );
			}
			rs->sr_entry = e;
			rs->sr_flags |= REP_ENTRY_MODIFIABLE|REP_ENTRY_MUSTBEFREED;
			a = attr_find( rs->sr_entry->e_attrs, vi->vi_ad );
		}

		n = a->a_numvals;
		if ( vi->vi_sort & VALSORT_WEIGHTED ) {
			int j, gotnvals;
			long *index = op->o_tmpalloc( n * sizeof(long), op->o_tmpmemctx );

			gotnvals = (a->a_vals != a->a_nvals );

			for (i=0; i<n; i++) {
				char *ptr = ber_bvchr( &a->a_nvals[i], '{' );
				char *end = NULL;
				if ( !ptr ) {
					Debug(LDAP_DEBUG_TRACE, "weights missing from attr %s "
						"in entry %s\n", vi->vi_ad->ad_cname.bv_val,
						rs->sr_entry->e_name.bv_val, 0 );
					break;
				}
				index[i] = strtol( ptr+1, &end, 0 );
				if ( *end != '}' ) {
					Debug(LDAP_DEBUG_TRACE, "weights misformatted "
						"in entry %s\n", 
						rs->sr_entry->e_name.bv_val, 0, 0 );
					break;
				}
				/* Strip out weights */
				ptr = a->a_nvals[i].bv_val;
				end++;
				for (;*end;)
					*ptr++ = *end++;
				*ptr = '\0';
				a->a_nvals[i].bv_len = ptr - a->a_nvals[i].bv_val;

				if ( a->a_vals != a->a_nvals ) {
					ptr = a->a_vals[i].bv_val;
					end = ber_bvchr( &a->a_vals[i], '}' );
					assert( end != NULL );
					end++;
					for (;*end;)
						*ptr++ = *end++;
					*ptr = '\0';
					a->a_vals[i].bv_len = ptr - a->a_vals[i].bv_val;
				}
			}
			/* An attr was missing weights here, ignore it */
			if ( i<n ) {
				op->o_tmpfree( index, op->o_tmpmemctx );
				continue;
			}
			/* Insertion sort */
			for ( i=1; i<n; i++) {
				long idx = index[i];
				struct berval tmp = a->a_vals[i], ntmp;
				if ( gotnvals ) ntmp = a->a_nvals[i];
				j = i;
				while (( j>0 ) && (index[j-1] > idx )) {
					index[j] = index[j-1];
					a->a_vals[j] = a->a_vals[j-1];
					if ( gotnvals ) a->a_nvals[j] = a->a_nvals[j-1];
					j--;
				}
				index[j] = idx;
				a->a_vals[j] = tmp;
				if ( gotnvals ) a->a_nvals[j] = ntmp;
			}
			/* Check for secondary sort */
			if ( vi->vi_sort ^ VALSORT_WEIGHTED ) {
				for ( i=0; i<n;) {
					for (j=i+1; j<n; j++) {
						if (index[i] != index[j])
							break;
					}
					if( j-i > 1 )
						do_sort( op, a, i, j-i, vi->vi_sort );
					i = j;
				}
			}
			op->o_tmpfree( index, op->o_tmpmemctx );
		} else {
			do_sort( op, a, 0, n, vi->vi_sort );
		}
	}
	return SLAP_CB_CONTINUE;
}
Ejemplo n.º 16
0
	ordered(BeginIt first, EndIt last, P&& p) : container(std::move(first), std::move(last)), compare_predicate(std::forward<P>(p)) {
		do_sort();
	}
Ejemplo n.º 17
0
Archivo: dir.c Proyecto: Chainie/mc
int
do_reload_dir (const vfs_path_t * vpath, dir_list * list, sortfn * sort, int count,
               gboolean lc_reverse, gboolean lc_case_sensitive, gboolean exec_ff, const char *fltr)
{
    DIR *dirp;
    struct dirent *dp;
    int next_free = 0;
    int i, status, link_to_dir, stale_link;
    struct stat st;
    int marked_cnt;
    GHashTable *marked_files;
    const char *tmp_path;

    dirp = mc_opendir (vpath);
    if (dirp == NULL)
    {
        message (D_ERROR, MSG_ERROR, _("Cannot read directory contents"));
        clean_dir (list, count);
        return set_zero_dir (list) ? 1 : 0;
    }

    tree_store_start_check (vpath);

    marked_files = g_hash_table_new (g_str_hash, g_str_equal);
    alloc_dir_copy (list->size);
    for (marked_cnt = i = 0; i < count; i++)
    {
        dir_copy.list[i].fnamelen = list->list[i].fnamelen;
        dir_copy.list[i].fname = list->list[i].fname;
        dir_copy.list[i].f.marked = list->list[i].f.marked;
        dir_copy.list[i].f.dir_size_computed = list->list[i].f.dir_size_computed;
        dir_copy.list[i].f.link_to_dir = list->list[i].f.link_to_dir;
        dir_copy.list[i].f.stale_link = list->list[i].f.stale_link;
        dir_copy.list[i].sort_key = NULL;
        dir_copy.list[i].second_sort_key = NULL;
        if (list->list[i].f.marked)
        {
            g_hash_table_insert (marked_files, dir_copy.list[i].fname, &dir_copy.list[i]);
            marked_cnt++;
        }
    }

    /* Add ".." except to the root directory. The ".." entry
       (if any) must be the first in the list. */
    tmp_path = vfs_path_get_by_index (vpath, 0)->path;
    if (!
        (vfs_path_elements_count (vpath) == 1 && (tmp_path[0] == PATH_SEP)
         && (tmp_path[1] == '\0')))
    {
        if (!set_zero_dir (list))
        {
            clean_dir (list, count);
            clean_dir (&dir_copy, count);
            return next_free;
        }

        if (get_dotdot_dir_stat (vpath, &st))
            list->list[next_free].st = st;

        next_free++;
    }

    while ((dp = mc_readdir (dirp)))
    {
        status = handle_dirent (list, fltr, dp, &st, next_free, &link_to_dir, &stale_link);
        if (status == 0)
            continue;
        if (status == -1)
        {
            mc_closedir (dirp);
            /* Norbert (Feb 12, 1997):
               Just in case someone finds this memory leak:
               -1 means big trouble (at the moment no memory left),
               I don't bother with further cleanup because if one gets to
               this point he will have more problems than a few memory
               leaks and because one 'clean_dir' would not be enough (and
               because I don't want to spent the time to make it working,
               IMHO it's not worthwhile).
               clean_dir (&dir_copy, count);
             */
            tree_store_end_check ();
            g_hash_table_destroy (marked_files);
            return next_free;
        }

        list->list[next_free].f.marked = 0;

        /*
         * If we have marked files in the copy, scan through the copy
         * to find matching file.  Decrease number of remaining marks if
         * we copied one.
         */
        if (marked_cnt > 0)
        {
            if ((g_hash_table_lookup (marked_files, dp->d_name)))
            {
                list->list[next_free].f.marked = 1;
                marked_cnt--;
            }
        }

        list->list[next_free].fnamelen = NLENGTH (dp);
        list->list[next_free].fname = g_strndup (dp->d_name, list->list[next_free].fnamelen);
        list->list[next_free].f.link_to_dir = link_to_dir;
        list->list[next_free].f.stale_link = stale_link;
        list->list[next_free].f.dir_size_computed = 0;
        list->list[next_free].st = st;
        list->list[next_free].sort_key = NULL;
        list->list[next_free].second_sort_key = NULL;
        next_free++;
        if (!(next_free % 16))
            rotate_dash ();
    }
    mc_closedir (dirp);
    tree_store_end_check ();
    g_hash_table_destroy (marked_files);
    if (next_free)
    {
        do_sort (list, sort, next_free - 1, lc_reverse, lc_case_sensitive, exec_ff);
    }
    clean_dir (&dir_copy, count);
    return next_free;
}
Ejemplo n.º 18
0
int main( )
{
    srand( (unsigned)time(NULL) );              //srand로 초기화
  	
    int randomNum[nMAX];              		 //생성된 난수를 저장할 변수
    int bCheckExistOfNum[nMAX] = {0};    	 //생성된 난수가 중복인지 체크할 변수(인덱스)
    int i,j;
    
  	float gap;
  	float gap_result_list[6];
  	float max_gap = 0;
   	time_t startTime=0, endTime=0;
    //번호 생성 부분 
    char cmd[10], sorting_name[20];
    int sort_code = 0;
   	
   	while(1){
        printf("1. 삽입정렬\n");
        printf("2. 선택정렬\n");
        printf("3. 합병정렬\n");
        printf("4. 힙 정렬\n");
        printf("q : 종료\n");
        printf("무엇을 하시겠습니까? : ");
        scanf("%s", cmd);
        // 삽입 정렬의 경우 
        if(!strcmp(cmd,"1")){
            printf("삽입정렬 선택!\n");
            strcpy(sorting_name, "삽입정렬");
            sort_code = 1;
        }
        // 선택 정렬의 경우 
        else if(!strcmp(cmd,"2")){
            printf("선택정렬 선택!\n");
            strcpy(sorting_name, "선택정렬");
            sort_code = 2;
        }
        // 합병 정렬의 경우 
        else if(!strcmp(cmd,"3")){
            printf("합병정렬 선택!\n");
            strcpy(sorting_name, "합병정렬");
            sort_code = 3;
        }
        // 힙 정렬의 경우 
        else if(!strcmp(cmd,"4")){
            printf("힙정렬 선택!\n");
            strcpy(sorting_name, "힙정렬");
            sort_code = 4;
        }
        else if(!strcmp(cmd,"q")) break;			// q를 입력하면 종료 
        else{
            printf("올바른 코드를 입력해주세요\n");
            continue;
        }
        
        // 각각 10000개, 20000개, 30000개, 40000개, 50000개, 60000개인 경우를 실행한다.  
        for(i = 0 ; i< 6; i++){
        	gap_result_list[i] = do_sort(sort_code, randomNum, bCheckExistOfNum, (i+1)*10000);
		}
        
        // 실험 결과를 출력한다. 
        system("cls");			// 커맨드 창 클리어 
        printf("-----------%s 실험 결과--------------\n",sorting_name);
        for(i = 0 ; i < 6 ; i++){
        	printf("%d개 정렬 수행 시간 : %f초\n", (i+1)*10000, gap_result_list[i]);
        }
        printf("---------------------------------------\n");
        
        
    }
   	
    return 0;
}
Ejemplo n.º 19
0
Archivo: dir.c Proyecto: Chainie/mc
int
do_load_dir (const vfs_path_t * vpath, dir_list * list, sortfn * sort, gboolean lc_reverse,
             gboolean lc_case_sensitive, gboolean exec_ff, const char *fltr)
{
    DIR *dirp;
    struct dirent *dp;
    int status, link_to_dir, stale_link;
    int next_free = 0;
    struct stat st;
    char *path;

    /* ".." (if any) must be the first entry in the list */
    if (!set_zero_dir (list))
        return next_free;

    if (get_dotdot_dir_stat (vpath, &st))
        list->list[next_free].st = st;
    next_free++;

    dirp = mc_opendir (vpath);
    if (dirp == NULL)
    {
        message (D_ERROR, MSG_ERROR, _("Cannot read directory contents"));
        return next_free;
    }

    tree_store_start_check (vpath);

    /* Do not add a ".." entry to the root directory */
    path = vfs_path_to_str (vpath);
    if ((path[0] == PATH_SEP) && (path[1] == '\0'))
        next_free--;
    g_free (path);

    while ((dp = mc_readdir (dirp)) != NULL)
    {
        status = handle_dirent (list, fltr, dp, &st, next_free, &link_to_dir, &stale_link);
        if (status == 0)
            continue;
        if (status == -1)
            goto ret;

        list->list[next_free].fnamelen = NLENGTH (dp);
        list->list[next_free].fname = g_strndup (dp->d_name, list->list[next_free].fnamelen);
        list->list[next_free].f.marked = 0;
        list->list[next_free].f.link_to_dir = link_to_dir;
        list->list[next_free].f.stale_link = stale_link;
        list->list[next_free].f.dir_size_computed = 0;
        list->list[next_free].st = st;
        list->list[next_free].sort_key = NULL;
        list->list[next_free].second_sort_key = NULL;
        next_free++;

        if ((next_free & 31) == 0)
            rotate_dash ();
    }

    if (next_free != 0)
        do_sort (list, sort, next_free - 1, lc_reverse, lc_case_sensitive, exec_ff);

  ret:
    mc_closedir (dirp);
    tree_store_end_check ();
    return next_free;
}
Ejemplo n.º 20
0
int main(int argc, char **argv) {

        if (argc != 4) {
                fprintf(stderr, "Usage: %s <vector size in K> <sort size in K> <merge size in K>\n", argv[0]);
                return 1;
        }

#if _EXTRAE_
	Extrae_init();
#endif
	N = atol(argv[1]) * 1024L;
	MIN_SORT_SIZE = atol(argv[2]) * 1024L;
        MIN_MERGE_SIZE = atol(argv[3]) * 1024L;

	T *data = malloc(N*sizeof(T));
	T *tmp = malloc(N*sizeof(T));

#if _TAREADOR_
	tareador_ON();
#endif

#if _EXTRAE_
	Extrae_event(PROGRAM, INITIALIZE);
#else
	double init_time = omp_get_wtime();
#endif
	initialize(N, data);
	clear(N, tmp);
#if _EXTRAE_
	Extrae_event(PROGRAM, END);
#else
	init_time = omp_get_wtime() - init_time;
    	fprintf(stdout, "Initialization time in seconds = %g\n", init_time);
#endif

    	fprintf(stdout, "Multisort execution time using randomly generated data = ");
   	do_sort(N, data, tmp); //sort randomly generated data

#if _TAREADOR_
	tareador_OFF();
#endif

#if _EXTRAE_
	Extrae_event(PROGRAM, INITIALIZE);
	Extrae_event(PROGRAM, END);
#endif
    	fprintf(stdout, "Multisort execution time using already sorted data = ");
   	do_sort(N, data, tmp); // sort already sorted

#if _EXTRAE_
	Extrae_event(PROGRAM, INITIALIZE);
#endif
   	for (int i=0; i<N/2; i++) { // Reverse order
      		double tmp =data[N-1-i];
      		data[N-1-i] = data[i];
      		data[i]=tmp;
   	}
#if _EXTRAE_
	Extrae_event(PROGRAM, END);
#endif
    	fprintf(stdout, "Multisort execution time using reverse order data = ");
   	do_sort(N, data, tmp); //sort data in inverted order

#if _EXTRAE_
	Extrae_fini();
#endif
    	fprintf(stdout, "Multisort program finished\n");
	return 0;
}