Skip to content

Commit ef87557

Browse files
committed
upd: moved functionality to get number of children to its own function
1 parent 69e37c3 commit ef87557

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/node.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,14 @@ impl Node {
4444
}
4545
}
4646

47+
/// Returns the number of children of the node.
48+
pub fn n_children(&self) -> usize {
49+
unsafe { ffi::SCIPgetNChildren(self.scip.raw) as usize }
50+
}
51+
4752
/// Returns the children of the node.
4853
pub fn children(&self) -> Option<Vec<Node>> {
49-
let num_children = unsafe { ffi::SCIPgetNChildren(self.scip.raw) };
54+
let num_children = self.n_children();
5055
if num_children == 0 {
5156
return None;
5257
}
@@ -55,9 +60,9 @@ impl Node {
5560
unsafe {
5661
ffi::SCIPgetChildren(self.scip.raw, &mut child_nodes_ptr, std::ptr::null_mut());
5762
}
58-
let child_nodes_slice = unsafe{std::slice::from_raw_parts(child_nodes_ptr, num_children as usize)};
63+
let child_nodes_slice = unsafe{std::slice::from_raw_parts(child_nodes_ptr, num_children)};
5964
// put into a Vec and transform to Node
60-
let mut children_vec = Vec::with_capacity(num_children as usize);
65+
let mut children_vec = Vec::with_capacity(num_children);
6166
for child in child_nodes_slice {
6267
children_vec.push(Node{
6368
raw: *child,

0 commit comments

Comments
 (0)