randy3k / collections

High-performance container datatypes for R
https://randy3k.github.io/collections
Other
103 stars 3 forks source link

set method on one OrderedDict changes another OrderedDict #2

Closed paultpearson closed 5 years ago

paultpearson commented 5 years ago

I created two OrderedDict objects x and r, set a key value pair in r, and found that the keys and values in x had also been modified to be a copy of r even though no set method was called on x. Here is a minimal working example of the bug with R output on lines that begin with ##.

library(collections)
x <- OrderedDict$new() 
r <- OrderedDict$new() 
print(paste("x$keys()",x$keys()))
## [1] "x$keys() "
print(paste("x$values()",x$values()))
## [1] "x$values() "
seed <- c(27)
for (s in seed) { 
  r$set(as.character(s), 1/length(seed))
}
print(paste("x$keys()",x$keys())) # this should still be empty, but it's not.  It's a copy of r
## [1] "x$keys() 27"
print(paste("x$values()",x$values())) # this should still be empty, but it's not.  It's a copy of r
## [1] "x$values() 1"
sessionInfo()
## R version 3.4.4 (2018-03-15)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 18.04.1 LTS
## 
## Matrix products: default
## BLAS: /usr/lib/x86_64-linux-gnu/atlas/libblas.so.3.10.3
## LAPACK: /usr/lib/x86_64-linux-gnu/atlas/liblapack.so.3.10.3
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] collections_0.1.2
## 
## loaded via a namespace (and not attached):
##  [1] compiler_3.4.4  backports_1.1.2 R6_2.2.2        magrittr_1.5   
##  [5] rprojroot_1.3-2 tools_3.4.4     htmltools_0.3.6 yaml_2.2.0     
##  [9] Rcpp_0.12.19    stringi_1.2.4   rmarkdown_1.10  knitr_1.20     
## [13] stringr_1.3.1   digest_0.6.17   evaluate_0.11
randy3k commented 5 years ago

Thanks for the bug report. I have identified the reason and will push a fix later today.