parent function doesn't work

thread
Brett 2024-08-13 17:30:48 -04:00
parent 804378f2a6
commit a43922589f
2 changed files with 8 additions and 10 deletions

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.25) cmake_minimum_required(VERSION 3.25)
project(blt-gp VERSION 0.0.141) project(blt-gp VERSION 0.0.142)
include(CTest) include(CTest)

View File

@ -225,24 +225,22 @@ namespace blt::gp
return index; return index;
} }
// this function doesn't work!
blt::ptrdiff_t tree_t::find_parent(gp_program& program, blt::ptrdiff_t index) const blt::ptrdiff_t tree_t::find_parent(gp_program& program, blt::ptrdiff_t index) const
{ {
if (index == 0) blt::i64 children_left = 0;
return 0;
blt::i64 children_left = 1;
// move to the left
--index;
do do
{ {
if (index == 0)
return 0;
const auto& type = program.get_operator_info(operations[index].id); const auto& type = program.get_operator_info(operations[index].id);
BLT_TRACE_STREAM << "Operating on index " << index << " with children left: " << children_left << " and argc = " << type.argc.argc << "\n";
--index;
if (type.argc.argc > 0) if (type.argc.argc > 0)
children_left -= type.argc.argc; children_left -= type.argc.argc;
children_left++;
if (children_left <= 0) if (children_left <= 0)
break; break;
children_left++; --index;
} while (children_left > 0); } while (true);
return index; return index;
} }