Skip to content

Commit

Permalink
new sort func
Browse files Browse the repository at this point in the history
  • Loading branch information
oguyon committed Nov 10, 2023
1 parent 7c6d53d commit cdcebb0
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
77 changes: 77 additions & 0 deletions src/COREMOD_tools/quicksort.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,67 @@ void qs_ushort(
}
}




void qs2(
double * __restrict array,
double * __restrict array1,
unsigned long left,
unsigned long right
)
{
register unsigned long i, j;
double x, y;
double y1;

i = left;
j = right;
x = array[(left + right) / 2];

do
{
while(array[i] < x && i < right)
{
i++;
}
while(x < array[j] && j > left && j > 0)
{
j--;
}

if(i <= j)
{
y = array[i];
array[i] = array[j];
array[j] = y;

y1 = array1[i];
array1[i] = array1[j];
array1[j] = y1;

i++;

if(j > 0)
{
j--;
}
}
}
while(i <= j);

if(left < j)
{
qs2(array, array1, left, j);
}
if(i < right)
{
qs2(array, array1, i, right);
}
}



void qs3(
double * __restrict array,
double * __restrict array1,
Expand Down Expand Up @@ -277,6 +338,12 @@ void qs3(
}
}







void qs3_float(
float * __restrict array,
float * __restrict array1,
Expand Down Expand Up @@ -681,6 +748,7 @@ void qs3ll_double(
}
}


void qs3ulul_double(
double * __restrict array,
unsigned long * __restrict array1,
Expand Down Expand Up @@ -778,6 +846,15 @@ void quick_sort_ushort(
qs_ushort(array, 0, count - 1);
}

void quick_sort2(
double * __restrict array,
double * __restrict array1,
unsigned long count
)
{
qs2(array, array1, 0, count - 1);
}


void quick_sort3(
double * __restrict array,
Expand Down
14 changes: 14 additions & 0 deletions src/COREMOD_tools/quicksort.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ void quick_sort_ushort(
unsigned long count
);

void qs2(
double * __restrict array,
double * __restrict array1,
unsigned long left,
unsigned long right
);


void qs3(
double * __restrict array,
double * __restrict array1,
Expand All @@ -67,6 +75,12 @@ void qs3_double(
unsigned long right
);

void quick_sort2(
double * __restrict array,
double * __restrict array1,
unsigned long count
);

void quick_sort3(
double * __restrict array,
double * __restrict array1,
Expand Down

0 comments on commit cdcebb0

Please sign in to comment.