runtime - C++ Run time efficiency -


I am creating a hex board from the nodes. In some of this code, anything works for me. My problem is that starred item slows down this loop from 1 second to 1 minute. This vector does not have the number of objects, because if I remove the last one except those that still take 1 minute. There are errors in either way of not running a path

 for  (x = 0; x  Nodes [x] [y] .neighbors = std :: vector & lt; Node & gt; (6); If ((x == 0) & amp; (y == 0)) {this-> Nodes [x] [y] Navy = {nodes [x + 1] [y], this-> nodes [x] [y + 1]}; } And if ((x == 0) & amp; amp;; (y == max)) {this-> Nodes [x] [y] Neighbors = {This- & gt; Nodes [x + 1] [y], this-> nodes [x] [y - 1], this-> nodes [x + 1] [y - 1]}; } And if ((x == max) & amp;; (y == 0)) {this-> Nodes [x] [y] Neighbors = {This- & gt; Nodes [x - 1] [y], this-> nodes [x] [y + 1], this-> nodes [x - 1] [y + 1]}; } And if ((x == max)) & amp; Amp;; (Y == max)) {it-> Nodes [x] [y] Despicable = {is-> nodes [x - 1] [y], this-> Nodes [x] [y - 1]}; } And if (y == 0 & amp; amp; (x! = 0 & amp;; x! = Max)) {This-> Nodes [x] [y] Lower = {is-> nodes [x - 1] [or], this-> nodes [x + 1] [y], this-> nodes [x - 1] [y + 1], this-> nodes [x] ] [Y + 1]}; } And if (y == Max & amp; (x! = 0 & amp;; x! = Max)) {This-> Nodes [x] [y] Navy = {is-> nodes [x - 1] [or], this-> nodes [x + 1] [y], this-> Nodes [x - 1] [y - 1], this-> Nodes [x] [y - 1]}; } And if (x == 0 & amp; y; = 0 & amp; y! = Max)) {this-> Nodes [x] [y] Navy = {is-> nodes [x] [y - 1], this-> nodes [x] [y + 1], it-> nodes [x + 1] [y], this-> nodes [x + 1 ] [Y - 1]}; } And if (x == max & amp; (y! = 0 & amp;; y! = Max)) {this-> Nodes [x] [y] Navy = {is-> nodes [x] [y - 1], this-> nodes [x] [y + 1], this-> Nodes [x - 1] [y - 1], this-> nodes [x - 1] [y]}; } Other {this-> Nodes [x] [y] Navy = {This- & gt; Nodes [x + 1] [y], it-> nodes [x - 1] [y], this-> Nodes [x] [y - 1], this-> Nodes [x + 1] [y - 1], this-> nodes [x] [y + 1], this-> Nodes [x - 1] [Y + 1]}; Looking at this idea, you have to track the neighbor, which you know has been pre-established. Created, you probably only want to keep them reference or indicators; You can not copy    node  s value  . 

You can enter vector & lt; Context_weep & lt; Node & gt; & Gt; or vector & lt; Node *> , with related initialization in this way:

  nodes [x] [y]. = {Ref (nodes [a] [b]), referee (nodes [c] [d]) ...}; Nodes [x] [y] Niibers = {& amp; Nodes [a] [b], and nodes [c] [d], ...};  

With Pointer, when you reach Neighbors [n] , you should explicitly remove the indicator too.

Why it was so slow about ... copying the meaning of copy by copying node s to neighbors , all those neighboring Node was making copies of neighbors and their neighbors, for a long time the number of nodes is increasing with neighboring hierarchies.


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -