Mercurial > gemma
changeset 4643:a1a9b1eab57c stree-experiment
Use append/slicing trick to simplify tree traversals.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 11 Oct 2019 23:46:35 +0200 |
parents | b5d9647c5bc1 |
children | 486495590483 89a72e0e2f9b |
files | pkg/octree/strtree.go |
diffstat | 1 files changed, 4 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/octree/strtree.go Fri Oct 11 23:36:28 2019 +0200 +++ b/pkg/octree/strtree.go Fri Oct 11 23:46:35 2019 +0200 @@ -127,12 +127,8 @@ s.allTriangles(top, removed) default: // mixed bag - // TODO slicing like: - // n := s.index[top+1] - // stack = append(stack, s.index[top+2:top+2+n]...) - for i, n := int32(0), s.index[top+1]; i < n; i++ { - stack = append(stack, s.index[top+2+i]) - } + n := s.index[top+1] + stack = append(stack, s.index[top+2:top+2+n]...) } } else { // leaf top = -top - 1 @@ -160,9 +156,8 @@ top := stack[len(stack)-1] stack = stack[:len(stack)-1] if top > 0 { // node - for i, n := int32(0), s.index[top+1]; i < n; i++ { - stack = append(stack, s.index[top+2+i]) - } + n := s.index[top+1] + stack = append(stack, s.index[top+2:top+2+n]...) } else { // leaf top = -top - 1 for i, n := int32(0), s.index[top+1]; i < n; i++ {