QSort -> QuickSort

This commit is contained in:
xmm15 2020-02-15 18:35:54 -06:00
parent 143c1830e0
commit b482ea4f01
25 changed files with 383 additions and 370 deletions

Binary file not shown.

View File

@ -94,7 +94,7 @@ public U0 StrFileWrite(U8 *name,CHashTable *table,Bool no_nums=FALSE)
tmph=tmph->next;
}
}
QSortI64(a,count,&StrEntriesCompare);
QuickSortI64(a,count,&StrEntriesCompare);
for (i=0;i<count;i++) {
tmph=a[i];
if (tmph->user_data1&15!=color) {

View File

@ -371,7 +371,7 @@ U0 DrawIt(CTask *task,CDC *dc)
}
}
QSortI64(o_sort,OBJS_NUM,&ObjCompare);
QuickSortI64(o_sort,OBJS_NUM,&ObjCompare);
for (i=0;i<OBJS_NUM;i++)
DrawObj(dc,o_sort[i],tt);
tt=(game_t_end-tS)/60;

Binary file not shown.

View File

@ -535,7 +535,7 @@ R12 and R13 as non-pointer register variables, such as index variables i,j,k.
~(REGG_LOCAL_VARS|REGG_LOCAL_NON_PTR_VARS)|used_reg_mask;
if (!Bt(&cc->opts,OPTf_NO_REG_VAR) &&
!(cc->flags & CCF_NO_REG_OPT)) {
QSort(mv,member_count,sizeof(COptMemberVar),&OptMVCompare);
QuickSort(mv,member_count,sizeof(COptMemberVar),&OptMVCompare);
while (member_count && !mv[member_count-1].score)
member_count--;
j=0;

View File

@ -238,8 +238,8 @@ U0 UAsmHashLoad()
tmph=tmph->next;
}
}
QSortI64(uasm.table_16_32,uasm.table_16_32_entries,&InstEntriesCompare);
QSortI64(uasm.table_64 ,uasm.table_64_entries ,&InstEntriesCompare);
QuickSortI64(uasm.table_16_32,uasm.table_16_32_entries,&InstEntriesCompare);
QuickSortI64(uasm.table_64 ,uasm.table_64_entries ,&InstEntriesCompare);
}
U0 Ui(U8 *buf,U8 **_rip,I64 seg_size=64,I64 *_jmp_dst=NULL,Bool just_ins=FALSE)

Binary file not shown.

View File

@ -17,9 +17,9 @@ I64 Compare(I32 *e1,I32 *e2)
return *e1-*e2;
}
U0 QSortU32(I32 *base,I64 num)
U0 QuickSortU32(I32 *base,I64 num)
{//By customizing, we dramatically improve it!
//Cut and paste from $LK,"QSortI64",A="MN:QSortI64"$().
//Cut and paste from $LK,"QuickSortI64",A="MN:QuickSortI64"$().
I64 i;
I32 *less,*greater,pivot;
if (num>1) {
@ -50,11 +50,11 @@ U0 QSortU32(I32 *base,I64 num)
} else //All equ
break;
} else if (i<num/2) {
QSortU32(base,i);
QuickSortU32(base,i);
num-=i;
base=greater;
} else {
QSortU32(greater,num-i);
QuickSortU32(greater,num-i);
num=i;
}
} while (num>1);
@ -64,7 +64,7 @@ U0 QSortU32(I32 *base,I64 num)
U0 MPSort(I64 dummy=0)
{
no_warn dummy;
QSortU32(b[Gs->num],bn[Gs->num]);
QuickSortU32(b[Gs->num],bn[Gs->num]);
LBtr(&mp_not_done_flags,Gs->num);
}
@ -79,17 +79,17 @@ U0 MPRadixSortDemo(I64 dummy=0)
arg2=MAlloc(NUM*sizeof(I32));
"$$GREEN$$QSort$$FG$$\n";
"$$GREEN$$QuickSort$$FG$$\n";
t0=tS;
MemCpy(arg2,arg1,sizeof(I32)*NUM);
QSort(arg2,NUM,sizeof(I32),&Compare);
QuickSort(arg2,NUM,sizeof(I32),&Compare);
"Time:%9.6f\n",tS-t0;
D(arg2+NUM/4);
"$$GREEN$$QSortU32$$FG$$\n";
"$$GREEN$$QuickSortU32$$FG$$\n";
t0=tS;
MemCpy(arg2,arg1,sizeof(I32)*NUM);
QSortU32(arg2,NUM);
QuickSortU32(arg2,NUM);
"Time:%9.6f\n",tS-t0;
D(arg2+NUM/4);
@ -103,7 +103,7 @@ U0 MPRadixSortDemo(I64 dummy=0)
if (my_mp_count<2) throw('MultCore');
"$$GREEN$$MP Radix QSortU32$$FG$$\n";
"$$GREEN$$MP Radix QuickSortU32$$FG$$\n";
t0=tS;
k1=32-Bsr(my_mp_count);
k2=my_mp_count/2;
@ -133,10 +133,10 @@ U0 MPRadixSortDemo(I64 dummy=0)
MPRadixSortDemo;
/*$HL,0$ Results on 8 Cores 3.397GHz Core i7:
$FG,2$QSort$FG$
$FG,2$QuickSort$FG$
Time: 0.759998
$FG,2$QSortU32$FG$
$FG,2$QuickSortU32$FG$
Time: 0.093684
$FG,2$MP Radix QSortU32$FG$
$FG,2$MP Radix QuickSortU32$FG$
Time: 0.045450
$HL,1$*/

