onflow / atree

Atree provides scalable arrays and scalable ordered maps.
https://onflow.org
Apache License 2.0
39 stars 13 forks source link

Check mutation of elements from readonly map iterator #410

Closed fxamacker closed 1 month ago

fxamacker commented 1 month ago

Updates #409

Projects using atree might unintentionally mutate elements returned by readonly iterators.

As always, mutation of elements from readonly iterators are not guaranteed to persist.

This PR returns error from mutation functions, and supports callback functions that allow projects using atree to log or debug such mutations with extra context, panic, etc.

If elements from readonly iterators are mutated:

Two callback functions can be provided by using ReadOnlyIteratorWithMutationCallback.

func (m *OrderedMap) ReadOnlyIteratorWithMutationCallback(
    keyMutatinCallback ReadOnlyMapIteratorMutationCallback,
    valueMutationCallback ReadOnlyMapIteratorMutationCallback,
) (MapIterator, error)