I was under the impression that any call to a list by the index was a constant runtime (i.e. O(1) ), but it seems that this is not actually the case, as shown below. What causes this increase in runtime (looks like O(n) ), and more importantly, is there a way around it? I would like to have a list of data.frame's that has the constant runtime access of a hash set (and there will be no changes to the "key set" so a "perfect" hash is possible).
> l <- list()
> system.time(l[[300000000]] <- "test")
user system elapsed
1.86 0.36 2.21
> system.time(l[[299999999]] <- "test")
user system elapsed
4.42 0.73 5.15
> system.time(l[[1]] <- "test")
user system elapsed
4.34 0.44 4.77
> l <- list()
> system.time(l[[300000]] <- "test")
user system elapsed
0 0 0
> l <- list()
> system.time(l[[3000000]] <- "test")
user system elapsed
0.01 0.00 0.01
> l <- list()
> system.time(l[[30000000]] <- "test")
user system elapsed
0.32 0.03 0.36