Fix nondeterministic qsorts
This commit is contained in:
@@ -2717,8 +2717,9 @@ int64_t *tred, *tadd, *tmul, *tround, *tsample, *tpack, *tshake;
|
|||||||
static int cmp_llu(const void *a, const void*b)
|
static int cmp_llu(const void *a, const void*b)
|
||||||
{
|
{
|
||||||
if(*(int64_t *)a < *(int64_t *)b) return -1;
|
if(*(int64_t *)a < *(int64_t *)b) return -1;
|
||||||
if(*(int64_t *)a > *(int64_t *)b) return 1;
|
else if(*(int64_t *)a > *(int64_t *)b) return 1;
|
||||||
return 0;
|
else if ( (uint64_t)a < (uint64_t)b ) return -1;
|
||||||
|
else return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int64_t median(int64_t *l, size_t llen)
|
static int64_t median(int64_t *l, size_t llen)
|
||||||
|
|||||||
@@ -301,6 +301,9 @@ static int _el_buf_cmp(const void *ap, const void *bp) {
|
|||||||
ret = -1;
|
ret = -1;
|
||||||
else if(a->length > b->length)
|
else if(a->length > b->length)
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
else if ( (uint64_t)a < (uint64_t)b ) // jl777 prevent nondeterminism
|
||||||
|
ret = -1;
|
||||||
|
else ret = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -35,8 +35,15 @@ static uint32_t thresholdSubtypes(const CC *cond) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int cmpCostDesc(const void *a, const void *b) {
|
static int cmpCostDesc(const void *a, const void *b)
|
||||||
return (int) ( *(unsigned long*)b - *(unsigned long*)a );
|
{
|
||||||
|
int retval;
|
||||||
|
retval = (int) ( *(unsigned long*)b - *(unsigned long*)a );
|
||||||
|
if ( retval != 0 )
|
||||||
|
return(retval);
|
||||||
|
else if ( (uint64_t)a < (uint64_t)b ) // jl777 prevent nondeterminism
|
||||||
|
return(-1);
|
||||||
|
else return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -79,7 +86,9 @@ static int cmpConditionBin(const void *a, const void *b) {
|
|||||||
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
return r0.encoded < r1.encoded ? -1 : 1;
|
return r0.encoded < r1.encoded ? -1 : 1;
|
||||||
return 0;
|
else if ( (uint64_t)a < (uint64_t)b ) // jl777 prevent nondeterminism
|
||||||
|
return(-1);
|
||||||
|
else return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2524,8 +2524,10 @@ void smooth64(int64_t dest[],int64_t src[],int32_t width,int32_t smoothiters)
|
|||||||
static int cmp_llu(const void *a, const void*b)
|
static int cmp_llu(const void *a, const void*b)
|
||||||
{
|
{
|
||||||
if(*(int64_t *)a < *(int64_t *)b) return -1;
|
if(*(int64_t *)a < *(int64_t *)b) return -1;
|
||||||
if(*(int64_t *)a > *(int64_t *)b) return 1;
|
else if(*(int64_t *)a > *(int64_t *)b) return 1;
|
||||||
return 0;
|
else if ( (uint64_t)a < (uint64_t)b ) // jl777 prevent nondeterminism
|
||||||
|
return(-1);
|
||||||
|
else return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int64_t sort64(int64_t *l, int32_t llen)
|
static int64_t sort64(int64_t *l, int32_t llen)
|
||||||
@@ -2536,13 +2538,15 @@ static int64_t sort64(int64_t *l, int32_t llen)
|
|||||||
static int revcmp_llu(const void *a, const void*b)
|
static int revcmp_llu(const void *a, const void*b)
|
||||||
{
|
{
|
||||||
if(*(int64_t *)a < *(int64_t *)b) return 1;
|
if(*(int64_t *)a < *(int64_t *)b) return 1;
|
||||||
if(*(int64_t *)a > *(int64_t *)b) return -1;
|
else if(*(int64_t *)a > *(int64_t *)b) return -1;
|
||||||
return 0;
|
else if ( (uint64_t)a < (uint64_t)b ) // jl777 prevent nondeterminism
|
||||||
|
return(-1);
|
||||||
|
else return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int64_t revsort64(int64_t *l, int32_t llen)
|
static int64_t revsort64(int64_t *l, int32_t llen)
|
||||||
{
|
{
|
||||||
heapsort(l,llen,sizeof(uint64_t),cmp_llu);
|
qsort(l,llen,sizeof(uint64_t),revcmp_llu);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t komodo_priceave(int64_t *buf,int64_t *correlated,int32_t cskip)
|
int64_t komodo_priceave(int64_t *buf,int64_t *correlated,int32_t cskip)
|
||||||
@@ -2575,7 +2579,7 @@ int64_t komodo_priceave(int64_t *buf,int64_t *correlated,int32_t cskip)
|
|||||||
decayprice = buf[0];
|
decayprice = buf[0];
|
||||||
for (i=0; i<PRICES_DAYWINDOW; i++)
|
for (i=0; i<PRICES_DAYWINDOW; i++)
|
||||||
{
|
{
|
||||||
decayprice = ((decayprice * 9) + (buf[i] * 1)) / 10
|
decayprice = ((decayprice * 9) + (buf[i] * 1)) / 10;
|
||||||
fprintf(stderr,"%.4f ",(double)buf[i]/COIN);
|
fprintf(stderr,"%.4f ",(double)buf[i]/COIN);
|
||||||
}
|
}
|
||||||
fprintf(stderr,"sort half %.4f vs %.4f -> %.4f\n",(double)halfprice/COIN,(double)price/COIN,(double)decayprice/COIN);
|
fprintf(stderr,"sort half %.4f vs %.4f -> %.4f\n",(double)halfprice/COIN,(double)price/COIN,(double)decayprice/COIN);
|
||||||
@@ -2586,7 +2590,7 @@ int64_t komodo_priceave(int64_t *buf,int64_t *correlated,int32_t cskip)
|
|||||||
decayprice = buf[0];
|
decayprice = buf[0];
|
||||||
for (i=0; i<PRICES_DAYWINDOW; i++)
|
for (i=0; i<PRICES_DAYWINDOW; i++)
|
||||||
{
|
{
|
||||||
decayprice = ((decayprice * 9) + (buf[i] * 1)) / 10
|
decayprice = ((decayprice * 9) + (buf[i] * 1)) / 10;
|
||||||
fprintf(stderr,"%.4f ",(double)buf[i]/COIN);
|
fprintf(stderr,"%.4f ",(double)buf[i]/COIN);
|
||||||
}
|
}
|
||||||
fprintf(stderr,"revsort half %.4f vs %.4f -> %.4f\n",(double)halfprice/COIN,(double)price/COIN,(double)decayprice/COIN);
|
fprintf(stderr,"revsort half %.4f vs %.4f -> %.4f\n",(double)halfprice/COIN,(double)price/COIN,(double)decayprice/COIN);
|
||||||
|
|||||||
Reference in New Issue
Block a user