Search code examples
data-structuresimmutabilityobject-persistence

persistent vs immutable data structure


Is there any difference in a persistent and immutable data structure? Wikipedia refers to immutable data structure when discussing persistence but I have a feeling there might be a subtle difference between the two.


Solution

  • Immutability is an implementation technique. Among other things, it provides persistence, which is an interface. The persistence API is something like:

    • version update(operation o, version v) performs operation o on version v, returning a new version. If the data structure is immutable, the new version is a new structure (that may share immutable parts of the old structure). If the data structure isn't immutable, the returned version might just be a version number. The version v remains a valid version, and it shouldn't change in any observe-able way because of this update - the update is only visible in the returned version, not in v.
    • data observe(query q, version v) observes a data structure at version v without changing it or creating a new version.

    For more about these differences, see: