r-lib / fastmap

Fast map implementation for R
https://r-lib.github.io/fastmap/
Other
133 stars 7 forks source link

Get all the values, key from value #14

Closed shahreyar-abeer closed 4 years ago

shahreyar-abeer commented 4 years ago

Is it possible to-

  1. Get all the values?
  2. Get key(s) given a value?
wch commented 4 years ago

Yes, though it won't be as fast as the reverse operations. For the first, you can use m$mget(m$keys()). That will return a named list. For the second, I think you'd have to iterate through that list to search for the value, then get the corresponding name for that index.

shahreyar-abeer commented 4 years ago

Thanks for that.

wch commented 4 years ago

I just remembered that you can use m$as_list() to get a named list. That's simpler and probably faster than m$mget(m$keys()).

shahreyar-abeer commented 4 years ago

Thanks. I did do that. Is there any way to update the values except m$set()?

wch commented 4 years ago

You can use m$mset(). This stuff is in the documentation, which can see with ?fastmap, or here: https://r-lib.github.io/fastmap/reference/fastmap.html

shahreyar-abeer commented 4 years ago

Okay, thanks for that.