Skip to content

Commit 34f85ad

Browse files
authored
Merge pull request #99 from WIAS-PDELib/doc/tdict
Add `TDict` doc entry and add a small summary
2 parents e36b270 + b762cfb commit 34f85ad

3 files changed

Lines changed: 18 additions & 7 deletions

File tree

docs/Project.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1616
Triangulate = "f7e6ffb2-c36d-4f8f-a77e-16e897189344"
1717

1818
[compat]
19-
CairoMakie = "0.12"
2019
Documenter = "1"
2120
ExampleJuggler = "2"
2221
julia = "1.9"

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ function mkdocs()
3838
"adjacency.md",
3939
"vectorofconstants.md",
4040
"typehierarchy.md",
41+
"tdict.md",
4142
"elementgeometry.md",
4243
"shape_specs.md",
4344
"coordinatesystem.md",

docs/src/tdict.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,18 @@
33
Here we describe the idea behind the data structure used in this package.
44
TDict 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

819
In certain contexts it is desirable to use containers with core components
920
which are user extendable and allow for type stable component access. Moreover,
@@ -13,14 +24,14 @@ from typos in component names etc.
1324

1425
Julia 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

3445
Harness 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
4556
See 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

Comments
 (0)