Skip to content
Snippets Groups Projects
Commit 0d763185 authored by Jonge,J. de (Joes)'s avatar Jonge,J. de (Joes)
Browse files

belowappend changed with copy

parent 6129692e
No related branches found
No related tags found
1 merge request!1Big merge
......@@ -395,7 +395,7 @@ func addOneFilter(filterPDict pdict, JSONQuery *entity.IncomingQueryJSON, p pdic
if len(listoflists) > l+1 && listoflists[l+1][0].typename == "filter" {
listoflists[l+1] = append(listoflists[l+1], filterPDict)
} else {
BelowAppend(l, k)
listoflists = BelowAppend(listoflists, l, k)
}
(*filterDone)[filterPDict.pointer] = true
} else if p.typename == "filter" {
......@@ -409,7 +409,7 @@ func addOneFilter(filterPDict pdict, JSONQuery *entity.IncomingQueryJSON, p pdic
if len(listoflists) > l+1 && listoflists[l+1][0].typename == "filter" {
listoflists[l+1] = append(listoflists[l+1], filterPDict)
} else {
BelowAppend(l, k)
listoflists = BelowAppend(listoflists, l, k)
}
(*filterDone)[filterPDict.pointer] = true
} else {
......@@ -418,28 +418,31 @@ func addOneFilter(filterPDict pdict, JSONQuery *entity.IncomingQueryJSON, p pdic
if len(listoflists) > l+1 && listoflists[l+1][0].typename == "filter" {
listoflists[l+1] = append(listoflists[l+1], filterPDict)
} else {
BelowAppend(l, k)
listoflists = BelowAppend(listoflists, l, k)
}
(*filterDone)[filterPDict.pointer] = true
}
}
// A function that appends 1 level above (if index is 0 this won't work)
func AboveAppend(index int, value []pdict) [][]pdict {
func AboveAppend(list [][]pdict, index int, value []pdict) [][]pdict {
if index == 0 {
return prepend(listoflists, value)
return prepend(list, value)
}
return BelowAppend(index-1, value)
return BelowAppend(list, index-1, value)
}
// A function that appends 1 level below (thanks to wasmup on stackoverflow)
func BelowAppend(index int, value []pdict) [][]pdict {
if len(listoflists) == index { // nil or empty slice or after last element
return append(listoflists, value)
func BelowAppend(lists [][]pdict, index int, value []pdict) [][]pdict {
if len(lists)-1 == index { // nil or empty slice or after last element
return append(lists, value)
}
listoflists = append(listoflists[:index+1], listoflists[index:]...) // index < len(a)
listoflists[index] = value
return listoflists
k := make([][]pdict, len(lists[index+1:]))
copy(k, lists[index+1:])
l := make([][]pdict, len(lists[:index+1]))
copy(l, lists[:index+1])
lists = append(l, value) // index < len(a)
return append(lists, k...)
}
// A simple double-for loop that finds the layer in which an element resides in the hierarchy
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment