generate characters with sane compile time/memory
This commit is contained in:
@@ -26,16 +26,40 @@ func LoadTemplates() (*template.Template, error) {
|
||||
|
||||
// ExecCharacterKK renders the Koka character module to w.
|
||||
func ExecCharacterKK(t *template.Template, w io.Writer, c []Character, pairs, trios []AffinityRelation) error {
|
||||
if len(pairs) != len(c)*len(c) {
|
||||
return fmt.Errorf("there are %d pairs but there must be %d for %d characters", len(pairs), len(c)*len(c), len(c))
|
||||
}
|
||||
if len(trios) != len(c)*len(c)*len(c) {
|
||||
return fmt.Errorf("there are %d trios but there must be %d for %d characters", len(trios), len(c)*len(c)*len(c), len(c))
|
||||
}
|
||||
|
||||
maxid := 0
|
||||
pm := make(map[int]map[int]int, len(c))
|
||||
tm := make(map[int]map[int]map[int]int, len(c))
|
||||
for _, u := range c {
|
||||
maxid = max(maxid, u.ID)
|
||||
pm[u.ID] = make(map[int]int, len(c))
|
||||
tm[u.ID] = make(map[int]map[int]int, len(c))
|
||||
for _, v := range c {
|
||||
tm[u.ID][v.ID] = make(map[int]int, len(c))
|
||||
}
|
||||
}
|
||||
for _, p := range pairs {
|
||||
pm[p.IDA][p.IDB] = p.Affinity
|
||||
}
|
||||
for _, t := range trios {
|
||||
tm[t.IDA][t.IDB][t.IDC] = t.Affinity
|
||||
}
|
||||
|
||||
data := struct {
|
||||
Characters []Character
|
||||
Pairs []AffinityRelation
|
||||
Trios []AffinityRelation
|
||||
PairMaps map[int]map[int]int
|
||||
TrioMaps map[int]map[int]map[int]int
|
||||
Count int
|
||||
MaxID int
|
||||
}{c, pairs, trios, maxid}
|
||||
}{c, pairs, trios, pm, tm, len(c), maxid}
|
||||
return t.ExecuteTemplate(w, "koka-character", &data)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user