6 wchar_t * makeSortString(
const char * in) {
13 struct custom_sort_data {
19 template<
int direction>
21 int ret = direction * StrCmpLogicalW(elem1.text,elem2.text);
27 template<
int direction>
29 return custom_sort_compare<direction>(*
reinterpret_cast<const custom_sort_data*
>(v1),*reinterpret_cast<const custom_sort_data*>(v2));
58 m_API->seed((
unsigned)__rdtsc());
67 if (param_count == 1) {
70 val = m_API->genrand(mod);
75 val = m_API->genrand(0xFFFFFFFF);
91 ~tfthread() {waitTillDone();}
96 TRACK_CALL_TEXT(
"metadb_handle sort helper thread");
103 const t_size total = m_items.get_size();
105 const t_size index = (*m_walk)++;
106 if (index >= total)
break;
107 m_out[index].index = index;
108 m_items[index]->format_title(hookPtr,temp,m_script,0);
109 m_out[index].text = makeSortString(temp);
115 custom_sort_data *
const m_out;
116 titleformat_object::ptr
const m_script;
131 PFC_ASSERT( threads.
get_size() > 0 );
133 threads[walk].new_t(&counter,p_list,data.
get_ptr(),p_script,p_hook);
135 for(
t_size walk = 1; walk < threads.
get_size(); ++walk) threads[walk]->start();
136 threads[0]->threadProc();
137 for(
t_size walk = 1; walk < threads.
get_size(); ++walk) threads[walk]->waitTillDone();
141 pfc::sort_t(data, p_direction > 0 ? custom_sort_compare<1> : custom_sort_compare<-1>,count);
147 for(
t_size n=0;n<count;n++)
149 order[n]=data[n].index;
150 delete[] data[n].text;
178 if (!api->get_relative_path(item,temp)) temp =
"";
180 data[n].text = makeSortString(temp);
189 order[n]=data[n].index;
190 delete[] data[n].text;
207 for(n=0;n<count-1;n++)
212 mask.
set(order[n+1],
true);
226 bool b_found =
false;
228 for(n=0;n<count-1;n++)
241 for(n=0;n<count-1;n++)
267 if (p_list.
bsearch_t(pfc::compare_t<metadb_handle_ptr,metadb_handle_ptr>,val,blah))
return blah;
278 found_1 = found_2 = 0;
280 while(ptr_1 < count_1 || ptr_2 < count_2)
282 while(ptr_1 < count_1 && (ptr_2 == count_2 || p_list_1[ptr_1] < p_list_2[ptr_2]))
285 t_size ptr_1_new = ptr_1 + 1;
286 while(ptr_1_new < count_1 && p_list_1[ptr_1_new] == p_list_1[ptr_1]) ptr_1_new++;
289 while(ptr_2 < count_2 && (ptr_1 == count_1 || p_list_2[ptr_2] < p_list_1[ptr_1]))
292 t_size ptr_2_new = ptr_2 + 1;
293 while(ptr_2_new < count_2 && p_list_2[ptr_2_new] == p_list_2[ptr_2]) ptr_2_new++;
296 while(ptr_1 < count_1 && ptr_2 < count_2 && p_list_1[ptr_1] == p_list_2[ptr_2]) {ptr_1++; ptr_2++;}
303 if (found_1 > 0 || found_2 > 0)
305 found_1 = found_2 = 0;
308 while(ptr_1 < count_1 || ptr_2 < count_2)
310 while(ptr_1 < count_1 && (ptr_2 == count_2 || p_list_1[ptr_1] < p_list_2[ptr_2]))
312 p_list_1_specific[found_1++] = p_list_1[ptr_1];
313 t_size ptr_1_new = ptr_1 + 1;
314 while(ptr_1_new < count_1 && p_list_1[ptr_1_new] == p_list_1[ptr_1]) ptr_1_new++;
317 while(ptr_2 < count_2 && (ptr_1 == count_1 || p_list_2[ptr_2] < p_list_1[ptr_1]))
319 p_list_2_specific[found_2++] = p_list_2[ptr_2];
320 t_size ptr_2_new = ptr_2 + 1;
321 while(ptr_2_new < count_2 && p_list_2[ptr_2_new] == p_list_2[ptr_2]) ptr_2_new++;
324 while(ptr_1 < count_1 && ptr_2 < count_2 && p_list_1[ptr_1] == p_list_2[ptr_2]) {ptr_1++; ptr_2++;}
336 double temp = p_list.
get_item(n)->get_length();
337 if (temp > 0) ret += temp;
358 beenHere.
add_ex( h->get_path(), isNew);
372 foundUnknown =
false;
393 if (total == 0)
return false;
394 const char * path = list[0]->get_path();
395 for(
t_size walk = 1; walk < total; ++walk) {
virtual void sort(sort_callback &p_callback)=0
int sgn_t(const T &p_val)
const t_item * get_ptr() const
t_size estimate_utf8_to_wide(const char *p_in)
int SHARED_EXPORT stricmp_utf8_ex(const char *p1, t_size len1, const char *p2, t_size len2)
static void g_fill(t_int *p_order, const t_size p_count)
Generic variable bit_array implementation. Needs to be initialized with requested array size before ...
t_size getOptimalWorkerThreadCountEx(t_size taskCountLimit)
void remove_mask(const bit_array &mask)
void set(t_size n, bool val)
static const t_filesize filesize_invalid
Invalid/unknown file size constant. Also see: t_filesize.
t_storage & add_ex(const t_param &p_item, bool &p_isnew)
bool bsearch_t(t_compare p_compare, t_param const &p_param, t_size &p_index) const
void set_count(t_size p_count)
IMPORTANT: all classes derived from thread must call waitTillDone() in their destructor, to avoid object destruction during a virtual function call!
void set_size(t_size p_size)
virtual t_size get_count() const =0
t_size convert_utf8_to_wide_unchecked(wchar_t *p_out, const char *p_in)
This is free and unencumbered software released into the public domain Anyone is free to compile
void reorder(const t_size *p_data)
static void sort_t(t_container &p_data, t_compare p_compare, t_size p_count)
pfc::sized_int_t< sizeof(size_t) >::t_signed t_ssize
t_uint64 t_filesize
Type used for file size related variables.
void sort_t(t_compare p_compare)
t_ret implicit_cast(t_ret val)
void write_int(const GUID &p_inputtype, t_int64 val)
void sort_t(t_compare p_compare)
void sort_get_permutation_t(t_compare p_compare, t_permutation const &p_permutation) const
Helper template used to easily access core services. Usage: static_api_ptr_t<myclass> api; api->doso...
virtual void get_item_ex(T &p_out, t_size n) const =0
string8_t< pfc::alloc_fast_aggressive > string8_fastalloc
T get_item(t_size n) const