/
gong_slices.go
87 lines (69 loc) · 2.58 KB
/
gong_slices.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// generated code - do not edit
package models
// EvictInOtherSlices allows for adherance between
// the gong association model and go.
//
// Says you have a Astruct struct with a slice field "anarrayofb []*Bstruct"
//
// go allows many Astruct instance to have the anarrayofb field that have the
// same pointers. go slices are MANY-MANY association.
//
// With gong it is only ZERO-ONE-MANY associations, a Bstruct can be pointed only
// once by an Astruct instance through a given field. This follows the requirement
// that gong is suited for full stack programming and therefore the association
// is encoded as a reverse pointer (not as a joint table). In gong, a named struct
// is translated in a table and each table is a named struct.
//
// EvictInOtherSlices removes the fields instances from other
// fields of other instance
//
// Note : algo is in O(N)log(N) of nb of Astruct and Bstruct instances
func EvictInOtherSlices[OwningType PointerToGongstruct, FieldType PointerToGongstruct](
stage *StageStruct,
owningInstance OwningType,
sliceField []FieldType,
fieldName string) {
// create a map of the field elements
setOfFieldInstances := make(map[FieldType]any, 0)
for _, fieldInstance := range sliceField {
setOfFieldInstances[fieldInstance] = true
}
switch owningInstanceInfered := any(owningInstance).(type) {
// insertion point
case *CivilianAirport:
// insertion point per field
case *Liner:
// insertion point per field
case *Message:
// insertion point per field
case *OpsLine:
// insertion point per field
case *Radar:
// insertion point per field
case *Satellite:
// insertion point per field
case *Scenario:
// insertion point per field
default:
_ = owningInstanceInfered // to avoid "declared and not used" error if no named struct has slices
}
}
// ComputeReverseMaps computes the reverse map, for all intances, for all slice to pointers field
// Its complexity is in O(n)O(p) where p is the number of pointers
func (stage *StageStruct) ComputeReverseMaps() {
// insertion point per named struct
// Compute reverse map for named struct CivilianAirport
// insertion point per field
// Compute reverse map for named struct Liner
// insertion point per field
// Compute reverse map for named struct Message
// insertion point per field
// Compute reverse map for named struct OpsLine
// insertion point per field
// Compute reverse map for named struct Radar
// insertion point per field
// Compute reverse map for named struct Satellite
// insertion point per field
// Compute reverse map for named struct Scenario
// insertion point per field
}