JuliaCollections/FunctionalCollections.jl

PersistentVector contains incorrect values after `pop()` several times

Closed this issue · 0 comments

julia> p = PersistentVector(range(1,1000))
Persistent{Int64}[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, ..., 975, 976, 977, 978, 979, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, 1000]

julia> for _ in 1:20 p = pop(p) end

julia> p[1:960] == collect(1:960)
true

julia > p[961:end]
20-element Vector{Int64}:
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20

It can be seen that the tail part was broken.

The cause is that FunctionalCollections.peek(bt::DenseBitmappedTrie) = bt[end], but the index is shifted and actually bt[1] was taken instead of the last one.