s-u / fastmatch

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

fmatch fails (crashes) when table is NULL #8

Open EmilBode opened 4 years ago

EmilBode commented 4 years ago

As the title says: fmatch('somevalue', c()) gives me:

Error in fmatch("somevalue", c()) :
  uable to allocate 67108864.00Mb for a hash table

(I've also seen it with 33554432.00Mb, but anyway it's trying to allocate a nearly infinte amount of memory)

It does work fine with regular length-0 vectors (e.g. giving character(0) instead of c()).

EmilBode commented 4 years ago

I've been playing some more, but it seems this error message it only happens with me under Rstudio (1.2.1335) and R 3.6.1. Under other versions, I get the message : attempt to set an attribute on NULL, which is at least clearer. Still, I think the best way to resolve this would be to return NA, as happens when table=character()

And for fmatch.hash (see other issue as well), returning a table of length-0 in the class of x

ms609 commented 3 years ago

I have encountered what I believe is an equivalent error using fastmatch 1.1.0 under R 4.1.1 in RStudio.

'a' %fin% colnames(matrix(1, 1, 1)) gives

Error in "a" %fin% colnames(matrix(1, 1, 1)) : unable to allocate 33554432.00Mb for a hash table

I expect the function to return FALSE (rather than NA), to match the behaviour of 'a' %in% colnames(matrix(1, 1, 1)).

ms609 commented 3 years ago

I've noticed that version 1.1.3 of fastmatch has been released and resolves this issue for me. Thanks, @s-u !