Learn R Programming

bit64 (version 4.8.4)

hashmap: Hashing for 64bit integers

Description

This is an explicit implementation of hash functionality that underlies matching and other functions in R. Explicit means that you can create, store and use hash functionality directly. One advantage is that you can re-use hashmaps, which avoid re-building hashmaps again and again.

Usage

hashfun(x, ...)

# S3 method for integer64 hashfun(x, minfac = 1.41, hashbits = NULL, ...)

hashmap(x, ...)

# S3 method for integer64 hashmap(x, nunique = NULL, minfac = 1.41, hashbits = NULL, cache = NULL, ...)

hashpos(cache, ...)

# S3 method for cache_integer64 hashpos(cache, x, nomatch = NA_integer_, ...)

hashrev(cache, ...)

# S3 method for cache_integer64 hashrev(cache, x, nomatch = NA_integer_, ...)

hashfin(cache, ...)

# S3 method for cache_integer64 hashfin(cache, x, ...)

hashrin(cache, ...)

# S3 method for cache_integer64 hashrin(cache, x, ...)

hashdup(cache, ...)

# S3 method for cache_integer64 hashdup(cache, ...)

hashuni(cache, ...)

# S3 method for cache_integer64 hashuni(cache, keep.order = FALSE, ...)

hashupo(cache, ...)

# S3 method for cache_integer64 hashupo(cache, keep.order = FALSE, ...)

hashtab(cache, ...)

# S3 method for cache_integer64 hashtab(cache, ...)

hashmaptab(x, ...)

# S3 method for integer64 hashmaptab(x, nunique = NULL, minfac = 1.5, hashbits = NULL, ...)

hashmapuni(x, ...)

# S3 method for integer64 hashmapuni(x, nunique = NULL, minfac = 1.5, hashbits = NULL, ...)

hashmapupo(x, ...)

# S3 method for integer64 hashmapupo(x, nunique = NULL, minfac = 1.5, hashbits = NULL, ...)

Arguments

Value

See Details

Details

functionsee alsodescription
hashfundigestexport of the hash function used in hashmap
hashmapmatch()return hashmap
hashposmatch()return positions of x in hashmap
hashrevmatch()return positions of hashmap in x
hashfin%in%.integer64return logical whether x is in hashmap
hashrin%in%.integer64return logical whether hashmap is in x
hashdupduplicated()return logical whether hashdat is duplicated using hashmap
hashuniunique()return unique values of hashmap
hashmapuniunique()return unique values of x
hashupounique()return positions of unique values in hashdat
hashmapupounique()return positions of unique values in x
hashtabtable()tabulate values of hashdat using hashmap in keep.order=FALSE
hashmaptabtable()tabulate values of x building hasmap on the fly in keep.order=FALSE

See Also

match(), runif64()

Examples

Run this code
x <- as.integer64(sample(c(NA, 0:9)))
y <- as.integer64(sample(c(NA, 1:9), 10, TRUE))
hashfun(y)
hx <- hashmap(x)
hy <- hashmap(y)
ls(hy)
hashpos(hy, x)
hashrev(hx, y)
hashfin(hy, x)
hashrin(hx, y)
hashdup(hy)
hashuni(hy)
hashuni(hy, keep.order=TRUE)
hashmapuni(y)
hashupo(hy)
hashupo(hy, keep.order=TRUE)
hashmapupo(y)
hashtab(hy)
hashmaptab(y)

    if (FALSE) {
    message("explore speed given size of the hasmap in 2^hashbits and size of the data")
    message("more hashbits means more random access and less collisions")
    message("i.e. more data means less random access and more collisions")
    bits <- 24
    b <- seq(-1, 0, 0.1)
    tim <- matrix(NA, length(b), 2, dimnames=list(b, c("bits", "bits+1")))
    for (i in 1:length(b)) {
      n <- as.integer(2^(bits+b[i]))
      x <- as.integer64(sample(n))
      tim[i, 1] <- repeat.time(hashmap(x, hashbits=bits))[3]
      tim[i, 2] <- repeat.time(hashmap(x, hashbits=bits+1))[3]
      print(tim)
      matplot(b, tim)
    }
    message("we conclude that n*sqrt(2) is enough to avoid collisions")
    }

Run the code above in your browser using DataLab