33#include < cassert>
44#include < cstring>
55
6- #include " ipm/hipo/auxiliary/Auxiliary.h"
7-
86namespace hipo {
97
108void CliqueStack::init (Int64 stack_size) {
11- stack_size = sizeAtLeastOne (stack_size);
12-
13- stack_.resize (stack_size, 0.0 );
149 top_ = 0 ;
1510 workspace_ = nullptr ;
1611 worksize_ = 0 ;
12+ empty_ = false ;
13+
14+ stack_.resize (stack_size, 0.0 );
1715}
1816
1917double * CliqueStack::setup (Int64 clique_size, bool & reallocation) {
@@ -22,23 +20,25 @@ double* CliqueStack::setup(Int64 clique_size, bool& reallocation) {
2220 assert (!workspace_ && !worksize_);
2321 reallocation = false ;
2422
25- // This should not trigger reallocation, because the resize in init is done
26- // with the maximum possible size of the stack.
27- if (top_ + clique_size > stack_.size ()) {
28- reallocation = true ;
29- stack_.resize (top_ + clique_size, 0.0 );
30- }
23+ if (stack_.size () > 0 ) {
24+ // This should not trigger reallocation, because the resize in init is done
25+ // with the maximum possible size of the stack.
26+ if (top_ + clique_size > stack_.size ()) {
27+ reallocation = true ;
28+ stack_.resize (top_ + clique_size, 0.0 );
29+ }
3130
32- workspace_ = &stack_[top_];
33- worksize_ = clique_size;
31+ workspace_ = &stack_[top_];
32+ worksize_ = clique_size;
3433
35- // initialize workspace to zero
36- std::memset (workspace_, 0 , worksize_ * sizeof (double ));
34+ // initialize workspace to zero
35+ std::memset (workspace_, 0 , worksize_ * sizeof (double ));
36+ }
3737
3838 return workspace_;
3939}
4040
41- bool CliqueStack::empty () const { return stack_. empty () ; }
41+ bool CliqueStack::empty () const { return empty_ ; }
4242
4343const double * CliqueStack::getChild (Int& child_sn) const {
4444 // Get the top of the stack, in terms of supernode ID of the child and pointer
@@ -63,14 +63,16 @@ void CliqueStack::popChild() {
6363void CliqueStack::pushWork (Int sn) {
6464 // Put the content of the workspace at the top of the stack
6565
66- // stack_[top_] has lower address than workspace, so no need to resize.
67- // workspace_ and stack_[top_] do not overlap, so use memcpy
68- std::memcpy (&stack_[top_], workspace_, worksize_ * sizeof (double ));
66+ if (stack_.size () > 0 ) {
67+ // stack_[top_] has lower address than workspace, so no need to resize.
68+ // workspace_ and stack_[top_] do not overlap, so use memcpy
69+ std::memcpy (&stack_[top_], workspace_, worksize_ * sizeof (double ));
6970
70- top_ += worksize_;
71+ top_ += worksize_;
7172
72- // keep track of supernodes pushed
73- sn_pushed_.push ({sn, worksize_});
73+ // keep track of supernodes pushed
74+ sn_pushed_.push ({sn, worksize_});
75+ }
7476
7577 worksize_ = 0 ;
7678 workspace_ = nullptr ;
0 commit comments