View File

@ -32,7 +32,7 @@ U0 F64FileSortTXT(U8 *in_name,U8 *out_name)
a[i++]=cc->cur_f64;
CompCtrlDel(cc);
QSortI64(a,n,&Compare); //Sort 64-bit sized values
QuickSortI64(a,n,&Compare); //Sort 64-bit sized values
//Save
doc=DocNew(out_name);
@ -52,7 +52,7 @@ U0 F64FileSortDAT(U8 *in_name,U8 *out_name)
{//$LK,"File/CFile",A="HI:File/CFile"$, $LK,"::/Demo/Disk/DataBase.HC"$
I64 size;
F64 *a=FileRead(in_name,&size);
QSortI64(a,size/sizeof(F64),&Compare); //Sort 64-bit sized values
QuickSortI64(a,size/sizeof(F64),&Compare); //Sort 64-bit sized values
FileWrite(out_name,a,size);
Free(a);
}

View File

@ -135,7 +135,7 @@ U0 FancyWordSearch()
CollectWords(-1,-1,&n);
CollectWords(1,-1,&n);
CollectWords(-1,1,&n);
QSortI64(word_ptrs,n,&WordsCompare);
QuickSortI64(word_ptrs,n,&WordsCompare);
DisplayWords(n);
'\n';
}

View File

@ -67,7 +67,7 @@ $FG$I didn't like that, so I made parentheses optional on calls with no args and
>$FG,2$Dir;$FG$
The syntax change created an ambiguity when specifying function addresses, like for calling $LK,"QSort",A="MN:QSort"$(). To resolve it, I made a '$FG,2$&$FG$' required in front of function names when specifying an address of a function, which is better anyway.
The syntax change created an ambiguity when specifying function addresses, like for calling $LK,"QuickSort",A="MN:QuickSort"$(). To resolve it, I made a '$FG,2$&$FG$' required in front of function names when specifying an address of a function, which is better anyway.
Once I was no longer using standard C/C++ syntax, I decided to change everything I didn't like and call it $LK,"HolyC",A="FI:::/Doc/HolyC.DD"$. Here are the new $LK,"operator precedence",A="FF:::/Doc/HolyC.DD,operator precedence"$ rules. It's Biblical! See $LK,"Luke,5:37",A="BF:Luke,5:37"$.

13
src/Home/MakeHome.HC Executable file
View File

@ -0,0 +1,13 @@
Cd(__DIR__);;
//If these are not present in /Home, it uses the version in the root dir. You
//can make your own, modified, version of these files in your /Home directory.
#include "~/HomeLocalize"
#include "/Zenith/Boot/MakeBoot"
#include "/Zenith/Utils/MakeUtils"
#include "~/HomeWrappers"
MapFileLoad("::/Kernel/Kernel");
MapFileLoad("::/Compiler/Compiler");
#include "~/HomeKeyPlugIns"
#include "~/HomeSys"
Cd("..");;

Binary file not shown.

View File

