s-u / fastmatch

Fast hashing functions and replacement of match()
18 stars 7 forks source link

fmatch.hash inconsistent for length-0 input #9

Open EmilBode opened 4 years ago

EmilBode commented 4 years ago

I used fmatch.hash to attach a hash-table to my objects, but this gets problematic when my table is of length 0 (but not NULL, see issue #8): the returned value is NA_integer_ (regardless of the value of x and the class of table).

This is a problem, both because my length is now different, but also because it now matches NA's. I think the following shows the problems:

subtable <- data.frame(value=fmatch.hash("myval", bigtable[somecondition],
                       bigtablerows=which(somecondition))

Works fine if some value of somecondition is TRUE, but not when it's all FALSE

And:

> match(NA, vector[c(F,F,F,F)])
[1] NA
> fmatch(NA, vector[c(F,F,F,F)])
[1] NA
> temp <- fmatch.hash('someval', vector(c(F,F,F,F]))
> fmatch(NA, temp)
[1] 1

I'd expect the final result to always be the same as when calling (f)match directly

Details about my setup: Reproduced with both fastmatch 1.1-0 and 1.1-1 R 3.5.3 and 3.6.1 Under Rstudio 1.1.463 and 1.2.1335, and command prompt with R --vanilla Windows 10