diff options
author | Kurt Jung <kurt.w.jung@gmail.com> | 2015-10-11 21:06:01 -0400 |
---|---|---|
committer | Kurt Jung <kurt.w.jung@gmail.com> | 2015-10-11 21:06:01 -0400 |
commit | d51e132c6432f2c1bbff5d9516f77375bb5252e6 (patch) | |
tree | db0dff5f018b3ddc6fb122f09940fcd4a23a52f6 /template.go | |
parent | 13a5fda5f79f2c15eea512e6ec3de2ce60aa29ca (diff) |
Conditionally order another map iteration. Fix 'go vet' problem with unkeyed field in composite literal.
Diffstat (limited to 'template.go')
-rw-r--r-- | template.go | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/template.go b/template.go index bf25c9f..cdb1428 100644 --- a/template.go +++ b/template.go @@ -178,12 +178,34 @@ func (f *Fpdf) putTemplates() { } } +func templateKeyList(mp map[int64]Template, sort bool) (keyList []int64) { + var key int64 + for key = range mp { + keyList = append(keyList, key) + } + if sort { + gensort(len(keyList), + func(a, b int) bool { + return keyList[a] < keyList[b] + }, + func(a, b int) { + keyList[a], keyList[b] = keyList[b], keyList[a] + }) + } + return +} + // sortTemplates puts templates in a suitable order based on dependices func sortTemplates(templates map[int64]Template) []Template { chain := make([]Template, 0, len(templates)*2) // build a full set of dependency chains - for _, t := range templates { + var keyList []int64 + var key int64 + var t Template + keyList = templateKeyList(templates, true) // FIXME + for _, key = range keyList { + t = templates[key] tlist := templateChainDependencies(t) for _, tt := range tlist { if tt != nil { @@ -219,3 +241,8 @@ func templateChainDependencies(template Template) []Template { chain = append(chain, template) return chain } + +// < 0002640 31 20 31 32 20 30 20 52 0a 2f 54 50 4c 32 20 31 |1 12 0 R./TPL2 1| +// > 0002640 31 20 31 32 20 30 20 52 0a 2f 54 50 4c 31 20 31 |1 12 0 R./TPL1 1| +// < 0002650 35 20 30 20 52 0a 2f 54 50 4c 31 20 31 34 20 30 |5 0 R./TPL1 14 0| +// > 0002650 34 20 30 20 52 0a 2f 54 50 4c 32 20 31 35 20 30 |4 0 R./TPL2 15 0| |