Skip to content

Commit 8e8cbbe

Browse files
committed
clean up merge
1 parent 89e728f commit 8e8cbbe

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

src/bmerge.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -312,27 +312,27 @@ void bmerge_r(int xlowIn, int xuppIn, int ilowIn, int iuppIn, int col, int thisg
312312
if (rollToNearest) { \
313313
/* when rollToNearest you can't limit the distance currently */ \
314314
/* rollToNearest not yet supported for STRSXP (checked up front) */ \
315-
if ( xlow>xlowIn && xupp<xuppIn ) { \
315+
if ( (!lowmax || xlow>xlowIn) && (!uppmax || xupp<xuppIn) ) { \
316316
if ( LOWDIST <= UPPDIST ) \
317317
xlow--; \
318318
else \
319319
xupp++; \
320320
} \
321-
else if (xupp==xuppIn && rollends[1]) \
321+
else if (uppmax && xupp==xuppIn && rollends[1]) \
322322
xlow--; \
323-
else if (xlow==xlowIn && rollends[0]) \
323+
else if (lowmax && xlow==xlowIn && rollends[0]) \
324324
xupp++; \
325325
} else { \
326326
/* Regular roll=TRUE|+ve|-ve */ \
327327
/* Rprintf("xlow=%d xlowIn=%d xupp=%d xuppIn=%d lowmax=%d uppmax=%d ilow=%d iupp=%d\n", xlow, xlowIn, xupp, xuppIn, lowmax, uppmax, ilow, iupp); */ \
328-
if ((( roll>0.0 && xlow>xlowIn && (xupp<xuppIn || !uppmax || rollends[1])) \
328+
if ((( roll>0.0 && (!lowmax || xlow>xlowIn) && (xupp<xuppIn || !uppmax || rollends[1])) \
329329
|| ( roll<0.0 && xupp==xuppIn && uppmax && rollends[1]) ) /* test 933 */ \
330330
&& ( isinf(rollabs) || ((LOWDIST)-(TYPE)rollabs <= (TYPE)1e-6) )) \
331331
/* ^^^^^^^^^^^^^^ always true for STRSXP where LOWDIST is a dummy, TODO pre-save isinf() into const bool */ \
332332
xlow--; \
333333
/* ** AND NOW EXTEND iupp too for all irows that join to this same row */ \
334334
else \
335-
if ((( roll<0.0 && xupp<xuppIn && (xlow>xlowIn || !lowmax || rollends[0])) \
335+
if ((( roll<0.0 && (!uppmax || xupp<xuppIn) && (xlow>xlowIn || !lowmax || rollends[0])) \
336336
|| ( roll>0.0 && xlow==xlowIn && lowmax && rollends[0]) ) \
337337
&& ( isinf(rollabs) || ((UPPDIST)-(TYPE)rollabs <= (TYPE)1e-6) )) \
338338
xupp++; \
@@ -413,8 +413,7 @@ void bmerge_r(int xlowIn, int xuppIn, int ilowIn, int iuppIn, int col, int thisg
413413
} else {
414414
const double *icv = REAL_RO(ic);
415415
const double *xcv = REAL_RO(xc);
416-
const double ival = icv[ir];
417-
const uint64_t ivalt = dtwiddle(ival); // TO: remove dtwiddle by dealing with NA, NaN, -Inf, +Inf up front
416+
double ival = icv[ir];
418417
#undef ISNAT
419418
#undef WRAP
420419
#define ISNAT(x) (ISNAN(x))
@@ -482,15 +481,15 @@ void bmerge_r(int xlowIn, int xuppIn, int ilowIn, int iuppIn, int col, int thisg
482481
if (col<ncol-1) { // could include col==-1 here (a non-equi non-data column)
483482
bmerge_r(xlow, xupp, ilow, iupp, col+1, thisgrp, true, true);
484483
} else {
485-
int len = xupp-xlow-1+rollLow+rollUpp; // rollLow and rollUpp cannot both be true
484+
int len = xupp-xlow-1;
486485
if (len>1) {
487486
if (mult==ALL)
488487
allLen1[0] = FALSE; // bmerge()$allLen1
489488
else if (mult==ERR)
490489
error(_("mult='error' and multiple matches during merge"));
491490
}
492491
if (nqmaxgrp == 1) {
493-
const int rf = (mult!=LAST) ? xlow+2-rollLow : xupp+rollUpp; // bmerge()$starts thus extra +1 for 1-based indexing at R level
492+
const int rf = (mult!=LAST) ? xlow+2 : xupp; // bmerge()$starts thus extra +1 for 1-based indexing at R level
494493
const int rl = (mult==ALL) ? len : 1; // bmerge()$lens
495494
for (int j=ilow+1; j<iupp; j++) { // usually iterates once only for j=ir
496495
const int k = o ? o[j]-1 : j;

0 commit comments

Comments
 (0)