Skip to content

Commit 1d6355a

Browse files
allow to retrieve subtree of parent
1 parent 2164d55 commit 1d6355a

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

plugins/clock_tree_extractor/include/clock_tree_extractor/clock_tree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ namespace hal
7474

7575
Result<std::monostate> export_dot( const std::string &pathname ) const;
7676

77-
Result<std::unique_ptr<ClockTree>> get_subtree( const void *ptr ) const;
77+
Result<std::unique_ptr<ClockTree>> get_subtree( const void *ptr, const bool parent ) const;
7878

7979
Result<igraph_integer_t> get_vertex_from_ptr( const void *ptr ) const;
8080

plugins/clock_tree_extractor/python/python_bindings.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,10 @@ namespace hal
127127
R"()" )
128128
.def(
129129
"get_subtree",
130-
[]( const cte::ClockTree &self, const void *ptr ) -> std::unique_ptr<cte::ClockTree> {
131-
auto result = self.get_subtree( ptr );
130+
[]( const cte::ClockTree &self,
131+
const void *ptr,
132+
const bool parent ) -> std::unique_ptr<cte::ClockTree> {
133+
auto result = self.get_subtree( ptr, parent );
132134
if( result.is_ok() )
133135
{
134136
return result.get();
@@ -138,6 +140,7 @@ namespace hal
138140
return nullptr;
139141
},
140142
py::arg( "ptr" ),
143+
py::arg( "parent" ) = false,
141144
py::return_value_policy::move,
142145
R"()" )
143146
.def(

plugins/clock_tree_extractor/src/clock_tree.cpp

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -469,17 +469,39 @@ namespace hal
469469
return OK( {} );
470470
}
471471

472-
Result<std::unique_ptr<ClockTree>> ClockTree::get_subtree( const void *ptr ) const
472+
Result<std::unique_ptr<ClockTree>> ClockTree::get_subtree( const void *ptr, const bool parent ) const
473473
{
474474
auto it = m_ptrs_to_vertices.find( ptr );
475475
if( it == m_ptrs_to_vertices.end() )
476476
{
477477
return ERR( "object is not part of clock tree" );
478478
}
479479

480-
const igraph_integer_t root = it->second;
481-
482480
igraph_error_t ierror;
481+
igraph_integer_t root = it->second;
482+
if( parent )
483+
{
484+
igraph_vector_int_t parents;
485+
if( ( ierror = igraph_vector_int_init( &parents, 0 ) ) != IGRAPH_SUCCESS )
486+
{
487+
return ERR( igraph_strerror( ierror ) );
488+
}
489+
490+
if( ( ierror = igraph_neighbors( m_igraph_ptr, &parents, root, IGRAPH_IN ) ) != IGRAPH_SUCCESS )
491+
{
492+
igraph_vector_int_destroy( &parents );
493+
return ERR( igraph_strerror( ierror ) );
494+
}
495+
496+
// Only accept, if there is only one parent vertex for now.
497+
if( igraph_vector_int_size( &parents ) == 1 )
498+
{
499+
root = VECTOR( parents )[0];
500+
}
501+
502+
igraph_vector_int_destroy( &parents );
503+
}
504+
483505
igraph_vector_int_t vertices;
484506
if( ( ierror = igraph_vector_int_init( &vertices, 0 ) ) != IGRAPH_SUCCESS )
485507
{
@@ -638,9 +660,3 @@ namespace hal
638660
}
639661
} // namespace cte
640662
} // namespace hal
641-
642-
// BUG: looks like ~20 vertices plus their edges are missing in benchmark
643-
// TODO: investigate possible BUG
644-
645-
// BUG: subtree is wrong
646-
// TODO: investigate why? Probably mapping is broken

0 commit comments

Comments
 (0)