Skip to content

Commit 86cd71e

Browse files
committed
replace dhashtab with hashtab in rbindlist
1 parent 09fe9ae commit 86cd71e

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/rbindlist.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg, SEXP ignor
7474
SEXP *uniq = malloc(sizeof(*uniq) * upperBoundUniqueNames); // upperBoundUniqueNames was initialized with 1 to ensure this is defined (otherwise 0 when no item has names)
7575
if (!uniq)
7676
error(_("Failed to allocate upper bound of %"PRId64" unique column names [sum(lapply(l,ncol))]"), (int64_t)upperBoundUniqueNames); // # nocov
77-
dhashtab * marks = dhash_create(1 + (LENGTH(l) ? (2 * LENGTH(getAttrib(VECTOR_ELT(l, 0), R_NamesSymbol))) : 0));
77+
hashtab * marks = hash_create(1 + (LENGTH(l) ? (2 * LENGTH(getAttrib(VECTOR_ELT(l, 0), R_NamesSymbol))) : 0));
7878
int nuniq=0;
7979
// first pass - gather unique column names
8080
for (int i=0; i<LENGTH(l); i++) {
@@ -86,9 +86,9 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg, SEXP ignor
8686
const SEXP *cnp = STRING_PTR_RO(cn);
8787
for (int j=0; j<thisncol; j++) {
8888
SEXP s = ENC2UTF8(cnp[j]); // convert different encodings for use.names #5452
89-
if (dhash_lookup(marks, s, 0)<0) continue; // seen this name before
89+
if (hash_lookup(marks, s, 0)<0) continue; // seen this name before
9090
uniq[nuniq++] = s;
91-
dhash_set(marks, s,-nuniq);
91+
hash_set(marks, s,-nuniq);
9292
}
9393
}
9494
if (nuniq>0) uniq = realloc(uniq, sizeof(SEXP)*nuniq); // shrink to only what we need to release the spare
@@ -113,7 +113,7 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg, SEXP ignor
113113
memset(counts, 0, nuniq*sizeof(*counts));
114114
for (int j=0; j<thisncol; j++) {
115115
SEXP s = ENC2UTF8(cnp[j]); // convert different encodings for use.names #5452
116-
counts[ -dhash_lookup(marks, s, 0)-1 ]++;
116+
counts[ -hash_lookup(marks, s, 0)-1 ]++;
117117
}
118118
for (int u=0; u<nuniq; u++) {
119119
if (counts[u] > maxdup[u]) maxdup[u] = counts[u];
@@ -152,7 +152,7 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg, SEXP ignor
152152
memset(counts, 0, nuniq*sizeof(*counts));
153153
for (int j=0; j<thisncol; j++) {
154154
SEXP s = ENC2UTF8(cnp[j]); // convert different encodings for use.names #5452
155-
int w = -dhash_lookup(marks, s, 0)-1;
155+
int w = -hash_lookup(marks, s, 0)-1;
156156
int wi = counts[w]++; // how many dups have we seen before of this name within this item
157157
if (uniqMap[w]==-1) {
158158
// first time seen this name across all items
@@ -356,7 +356,7 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg, SEXP ignor
356356
int ansloc=0;
357357
if (factor) {
358358
char warnStr[1000] = "";
359-
dhashtab * marks = dhash_create(1024);
359+
hashtab * marks = hash_create(1024);
360360
int nLevel=0, allocLevel=0;
361361
SEXP *levelsRaw = NULL; // growing list of SEXP pointers. Raw since managed with raw realloc.
362362
if (orderedFactor) {
@@ -376,7 +376,7 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg, SEXP ignor
376376
for (int k=0; k<longestLen; ++k) {
377377
SEXP s = sd[k];
378378
levelsRaw[k] = s;
379-
dhash_set(marks, s, -k-1);
379+
hash_set(marks, s, -k-1);
380380
}
381381
for (int i=0; i<LENGTH(l); ++i) {
382382
SEXP li = VECTOR_ELT(l, i);
@@ -389,7 +389,7 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg, SEXP ignor
389389
const int n = length(levels);
390390
for (int k=0, last=0; k<n; ++k) {
391391
SEXP s = levelsD[k];
392-
const int tl = dhash_lookup(marks, s, 0);
392+
const int tl = hash_lookup(marks, s, 0);
393393
if (tl>=last) { // if tl>=0 then also tl>=last because last<=0
394394
if (tl>=0) {
395395
snprintf(warnStr, sizeof(warnStr), // not direct warning as we're inside tl region
@@ -428,7 +428,7 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg, SEXP ignor
428428
for (int k=0; k<n; ++k) {
429429
SEXP s = thisColStrD[k];
430430
if (s==NA_STRING || // remove NA from levels; test 1979 found by package emil when revdep testing 1.12.2 (#3473)
431-
dhash_lookup(marks, s, 0)<0) continue; // seen this level before; handles removing dups from levels as well as finding unique of character columns
431+
hash_lookup(marks, s, 0)<0) continue; // seen this level before; handles removing dups from levels as well as finding unique of character columns
432432
if (allocLevel==nLevel) { // including initial time when allocLevel==nLevel==0
433433
SEXP *tt = NULL;
434434
if (allocLevel<INT_MAX) {
@@ -439,14 +439,14 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg, SEXP ignor
439439
if (tt==NULL) {
440440
// # nocov start
441441
// C spec states that if realloc() fails (above) the original block (levelsRaw) is left untouched: it is not freed or moved. We ...
442-
for (int k=0; k<nLevel; k++) dhash_set(marks, levelsRaw[k], 0); // ... rely on that in this loop which uses levelsRaw.
442+
for (int k=0; k<nLevel; k++) hash_set(marks, levelsRaw[k], 0); // ... rely on that in this loop which uses levelsRaw.
443443
free(levelsRaw);
444444
error(_("Failed to allocate working memory for %d factor levels of result column %d when reading item %d of item %d"), allocLevel, idcol+j+1, w+1, i+1);
445445
// # nocov end
446446
}
447447
levelsRaw = tt;
448448
}
449-
dhash_set(marks,s,-(++nLevel));
449+
hash_set(marks,s,-(++nLevel));
450450
levelsRaw[nLevel-1] = s;
451451
}
452452
int *targetd = INTEGER(target);
@@ -455,7 +455,7 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg, SEXP ignor
455455
if (length(thisCol)<=1) {
456456
// recycle length-1, or NA-fill length-0
457457
SEXP lev;
458-
const int val = (length(thisCol)==1 && id[0]!=NA_INTEGER && (lev=thisColStrD[id[0]-1])!=NA_STRING) ? -dhash_lookup(marks,lev,0) : NA_INTEGER;
458+
const int val = (length(thisCol)==1 && id[0]!=NA_INTEGER && (lev=thisColStrD[id[0]-1])!=NA_STRING) ? -hash_lookup(marks,lev,0) : NA_INTEGER;
459459
// ^^ #3915 and tests 2015.2-5
460460
for (int r=0; r<thisnrow; ++r) targetd[ansloc+r] = val;
461461
} else {
@@ -466,22 +466,22 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg, SEXP ignor
466466
// retain the position of NA level (if any) and the integer mappings to it
467467
for (int k=0; k<n; ++k) {
468468
SEXP s = thisColStrD[k];
469-
if (s!=NA_STRING && -dhash_lookup(marks,s,0)!=k+1) { hop=true; break; }
469+
if (s!=NA_STRING && -hash_lookup(marks,s,0)!=k+1) { hop=true; break; }
470470
}
471471
} else {
472472
for (int k=0; k<n; ++k) {
473473
SEXP s = thisColStrD[k];
474-
if (s==NA_STRING || -dhash_lookup(marks,s,0)!=k+1) { hop=true; break; }
474+
if (s==NA_STRING || -hash_lookup(marks,s,0)!=k+1) { hop=true; break; }
475475
}
476476
}
477477
if (hop) {
478478
if (orderedFactor) {
479479
for (int r=0; r<thisnrow; ++r)
480-
targetd[ansloc+r] = id[r]==NA_INTEGER ? NA_INTEGER : -dhash_lookup(marks,thisColStrD[id[r]-1],0);
480+
targetd[ansloc+r] = id[r]==NA_INTEGER ? NA_INTEGER : -hash_lookup(marks,thisColStrD[id[r]-1],0);
481481
} else {
482482
for (int r=0; r<thisnrow; ++r) {
483483
SEXP lev;
484-
targetd[ansloc+r] = id[r]==NA_INTEGER || (lev=thisColStrD[id[r]-1])==NA_STRING ? NA_INTEGER : -dhash_lookup(marks,lev,0);
484+
targetd[ansloc+r] = id[r]==NA_INTEGER || (lev=thisColStrD[id[r]-1])==NA_STRING ? NA_INTEGER : -hash_lookup(marks,lev,0);
485485
}
486486
}
487487
} else {
@@ -491,10 +491,10 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg, SEXP ignor
491491
} else {
492492
const SEXP *sd = STRING_PTR_RO(thisColStr);
493493
if (length(thisCol)<=1) {
494-
const int val = (length(thisCol)==1 && sd[0]!=NA_STRING) ? -dhash_lookup(marks,sd[0],0) : NA_INTEGER;
494+
const int val = (length(thisCol)==1 && sd[0]!=NA_STRING) ? -hash_lookup(marks,sd[0],0) : NA_INTEGER;
495495
for (int r=0; r<thisnrow; ++r) targetd[ansloc+r] = val;
496496
} else {
497-
for (int r=0; r<thisnrow; ++r) targetd[ansloc+r] = sd[r]==NA_STRING ? NA_INTEGER : -dhash_lookup(marks,sd[r],0);
497+
for (int r=0; r<thisnrow; ++r) targetd[ansloc+r] = sd[r]==NA_STRING ? NA_INTEGER : -hash_lookup(marks,sd[r],0);
498498
}
499499
}
500500
}

0 commit comments

Comments
 (0)