| 654 | bool is_checked |
| 655 | > |
| 656 | void directed_graph_kernel_1<T,E,mem_manager,is_checked>:: |
| 657 | remove_node ( |
| 658 | unsigned long index |
| 659 | ) |
| 660 | { |
| 661 | checker::check_remove_node(index,*this); |
| 662 | |
| 663 | node_type& n = *nodes[index]; |
| 664 | |
| 665 | // remove all edges pointing to this node from its parents |
| 666 | for (unsigned long i = 0; i < n.parents.size(); ++i) |
| 667 | { |
| 668 | // remove the edge from this specific parent |
| 669 | unsigned long pos = static_cast<unsigned long>(find(n.parents[i]->children.begin(), |
| 670 | n.parents[i]->children.end(), |
| 671 | &n) - n.parents[i]->children.begin()); |
| 672 | |
| 673 | n.parents[i]->children.erase(n.parents[i]->children.begin() + pos); |
| 674 | n.parents[i]->edge_children.erase(n.parents[i]->edge_children.begin() + pos); |
| 675 | } |
| 676 | |
| 677 | // remove all edges pointing to this node from its children |
| 678 | for (unsigned long i = 0; i < n.children.size(); ++i) |
| 679 | { |
| 680 | // remove the edge from this specific child |
| 681 | unsigned long pos = static_cast<unsigned long>(find(n.children[i]->parents.begin(), |
| 682 | n.children[i]->parents.end(), |
| 683 | &n) - n.children[i]->parents.begin()); |
| 684 | |
| 685 | n.children[i]->parents.erase(n.children[i]->parents.begin() + pos); |
| 686 | n.children[i]->edge_parents.erase(n.children[i]->edge_parents.begin() + pos); |
| 687 | } |
| 688 | |
| 689 | // now remove this node by replacing it with the last node in the nodes vector |
| 690 | nodes[index] = nodes[nodes.size()-1]; |
| 691 | |
| 692 | // update the index for the node we just moved |
| 693 | nodes[index]->idx = index; |
| 694 | |
| 695 | // now remove the duplicated node at the end of the vector |
| 696 | nodes.pop_back(); |
| 697 | } |
| 698 | |
| 699 | // ---------------------------------------------------------------------------------------- |
| 700 | |