mwparserfromhell icon indicating copy to clipboard operation
mwparserfromhell copied to clipboard

WIP - rewrote smart list

Open nyurik opened this issue 6 years ago • 1 comments

This is a first draft of the smart list. It passes all of the existing smartlist tests (except for full-list reversal, whose behavior has changed), but the rest of the code has not yet been updated.

Main idea: there is a non-exposed (private) storage class (essentially a list), plus the smart slices (views) into that list. All slices are created on the same level. Slices could be restricted [2:6:1] and non-restricted [::1] or a mix, with some limited support for step != 1.

The biggest unknown - how to handle data insertion beyond the edge of the current slice. Example:

full = smart_list((0,1,2,3])
part0 = full[:1]  # [0]
part1 = full[1:3]  # [1,2]
part1clone = part1[:]  # [1,2]
part2 = full[3:]  # [3]

what should the behavior be after this operation?

  • part1.insert(0,'a')
assert full == [0, 'a', 1, ,2, 3]
assert part0 ==  [0, 'a']
assert part1 == ['a', 1, 2]
assert part1clone == ['a', 1, 2]
assert part2 == [3]
  • part1.insert(100,'z')
assert full == [0, 1, 2, 3, 'z']
assert part0 ==  [0]
assert part1 == [1, 2, 'z']
assert part1clone == [1, 2, 'z']
assert part2 == [3, 'z']

nyurik avatar Jan 06 '20 19:01 nyurik

I think your WIP fixes https://github.com/earwig/mwparserfromhell/pull/289 ...

saper avatar Jun 28 '22 22:06 saper