33Here we describe the idea behind the data structure used in this package.
44TDict means: extendable containers with type stable content access and lazy content creation via the Julia type system.
55
6- ### Problem to be addressed
6+ ### TL;DR: We access grid components using types as keys.
7+
8+ - e.g., coordinates: ` grid[Coordinates] ` by type ` Coordinates `
9+ - we implement a custom method for ` Base.getindex ` with __ explicit return type__ (!) for any key type
10+ - non-existent dictionary entries are created lazily by an ` instantiate ` method
11+ - how to add a new grid component with key type ` T ` and value type ` TV ` ?
12+ - make ` T <: AbstractGridComponent `
13+ - add a method ` Base.getindex(grid::ExtendableGrid{Tc, Ti}, ::Type{T})::TV where {Tc, Ti} = get!(grid, T) ` for type stability (note the ` TV ` !)
14+ - optional: add a method ` instantiate(grid, ::Type{T}) ` to generate component ` T ` from other grid components
15+
16+
17+ ## Problem to be addressed
718
819In certain contexts it is desirable to use containers with core components
920which are user extendable and allow for type stable component access. Moreover,
@@ -13,14 +24,14 @@ from typos in component names etc.
1324
1425Julia default data structures do not provide these properties.
1526
16- #### ` struct `
27+ ### ` struct `
1728 - Julia structs with proper field type annotations guarantee type stability
1829 - Julia structs are not extendable, fields and their types are fixed upon definition
1930 - If we don't fix types of struct fields they become Any and a source
2031 for type instability
2132 - The situation could be fixed if ` getfield ` could be overloaded but it can't
2233
23- #### ` Dict `
34+ ### ` Dict `
2435 - Plain Dicts with flexible value types are a source of type instability
2536 - Dicts with strings as keys needs a meta protocol to handle
2637 semantics of keys which at the end probably hinges on string comparison which
@@ -29,7 +40,7 @@ Julia default data structures do not provide these properties.
2940 - Same for the implementation of a lazy evaluation protocol
3041 - If a dict contains components of different types, component access will not be typestable
3142
32- ### Proposed solution:
43+ ## Proposed solution:
3344
3445Harness the power of the Julia type system:
3546- Use a struct containing a Dict with DataType as keys. Every key is a type.
@@ -41,9 +52,9 @@ Harness the power of the Julia type system:
4152- Component access is made type stable by type dispatched` getindex ` methods
4253- Component insertion is made safe by having ` setindex! ` calling a ` veryform ` method
4354
44- #### Pros
55+ ### Pros
4556See above ...
4657
47- #### Cons
58+ ### Cons
4859- Implemented using a Dict, so access is inherently slower than access to a component
4960 of a struct. Therefore it is not well suited for inner loops.
0 commit comments