evomimic / map-holons

3 stars 1 forks source link

Introduce dance_state to HolonsContext #103

Closed evomimic closed 3 months ago

evomimic commented 3 months ago

This enhancement adds the ability to stash transient information (i.e., not intended to be persisted) in the context object for a dance. It also introduces a new TransientCollection type.

Motivation

During processing of complex dances, there may arise the need to stash state information in a well-known location that is accessible to various functions without having to explicit pass these various bits of state in function parameters. For example, during L0 Schema Loading, there is a requirement to keep track of previously staged or committed descriptors so they can be added as targets for various relationships. We already have a HolonsContext structure being passed in many function signatures. Adding a dance_state:TransientCollection field to context addresses these requirements.

Dependencies

Issue #110

Current State

The goal is to leverage the desirable behaviors of HolonCollection without the entanglement of their being targeted for persistent storage.

Analysis of Design Options

_Should Transient just be a new state of HolonCollection or should we introduce a TransientCollection struct?_

My initial thought was to introduce a new state. This allows us to share the method implementations for _addreferences and _get_bykey. But this benefit comes at the cost of adding complexity, overhead, and greater error potential to HolonCollection. It also requires the struct definitions to be identical (i.e., representing collection members as HolonReference). If we also introduce transient holons then to allow transient collections to contain transient holons, we may be forced to create a new HolonReference variant (TransientReference). Then we have to go to special measures to account for difference between them and prevent each type of reference being used in the wrong context.

Recommendation: Leave the current design of HolonCollection unchanged, add a new TransientCollection datatype:

Proposal

Introduce TransientCollection

pub struct TransientCollection {
    members: Vec<HolonReference>,
    keyed_index: BTreeMap<MapString, usize>, // usize is an index into the members vector
}

NOTE: We may need to wrap HolonReference in a new TransientReference enum if transient holons are implemented and allowed as members of TransientCollection.

Introduce dance_state: TransientCollection

Testing

This functionality is not exposed externally and so is not amenable to sweetest or tryorama. But by using the dance_state as part of the load_core_schema dance we can indirectly test that the dance_state is behaving as expected.

Definition of Done