Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better indexing for heterogeneous arrays #115

Open
marcrasi opened this issue Jul 7, 2020 · 0 comments
Open

better indexing for heterogeneous arrays #115

marcrasi opened this issue Jul 7, 2020 · 0 comments
Assignees

Comments

@marcrasi
Copy link
Collaborator

marcrasi commented Jul 7, 2020

We have many operations that "map" a heterogeneous array through a function that transforms elements. (See #114 for some examples).

The heterogeneous arrays have a var storage: [ObjectIdentifier: Something] field that stores their elements. There are two ways that the map operations could produce the storage for the resulting heterogeneous arrays:

  1. Transform the Somethings, but leave the ObjectIdentifiers unchanged (even if the transform changes the type of the elements).
  2. Transform the Somethings, and also transform the ObjectIdentifier to the identifier of the transformed element type.

Option 1 has the drawback that the resulting ObjectIdentifier no longer matches the element type and therefore the subscript using TypedID, which assumes that the ObjectIdentifier matches the element type, can't index into the result heterogeneous array. Option 2 has the drawback that ObjectIdentifiers can collide if the transform function maps distinct types to the same type.

We actually currently use both options in different places, depending on what we need. In the place where we use option 2, we don't handle collisions so we should really fix it soon (none of the use cases that we have implemented so far cause collisions).

The correct solution is probably to use option 1 but add additional data to TypedID so that we can subscript into the resulting arrays using TypedID.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants