R Under development (unstable) (2024-10-31 r87283 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(R.oo) Loading required package: R.methodsS3 R.methodsS3 v1.8.2 (2022-06-13 22:00:14 UTC) successfully loaded. See ?R.methodsS3 for help. R.oo v1.27.0 successfully loaded. See ?R.oo for help. Attaching package: 'R.oo' The following object is masked from 'package:R.methodsS3': throw The following objects are masked from 'package:methods': getClasses, getMethods The following objects are masked from 'package:base': attach, detach, load, save > > message("hashCode() ...") hashCode() ... > > message("- NULL") - NULL > > y <- hashCode(NULL) > print(y) NULL > stopifnot(is.null(y)) > > > message("- empty vectors") - empty vectors > > y <- hashCode(character(0L)) > print(y) NULL > stopifnot(is.null(y)) > > y <- hashCode(integer(0L)) > print(y) NULL > stopifnot(is.null(y)) > > y <- hashCode(double(0L)) > print(y) NULL > stopifnot(is.null(y)) > > y <- hashCode(list()) > print(y) NULL > stopifnot(is.null(y)) > > > message("- strings") - strings > > x <- "" > y <- hashCode(x) > print(y) [1] 0 > stopifnot( + is.integer(y), + length(y) == length(x), + !anyNA(y), + y == 0L + ) > > x <- base::letters > y <- hashCode(x) > print(y) [1] 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 [20] 116 117 118 119 120 121 122 > stopifnot( + is.integer(y), + length(y) == length(x), + !anyNA(y), + all(y == charToInt(base::letters)) + ) > > x <- "abcdefghij" > y <- hashCode(x) > print(y) [1] -634317659 > stopifnot( + is.integer(y), + length(y) == length(x), + !anyNA(y), + y == -634317659L + ) > > x <- "abcdefghijklmno" > y <- hashCode(x) > print(y) [1] 486644840 > stopifnot( + is.integer(y), + length(y) == length(x), + !anyNA(y), + y == 486644840L + ) > > > ## Assert no integer overflow => NA > for (n in seq_along(base::letters)) { + x <- paste(base::letters[seq_len(n)], collapse = "") + y <- hashCode(x) + cat(sprintf("%s => %d\n", x, y)) + stopifnot( + is.integer(y), + length(y) == length(x), + !anyNA(y) + ) + } a => 97 ab => 3105 abc => 96354 abcd => 2987074 abcde => 92599395 abcdef => -1424385949 abcdefg => -1206291356 abcdefgh => 1259673732 abcdefghi => 395180133 abcdefghij => -634317659 abcdefghijk => 1810989158 abcdefghijkl => 306089158 abcdefghijklm => 898829415 abcdefghijklmn => 2093908199 abcdefghijklmno => 486644840 abcdefghijklmnop => -2093879032 abcdefghijklmnopq => -485740439 abcdefghijklmnopqr => 2121915689 abcdefghijklmnopqrs => 1354877034 abcdefghijklmnopqrst => -948484790 abcdefghijklmnopqrstu => 661742699 abcdefghijklmnopqrstuv => -960812693 abcdefghijklmnopqrstuvw => 279577708 abcdefghijklmnopqrstuvwx => 76974476 abcdefghijklmnopqrstuvwxy => -1908758419 abcdefghijklmnopqrstuvwxyz => 958031277 > > message("- integers") - integers > > x <- 1:10 > y <- hashCode(x) > print(y) [1] 1 2 3 4 5 6 7 8 9 10 > stopifnot( + is.integer(y), + length(y) == length(x), + !anyNA(y), + all(y == x) + ) > > message("- doubles") - doubles > > x <- as.numeric(1:10) > y <- hashCode(x) > print(y) [1] 1 2 3 4 5 6 7 8 9 10 > stopifnot( + is.integer(y), + length(y) == length(x), + !anyNA(y), + all(y == as.integer(x)) + ) > > > message("- complex") - complex > > x <- 1:10 + 0.1 > y <- hashCode(x) > print(y) [1] 1 2 3 4 5 6 7 8 9 10 > stopifnot( + is.integer(y), + length(y) == length(x), + !anyNA(y), + all(y == 1:10) + ) > > message("- miscellaneous types") - miscellaneous types > > x <- list(0L) > y <- hashCode(x) > print(y) [1] 0 > stopifnot( + is.integer(y), + length(y) == length(x), + !anyNA(y), + y == 0L + ) > > x <- as.list(1:10) > y <- hashCode(x) > print(y) [1] 1 2 3 4 5 6 7 8 9 10 > stopifnot( + is.integer(y), + length(y) == length(x), + !anyNA(y), + all(y == 1:10) + ) > > > message("hashCode() ... DONE") hashCode() ... DONE > > proc.time() user system elapsed 0.25 0.12 0.34