Skip to content

Commit 88a424e

Browse files
committed
Add zero dups branch #648 #452.
1 parent eeaa49c commit 88a424e

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/kit_dup.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ SEXP dupVecIndex(SEXP x) {
131131
const double *restrict px = REAL(x);
132132
union uno tpv;
133133
for (int i = 0; i != n; ++i) {
134-
tpv.d = px[i]; // R_IsNA(px[i]) ? NA_REAL : (R_IsNaN(px[i]) ? R_NaN : px[i]);
134+
tpv.d = px[i] + 0.0; // R_IsNA(px[i]) ? NA_REAL : (R_IsNaN(px[i]) ? R_NaN : px[i]);
135135
id = HASH(tpv.u[0] + tpv.u[1], K);
136136
while(h[id]) {
137137
if(REQUAL(px[h[id]-1], px[i])) {
@@ -157,9 +157,9 @@ SEXP dupVecIndex(SEXP x) {
157157
} else if (C_IsNaN(tmp)) {
158158
tmp.r = tmp.i = R_NaN;
159159
}
160-
tpv.d = tmp.r;
160+
tpv.d = tmp.r + 0.0;
161161
u = tpv.u[0] ^ tpv.u[1];
162-
tpv.d = tmp.i;
162+
tpv.d = tmp.i + 0.0;
163163
u ^= tpv.u[0] ^ tpv.u[1];
164164
id = HASH(u, K);
165165
while(h[id]) {
@@ -295,7 +295,7 @@ SEXP dupVecIndexKeepNA(SEXP x) {
295295
pans_i[i] = NA_INTEGER;
296296
continue;
297297
}
298-
tpv.d = px[i];
298+
tpv.d = px[i] + 0.0;
299299
id = HASH(tpv.u[0] + tpv.u[1], K);
300300
while(h[id]) {
301301
if(REQUAL(px[h[id]-1], px[i])) {
@@ -320,9 +320,9 @@ SEXP dupVecIndexKeepNA(SEXP x) {
320320
pans_i[i] = NA_INTEGER;
321321
continue;
322322
}
323-
tpv.d = tmp.r;
323+
tpv.d = tmp.r + 0.0;
324324
u = tpv.u[0] ^ tpv.u[1];
325-
tpv.d = tmp.i;
325+
tpv.d = tmp.i + 0.0;
326326
u ^= tpv.u[0] ^ tpv.u[1];
327327
id = HASH(u, K);
328328
while(h[id]) {
@@ -473,7 +473,7 @@ SEXP dupVecIndexTwoVectors(SEXP x, SEXP y) {
473473
union uno tpx, tpy;
474474
// fill hash table with indices of 'table'
475475
for (int i = 0; i != n; ++i) {
476-
tpx.d = px[i]; tpy.d = py[i];
476+
tpx.d = px[i] + 0.0; tpy.d = py[i] + 0.0;
477477
id = HASH((64988430769U * (tpx.u[0] + tpx.u[1])) + tpy.u[0] + tpy.u[1], K); // Best combination it seems
478478
while(h[id]) {
479479
hid = h[id]-1;
@@ -497,7 +497,7 @@ SEXP dupVecIndexTwoVectors(SEXP x, SEXP y) {
497497
const double *restrict pr = REAL_RO(tx == REALSXP ? x : y);
498498
union uno tpv;
499499
for (int i = 0; i != n; ++i) {
500-
tpv.d = pr[i];
500+
tpv.d = pr[i] + 0.0;
501501
id = HASH((64988430769U * pi[i]) + tpv.u[0] + tpv.u[1], K); // Best combination it seems
502502
while(h[id]) {
503503
hid = h[id]-1;
@@ -517,7 +517,7 @@ SEXP dupVecIndexTwoVectors(SEXP x, SEXP y) {
517517
const double *restrict pr = REAL_RO(tx == REALSXP ? x : y);
518518
union uno tpv;
519519
for (int i = 0; i != n; ++i) {
520-
tpv.d = pr[i];
520+
tpv.d = pr[i] + 0.0;
521521
id = HASH((tpv.u[0] + tpv.u[1]) * ((uintptr_t)ps[i] & 0xffffffff), K); // Best combination it seems
522522
while(h[id]) {
523523
hid = h[id]-1;
@@ -655,7 +655,7 @@ int dupVecSecond(int *restrict pidx, int *restrict pans_i, SEXP x, const int n,
655655
const unsigned int mult = (M-1) / ng; // -1 because C is zero indexed
656656
union uno tpv;
657657
for (int i = 0; i != n; ++i) {
658-
tpv.d = px[i]; // R_IsNA(px[i]) ? NA_REAL : (R_IsNaN(px[i]) ? R_NaN :px[i]);
658+
tpv.d = px[i] + 0.0; // R_IsNA(px[i]) ? NA_REAL : (R_IsNaN(px[i]) ? R_NaN :px[i]);
659659
id = (pidx[i]*mult) ^ HASH(tpv.u[0] + tpv.u[1], K); // HASH((tpv.u[0] + tpv.u[1]) ^ pidx[i], K) + pidx[i]; // Note: This is much faster than just adding pidx[i] to the hash value...
660660
while(h[id]) { // Problem: This value might be seen before, but not in combination with that pidx value...
661661
hid = h[id]-1; // The issue here is that REQUAL(px[hid], px[i]) could be true but pidx[hid] == pidx[i] fails, although the same combination of px and pidx could be seen earlier before...
@@ -683,9 +683,9 @@ int dupVecSecond(int *restrict pidx, int *restrict pans_i, SEXP x, const int n,
683683
} else if (C_IsNaN(tmp)) {
684684
tmp.r = tmp.i = R_NaN;
685685
}
686-
tpv.d = tmp.r;
686+
tpv.d = tmp.r + 0.0;
687687
u = tpv.u[0] ^ tpv.u[1];
688-
tpv.d = tmp.i;
688+
tpv.d = tmp.i + 0.0;
689689
u ^= tpv.u[0] ^ tpv.u[1];
690690
id = (pidx[i]*mult) ^ HASH(u, K);
691691
while(h[id]) {
@@ -930,7 +930,7 @@ SEXP funiqueC(SEXP x) {
930930
const double *restrict px = REAL(x);
931931
union uno tpv;
932932
for (int i = 0; i != n; ++i) {
933-
tpv.d = px[i];
933+
tpv.d = px[i] + 0.0;
934934
id = HASH(tpv.u[0] + tpv.u[1], K);
935935
while(h[id]) {
936936
if(REQUAL(px[h[id]-1], px[i])) goto rbl;
@@ -961,9 +961,9 @@ SEXP funiqueC(SEXP x) {
961961
} else if (C_IsNaN(tmp)) {
962962
tmp.r = tmp.i = R_NaN;
963963
}
964-
tpv.d = tmp.r;
964+
tpv.d = tmp.r + 0.0;
965965
u = tpv.u[0] ^ tpv.u[1];
966-
tpv.d = tmp.i;
966+
tpv.d = tmp.i + 0.0;
967967
u ^= tpv.u[0] ^ tpv.u[1];
968968
id = HASH(u, K);
969969
while(h[id]) {

0 commit comments

Comments
 (0)