You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TL;DR: Would it be possible to add an option to tell .push() to only push items to the end, without using unused_indices?
In some scenarios, it might be useful to always .push to the end, without using the unused indices, and later .pack() manually.
In particular, this helps when you want to delete / reorder / insert a bunch of items, then check that there are no external references to the deleted items in a single pass, and only then pack what remains. Automatic packing makes such checks quite hard.
Let's take a simple example: we start with a list
[0] => A
[1] => B
[2] => C
and there are some external references, let's have just two for this primitive example:
ref1 => [1] (=> B)
ref2 => [2] (=> C)
Let's say we want to delete B from the list and immediately push D. In the current algorithm, this will result in the following structure:
[0] => A
[1] => D
[2] => C
now the external reference silently points to the wrong data:
ref1 => [1] (=> *D*)
ref2 => [2] (=> C)
Instead, we would want to be able to end up with the list like this:
[0] => A
[1] => (deleted)
[2] => C
[3] => D
then walk through references to check if there are any dead ones - in this case we'd find one:
ref1 => [1] (=> *(deleted)*)
ref2 => [2] (=> C)
And only when this check passes, then we want to .pack() the array and remap any external IDs:
[0] => A
[1] => D
[2] => C
This way, at any point of mutations we can be sure that there are no references that would silently start pointing to incorrect data because ID got reused.
This particularly helps with cyclical structures, where it's not possible to check if there are any dandling references until all the mutations are finished and you finally can do essentially mark-and-sweep via .pack().
The text was updated successfully, but these errors were encountered:
TL;DR: Would it be possible to add an option to tell
.push()
to only push items to the end, without usingunused_indices
?In some scenarios, it might be useful to always
.push
to the end, without using the unused indices, and later.pack()
manually.In particular, this helps when you want to delete / reorder / insert a bunch of items, then check that there are no external references to the deleted items in a single pass, and only then pack what remains. Automatic packing makes such checks quite hard.
Let's take a simple example: we start with a list
and there are some external references, let's have just two for this primitive example:
Let's say we want to delete
B
from the list and immediately pushD
. In the current algorithm, this will result in the following structure:now the external reference silently points to the wrong data:
Instead, we would want to be able to end up with the list like this:
then walk through references to check if there are any dead ones - in this case we'd find one:
And only when this check passes, then we want to
.pack()
the array and remap any external IDs:This way, at any point of mutations we can be sure that there are no references that would silently start pointing to incorrect data because ID got reused.
This particularly helps with cyclical structures, where it's not possible to check if there are any dandling references until all the mutations are finished and you finally can do essentially mark-and-sweep via
.pack()
.The text was updated successfully, but these errors were encountered: