In a tree, the relation between parent and child is bi-directional.
In our serialization format, we have such a relation for each Containment.
Option A: Store child id in parent
Example:
{
"type": "Car",
"id": "1111",
"children": {
"wheels": [
"2222",
"2223"
]
}
},
{
"type": "MetalWheel",
"id": "2222"
},
{
"type": "AluminiumWheel",
"id": "2223"
},
Pro:
- Efficient top-down navigation
Con:
- Need to build up child-to-parent relation during parsing
Option B: Store parent id in child
Example:
{
"type": "Car",
"id": "1111"
},
{
"type": "MetalWheel",
"id": "2222",
"parent": "1111"
},
{
"type": "AluminiumWheel",
"id": "2223",
"parent": "1111"
},
Pro:
- We know the parent even if it's not part of the currently serialized model chunk
- We don't need another Repo API call "get me the parent of this node"
Con:
- Need to build up parent-to-child relation during parsing
Option C: Store both
Example:
{
"type": "Car",
"id": "1111",
"children": {
"wheels": [
"2222",
"2223"
]
}
},
{
"type": "MetalWheel",
"id": "2222",
"parent": "1111"
},
{
"type": "AluminiumWheel",
"id": "2223",
"parent": "1111"
},
Pro:
- Combines all pros of option A and B
- Both directions are explicitly stored
Con:
- Duplicate information might waste space
- Have to handle inconsistent information
-> Decision: Option C
Space issues can be addressed by compression in lower protocol level (#73).
In a tree, the relation between parent and child is bi-directional.
In our serialization format, we have such a relation for each
Containment.Option A: Store child id in parent
Example:
{ "type": "Car", "id": "1111", "children": { "wheels": [ "2222", "2223" ] } }, { "type": "MetalWheel", "id": "2222" }, { "type": "AluminiumWheel", "id": "2223" },Pro:
Con:
Option B: Store parent id in child
Example:
{ "type": "Car", "id": "1111" }, { "type": "MetalWheel", "id": "2222", "parent": "1111" }, { "type": "AluminiumWheel", "id": "2223", "parent": "1111" },Pro:
Con:
Option C: Store both
Example:
{ "type": "Car", "id": "1111", "children": { "wheels": [ "2222", "2223" ] } }, { "type": "MetalWheel", "id": "2222", "parent": "1111" }, { "type": "AluminiumWheel", "id": "2223", "parent": "1111" },Pro:
Con:
-> Decision: Option C
Space issues can be addressed by compression in lower protocol level (#73).