Improve Binary Tree Array by getting rid of the recursion
We use a stack instead, it’s not terribly different from the recursion but it saves function calls which use a lot more stack than needed.
This commit is contained in:
committed by
Mathias Agopian
parent
38de58007c
commit
1f3dad48b6
@@ -30,10 +30,10 @@ TEST(BinaryTreeArray, basic) {
|
||||
Node array[256];
|
||||
|
||||
BinaryTreeArray::traverse(1,
|
||||
[&array](size_t index, size_t parent, size_t col, size_t next) {
|
||||
[&array](size_t index, size_t col, size_t next) {
|
||||
array[index] = Node{ index, next };
|
||||
},
|
||||
[&array](size_t index, size_t parent, size_t l, size_t r, size_t next) {
|
||||
[&array](size_t index, size_t l, size_t r, size_t next) {
|
||||
array[index] = Node{ index, next };
|
||||
});
|
||||
|
||||
@@ -42,10 +42,10 @@ TEST(BinaryTreeArray, basic) {
|
||||
|
||||
|
||||
BinaryTreeArray::traverse(2,
|
||||
[&array](size_t index, size_t parent, size_t col, size_t next) {
|
||||
[&array](size_t index, size_t col, size_t next) {
|
||||
array[index] = Node{ index, next };
|
||||
},
|
||||
[&array](size_t index, size_t parent, size_t l, size_t r, size_t next) {
|
||||
[&array](size_t index, size_t l, size_t r, size_t next) {
|
||||
array[index] = Node{ index, next };
|
||||
});
|
||||
|
||||
@@ -60,10 +60,10 @@ TEST(BinaryTreeArray, basic) {
|
||||
|
||||
|
||||
BinaryTreeArray::traverse(3,
|
||||
[&array](size_t index, size_t parent, size_t col, size_t next) {
|
||||
[&array](size_t index, size_t col, size_t next) {
|
||||
array[index] = Node{ index, next };
|
||||
},
|
||||
[&array](size_t index, size_t parent, size_t l, size_t r, size_t next) {
|
||||
[&array](size_t index, size_t l, size_t r, size_t next) {
|
||||
array[index] = Node{ index, next };
|
||||
});
|
||||
|
||||
@@ -90,10 +90,10 @@ TEST(BinaryTreeArray, basic) {
|
||||
|
||||
|
||||
BinaryTreeArray::traverse(4,
|
||||
[&array](size_t index, size_t parent, size_t col, size_t next) {
|
||||
[&array](size_t index, size_t col, size_t next) {
|
||||
array[index] = Node{ index, next };
|
||||
},
|
||||
[&array](size_t index, size_t parent, size_t l, size_t r, size_t next) {
|
||||
[&array](size_t index, size_t l, size_t r, size_t next) {
|
||||
array[index] = Node{ index, next };
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user