diff --git a/aql/hierarchy.go b/aql/hierarchy.go index dbd25b4ff01b388bd56abba1e9d27718009dd69a..dcbb96b2304c07e42e4bc85288c2726bb9f59930 100644 --- a/aql/hierarchy.go +++ b/aql/hierarchy.go @@ -391,7 +391,7 @@ func AddFilters(JSONQuery *entity.IncomingQueryJSON) { func addOneFilter(filterPDict pdict, JSONQuery *entity.IncomingQueryJSON, p pdict, filterDone *[]bool) { if p.typename == "filter" && (*filterDone)[p.pointer] { l := FindCurrentLayer(listoflists, p) - k := [1]pdict{} + k := []pdict{} if len(listoflists) > l+1 && listoflists[l+1][0].typename == "filter" { listoflists[l+1] = append(listoflists[l+1], filterPDict) } else { @@ -405,7 +405,7 @@ func addOneFilter(filterPDict pdict, JSONQuery *entity.IncomingQueryJSON, p pdic } addOneFilter(p, JSONQuery, pnew, filterDone) l := FindCurrentLayer(listoflists, p) - k := [1]pdict{filterPDict} + k := []pdict{filterPDict} if len(listoflists) > l+1 && listoflists[l+1][0].typename == "filter" { listoflists[l+1] = append(listoflists[l+1], filterPDict) } else { @@ -414,7 +414,7 @@ func addOneFilter(filterPDict pdict, JSONQuery *entity.IncomingQueryJSON, p pdic (*filterDone)[filterPDict.pointer] = true } else { l := FindCurrentLayer(listoflists, p) - k := [1]pdict{filterPDict} + k := []pdict{filterPDict} if len(listoflists) > l+1 && listoflists[l+1][0].typename == "filter" { listoflists[l+1] = append(listoflists[l+1], filterPDict) } else { @@ -424,16 +424,22 @@ func addOneFilter(filterPDict pdict, JSONQuery *entity.IncomingQueryJSON, p pdic } } -// TODO -// Write a function that appends 1 level above -func AboveAppend() { - +// A function that appends 1 level above (if index is 0 this won't work) +func AboveAppend(index int, value []pdict) [][]pdict { + if index == 0 { + return prepend(listoflists, value) + } + return BelowAppend(index-1, value) } -// TODO -// Write a function that appends 1 level below -func BelowAppend() { - +// 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) + } + listoflists = append(listoflists[:index+1], listoflists[index:]...) // index < len(a) + listoflists[index] = value + return listoflists } // A simple double-for loop that finds the layer in which an element resides in the hierarchy