@ -102,10 +102,10 @@ U0 DirFilesSort(CDirEntry **_tmpde,I64 key)
}
switch [key] {
case SK_NAME:
QSortI64(sort_buf,count,&DirEntryCompareName);
QuickSortI64(sort_buf,count,&DirEntryCompareName);
break;
case SK_CLUS:
QSortI64(sort_buf,count,&DirEntryCompareClus);
QuickSortI64(sort_buf,count,&DirEntryCompareClus);
break;
}
tmpde=sort_buf[0];

File diff suppressed because one or more lines are too long

View File

@ -48,7 +48,7 @@
#include "KeyDev"
#include "KExcept"
#include "SerialDev/MakeSerialDev"
#include "QSort"
#include "QuickSort"
#include "KTask"
#include "Job"
#include "PCIBIOS"

View File

@ -599,9 +599,9 @@ public extern I64 ScanMessage(I64 *_arg1=NULL,I64 *_arg2=NULL,
public extern I64 EndianI64(I64 d);
public extern U16 EndianU16(U16 d);
public extern U32 EndianU32(U32 d);
public extern U0 QSort(U8 *base,I64 num, I64 width,
public extern U0 QuickSort(U8 *base,I64 num, I64 width,
I64 (*fp_compare)(U8 *e1,U8 *e2));
public extern U0 QSortI64(I64 *base,I64 num,
public extern U0 QuickSortI64(I64 *base,I64 num,
I64 (*fp_compare)(I64 e1,I64 e2));
public extern F64 sys_os_version;

View File

@ -1,4 +1,4 @@
U0 QSortI64(I64 *base,I64 num, I64 (*fp_compare)(I64 e1,I64 e2))
U0 QuickSortI64(I64 *base,I64 num, I64 (*fp_compare)(I64 e1,I64 e2))
{/*Quick Sort for width==8.
fp_compare() passes by value instead of ref.
@ -22,14 +22,14 @@ Maybe, look at $LK,"::/Demo/MultiCore/MPRadix.HC"$.
} while (left<=right);
i=right+1-base;
if (1<i<num)
QSortI64(base,i,fp_compare);
QuickSortI64(base,i,fp_compare);
i=base+num-left;
if (1<i<num)
QSortI64(left,i,fp_compare);
QuickSortI64(left,i,fp_compare);
}
}
U0 QSort2a(U8 **base,I64 num,I64 (*fp_compare)(U8 **_e1,U8 **_e2))
U0 QuickSort2a(U8 **base,I64 num,I64 (*fp_compare)(U8 **_e1,U8 **_e2))
{//Not public.For case of width==size(U8 *)==8.
//fp_compare() passes by ref.
I64 i;
@ -47,12 +47,12 @@ U0 QSort2a(U8 **base,I64 num,I64 (*fp_compare)(U8 **_e1,U8 **_e2))
} while (left<=right);
i=right+1-base;
if (1<i<num)
QSort2a(base,i,fp_compare);
QuickSort2a(base,i,fp_compare);
i=base+num-left;
if (1<i<num)
QSort2a(left,i,fp_compare);
QuickSort2a(left,i,fp_compare);
}
U0 QSort2b(U8 *base,I64 num, I64 width,
U0 QuickSort2b(U8 *base,I64 num, I64 width,
I64 (*fp_compare)(U8 *e1,U8 *e2),U8 *tmp)
{//Not public
I64 i;
@ -77,12 +77,12 @@ U0 QSort2b(U8 *base,I64 num, I64 width,
} while (left<=right);
i=1+(right-base)/width;
if (1<i<num)
QSort2b(base,i,width,fp_compare,tmp);
QuickSort2b(base,i,width,fp_compare,tmp);
i=num+(base-left)/width;
if (1<i<num)
QSort2b(left,i,width,fp_compare,tmp);
QuickSort2b(left,i,width,fp_compare,tmp);
}
U0 QSort(U8 *base,I64 num, I64 width, I64 (*fp_compare)(U8 *e1,U8 *e2))
U0 QuickSort(U8 *base,I64 num, I64 width, I64 (*fp_compare)(U8 *e1,U8 *e2))
{/*Quick Sort: fp_compare() passes by ref.
For ascending strings: return StrCmp(*e1,*e2);
@ -94,10 +94,10 @@ Maybe, look at $LK,"::/Demo/MultiCore/MPRadix.HC"$.
U8 *tmp;
if (width && num>1) {
if (width==sizeof(U8 *)) //assign instead of MemCpy for width 8
QSort2a(base,num,fp_compare);
QuickSort2a(base,num,fp_compare);
else {
tmp=MAlloc(width*2);
QSort2b(base,num,width,fp_compare,tmp);
QuickSort2b(base,num,width,fp_compare,tmp);
Free(tmp);
}
}

Binary file not shown.

View File

@ -130,7 +130,7 @@ U8 *ACDSortWords(U8 *start,I64 size,I64 word_count)
ptr+=StrLen(ptr)+3;
}
"Sorting...\n"; Sleep(100);
QSortI64(ptr_array,word_count,&ACDCompareWords);
QuickSortI64(ptr_array,word_count,&ACDCompareWords);
"Done...\n"; Sleep(100);
ptr=out_start;

View File

@ -134,7 +134,7 @@ U0 KeyMapFamily(CTask *task,I64 scf,Bool no_shift,Bool shift)
ptr+=256;
count+=256;
}
QSortI64(entries,count,&KMCompare);
QuickSortI64(entries,count,&KMCompare);
for (i=0;i<count;i++)
if (entries[i]) {
"%s",entries[i];

View File

@ -275,7 +275,7 @@ public Bool Diff(U8 *dst_file,U8 *src_file,I64 *_df_flags=NULL)
doc_e=doc_e->next;
}
doc_unsorted1[i]=doc1;
QSortI64(doc_sorted1,count1,&DiffEntriesCompare);
QuickSortI64(doc_sorted1,count1,&DiffEntriesCompare);
doc_sorted2=MAlloc(count2*sizeof(CDocEntry *));
doc_unsorted2=MAlloc((count2+1)*sizeof(CDocEntry *));
@ -289,7 +289,7 @@ public Bool Diff(U8 *dst_file,U8 *src_file,I64 *_df_flags=NULL)
doc_e=doc_e->next;
}
doc_unsorted2[i]=doc2;
QSortI64(doc_sorted2,count2,&DiffEntriesCompare);
QuickSortI64(doc_sorted2,count2,&DiffEntriesCompare);
res=DiffSub(doc1,&df_flags,0,count1,0,count2,count1,count2,
doc_sorted1,doc_sorted2,doc_unsorted1,doc_unsorted2);
@ -342,7 +342,7 @@ public U0 ZipRep(U8 *files_find_mask="/*",U8 *fu_flags=NULL,
Free(arc);
tmpde=tmpde->next;
}
QSortI64(sort_buf,count,&ZRepCompare);
QuickSortI64(sort_buf,count,&ZRepCompare);
for (i=0;i<count;i++) {
"%4.1f%% %04X ",sort_buf[i]->user_data,sort_buf[i]->size;
PutFileLink(sort_buf[i]->full_name);

View File

@ -66,7 +66,7 @@ public U0 ProfRep(I64 filter_count=1,Bool leave_it=OFF)
else {
if (!(total_time=pf_jiffy_end-pf_jiffy_start))
total_time=1;
QSortI64(pf_array,pf_buf_in_ptr,&ProfCompare);
QuickSortI64(pf_array,pf_buf_in_ptr,&ProfCompare);
*last_buf=0;
for (i=0;i<pf_buf_in_ptr;i+=hits) {
rip=pf_array[i];

View File

@ -39,7 +39,7 @@ public I64 Sort(U8 *_in_name,U8 *_out_name=NULL,
DocEntryDel(doc,doc_e);
doc_e=doc_e1;
}
QSort(a,count/entry_lines,entry_lines*sizeof(CDocEntry *),&DEPtrCompare);
QuickSort(a,count/entry_lines,entry_lines*sizeof(CDocEntry *),&DEPtrCompare);
res=0;
st=NULL;

View File

@ -228,11 +228,11 @@ U8 *idx=NULL,CDoc *doc=NULL)
}
if (map)
QSort(list,count,sizeof(CWho),&HashEntriesCompare2);
QuickSort(list,count,sizeof(CWho),&HashEntriesCompare2);
else if (idx)
QSort(list,count,sizeof(CWho),&HashEntriesCompare3);
QuickSort(list,count,sizeof(CWho),&HashEntriesCompare3);
else
QSort(list,count,sizeof(CWho),&HashEntriesCompare);
QuickSort(list,count,sizeof(CWho),&HashEntriesCompare);
if (idx) {
progress1_max=count;