gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Bug fix in SmartGraph::restoreSnapshot() (#171)
0 1 0
default
1 file changed with 2 insertions and 2 deletions:
↑ Collapse diff ↑
Ignore white space 96 line context
... ...
@@ -685,98 +685,98 @@
685 685
    ///
686 686
    /// This function gives back true if the given arc is valid,
687 687
    /// ie. it is a real arc of the graph.
688 688
    ///
689 689
    /// \warning A removed arc (using Snapshot) could become valid again
690 690
    /// when new edges are added to the graph.
691 691
    bool valid(Arc a) const { return Parent::valid(a); }
692 692

	
693 693
    /// \brief Edge validity check
694 694
    ///
695 695
    /// This function gives back true if the given edge is valid,
696 696
    /// ie. it is a real edge of the graph.
697 697
    ///
698 698
    /// \warning A removed edge (using Snapshot) could become valid again
699 699
    /// when new edges are added to the graph.
700 700
    bool valid(Edge e) const { return Parent::valid(e); }
701 701

	
702 702
    ///Clear the graph.
703 703

	
704 704
    ///Erase all the nodes and edges from the graph.
705 705
    ///
706 706
    void clear() {
707 707
      Parent::clear();
708 708
    }
709 709

	
710 710
  public:
711 711

	
712 712
    class Snapshot;
713 713

	
714 714
  protected:
715 715

	
716 716
    void saveSnapshot(Snapshot &s)
717 717
    {
718 718
      s._graph = this;
719 719
      s.node_num = nodes.size();
720 720
      s.arc_num = arcs.size();
721 721
    }
722 722

	
723 723
    void restoreSnapshot(const Snapshot &s)
724 724
    {
725 725
      while(s.arc_num<arcs.size()) {
726 726
        int n=arcs.size()-1;
727 727
        Edge arc=edgeFromId(n/2);
728 728
        Parent::notifier(Edge()).erase(arc);
729 729
        std::vector<Arc> dir;
730 730
        dir.push_back(arcFromId(n));
731 731
        dir.push_back(arcFromId(n-1));
732 732
        Parent::notifier(Arc()).erase(dir);
733
        nodes[arcs[n].target].first_out=arcs[n].next_out;
734
        nodes[arcs[n-1].target].first_out=arcs[n-1].next_out;
733
        nodes[arcs[n-1].target].first_out=arcs[n].next_out;
734
        nodes[arcs[n].target].first_out=arcs[n-1].next_out;
735 735
        arcs.pop_back();
736 736
        arcs.pop_back();
737 737
      }
738 738
      while(s.node_num<nodes.size()) {
739 739
        int n=nodes.size()-1;
740 740
        Node node = nodeFromId(n);
741 741
        Parent::notifier(Node()).erase(node);
742 742
        nodes.pop_back();
743 743
      }
744 744
    }
745 745

	
746 746
  public:
747 747

	
748 748
    ///Class to make a snapshot of the digraph and to restrore to it later.
749 749

	
750 750
    ///Class to make a snapshot of the digraph and to restrore to it later.
751 751
    ///
752 752
    ///The newly added nodes and arcs can be removed using the
753 753
    ///restore() function.
754 754
    ///
755 755
    ///\note After you restore a state, you cannot restore
756 756
    ///a later state, in other word you cannot add again the arcs deleted
757 757
    ///by restore() using another one Snapshot instance.
758 758
    ///
759 759
    ///\warning If you do not use correctly the snapshot that can cause
760 760
    ///either broken program, invalid state of the digraph, valid but
761 761
    ///not the restored digraph or no change. Because the runtime performance
762 762
    ///the validity of the snapshot is not stored.
763 763
    class Snapshot
764 764
    {
765 765
      SmartGraph *_graph;
766 766
    protected:
767 767
      friend class SmartGraph;
768 768
      unsigned int node_num;
769 769
      unsigned int arc_num;
770 770
    public:
771 771
      ///Default constructor.
772 772

	
773 773
      ///Default constructor.
774 774
      ///To actually make a snapshot you must call save().
775 775
      ///
776 776
      Snapshot() : _graph(0) {}
777 777
      ///Constructor that immediately makes a snapshot
778 778

	
779 779
      ///This constructor immediately makes a snapshot of the digraph.
780 780
      ///\param graph The digraph we make a snapshot of.
781 781
      Snapshot(SmartGraph &graph) {
782 782
        graph.saveSnapshot(*this);
0 comments (0 inline)