gravatar
alpar (Alpar Juttner)
alpar@cs.elte.hu
Rename markToBottom() to dirtyTopButOne() + better doc (#174)
0 1 0
default
1 file changed with 17 insertions and 19 deletions:
↑ Collapse diff ↑
Ignore white space 48 line context
... ...
@@ -359,62 +359,61 @@
359 359
    ///Lift an active item to a higher level.
360 360

	
361 361
    ///Lift an active item to a higher level.
362 362
    ///\param i The item to be lifted. It must be active.
363 363
    ///\param new_level The new level of \c i. It must be strictly higher
364 364
    ///than the current level.
365 365
    ///
366 366
    void lift(Item i, int new_level)
367 367
    {
368 368
      const int lo = _level[i];
369 369
      const Vit w = _where[i];
370 370

	
371 371
      copy(_last_active[lo],w);
372 372
      copy(--_first[lo+1],_last_active[lo]--);
373 373
      for(int l=lo+1;l<new_level;l++)
374 374
        {
375 375
          copy(_last_active[l],_first[l]);
376 376
          copy(--_first[l+1],_last_active[l]--);
377 377
        }
378 378
      copy(i,_first[new_level]);
379 379
      _level[i]=new_level;
380 380
      if(new_level>_highest_active) _highest_active=new_level;
381 381
    }
382 382

	
383
    ///Mark the node as it did not reach the max level
383
    ///Move an inactive item to the top but one level (in a dirty way).
384 384

	
385
    ///Mark the node as it did not reach the max level. It sets the
386
    ///level to the under the max level value. The node will be never
387
    ///more activated because the push operation from the maximum
388
    ///level is forbidden in the push-relabel algorithms. The node
389
    ///should be lifted previously to the top level.
390
    void markToBottom(Item i) {
385
    ///This function moves an inactive item to the top but one level.
386
    ///It makes the underlying datastructure corrupt, so use is only if
387
    ///you really know what it is for.
388
    ///\pre The item is on the top level.
389
    void dirtyTopButOne(Item i) {
391 390
      _level[i] = _max_level - 1;
392 391
    }
393 392

	
394
    ///Lift all nodes on and above a level to the top (and deactivate them).
393
    ///Lift all items on and above a level to the top (and deactivate them).
395 394

	
396
    ///This function lifts all nodes on and above level \c l to \c
395
    ///This function lifts all items on and above level \c l to \c
397 396
    ///maxLevel(), and also deactivates them.
398 397
    void liftToTop(int l)
399 398
    {
400 399
      const Vit f=_first[l];
401 400
      const Vit tl=_first[_max_level];
402 401
      for(Vit i=f;i!=tl;++i)
403 402
        _level[*i]=_max_level;
404 403
      for(int i=l;i<=_max_level;i++)
405 404
        {
406 405
          _first[i]=f;
407 406
          _last_active[i]=f-1;
408 407
        }
409 408
      for(_highest_active=l-1;
410 409
          _highest_active>=0 &&
411 410
            _last_active[_highest_active]<_first[_highest_active];
412 411
          _highest_active--) ;
413 412
    }
414 413

	
415 414
  private:
416 415
    int _init_lev;
417 416
    Vit _init_num;
418 417

	
419 418
  public:
420 419

	
... ...
@@ -728,49 +727,49 @@
728 727
    void liftHighestActive(int new_level) {
729 728
      Item i = _first[_highest_active];
730 729
      if (_next[i] != INVALID) {
731 730
        _prev.set(_next[i], INVALID);
732 731
        _first[_highest_active] = _next[i];
733 732
      } else {
734 733
        _first[_highest_active] = INVALID;
735 734
        _last[_highest_active] = INVALID;
736 735
      }
737 736
      _level.set(i, _highest_active = new_level);
738 737
      if (_first[_highest_active] == INVALID) {
739 738
        _first[_highest_active] = _last[_highest_active] = i;
740 739
        _prev.set(i, INVALID);
741 740
        _next.set(i, INVALID);
742 741
      } else {
743 742
        _prev.set(_first[_highest_active], i);
744 743
        _next.set(i, _first[_highest_active]);
745 744
        _first[_highest_active] = i;
746 745
      }
747 746
    }
748 747

	
749 748
    ///Lift the highest active to top.
750 749

	
751 750
    ///Lift the item returned by highestActive() to the top level and
752
    ///deactivates the node.
751
    ///deactivates the item.
753 752
    ///
754 753
    void liftHighestActiveToTop() {
755 754
      Item i = _first[_highest_active];
756 755
      _level.set(i, _max_level);
757 756
      if (_next[i] != INVALID) {
758 757
        _prev.set(_next[i], INVALID);
759 758
        _first[_highest_active] = _next[i];
760 759
      } else {
761 760
        _first[_highest_active] = INVALID;
762 761
        _last[_highest_active] = INVALID;
763 762
      }
764 763
      while (_highest_active >= 0 && activeFree(_highest_active))
765 764
        --_highest_active;
766 765
    }
767 766

	
768 767
    ///@}
769 768

	
770 769
    ///\name Active Item on Certain Level
771 770
    ///Functions for working with the active items.
772 771

	
773 772
    ///@{
774 773

	
775 774
    ///Returns an active item on level \c l.
776 775

	
... ...
@@ -876,62 +875,61 @@
876 875
        _prev.set(_next[i], _prev[i]);
877 876
      } else {
878 877
        _last[new_level] = _prev[i];
879 878
      }
880 879
      if (_prev[i] != INVALID) {
881 880
        _next.set(_prev[i], _next[i]);
882 881
      } else {
883 882
        _first[new_level] = _next[i];
884 883
      }
885 884
      _level.set(i, new_level);
886 885
      if (_first[new_level] == INVALID) {
887 886
        _first[new_level] = _last[new_level] = i;
888 887
        _prev.set(i, INVALID);
889 888
        _next.set(i, INVALID);
890 889
      } else {
891 890
        _prev.set(_first[new_level], i);
892 891
        _next.set(i, _first[new_level]);
893 892
        _first[new_level] = i;
894 893
      }
895 894
      if (_highest_active < new_level) {
896 895
        _highest_active = new_level;
897 896
      }
898 897
    }
899 898

	
900
    ///Mark the node as it did not reach the max level
899
    ///Move an inactive item to the top but one level (in a dirty way).
901 900

	
902
    ///Mark the node as it did not reach the max level. It sets the
903
    ///level to the under the max level value. The node will be never
904
    ///more activated because the push operation from the maximum
905
    ///level is forbidden in the push-relabel algorithms. The node
906
    ///should be lifted previously to the top level.
907
    void markToBottom(Item i) {
901
    ///This function moves an inactive item to the top but one level.
902
    ///It makes the underlying datastructure corrupt, so use is only if
903
    ///you really know what it is for.
904
    ///\pre The item is on the top level.
905
    void dirtyTopButOne(Item i) {
908 906
      _level.set(i, _max_level - 1);
909 907
    }
910 908

	
911
    ///Lift all nodes on and above a level to the top (and deactivate them).
909
    ///Lift all items on and above a level to the top (and deactivate them).
912 910

	
913
    ///This function lifts all nodes on and above level \c l to \c
911
    ///This function lifts all items on and above level \c l to \c
914 912
    ///maxLevel(), and also deactivates them.
915 913
    void liftToTop(int l)  {
916 914
      for (int i = l + 1; _first[i] != INVALID; ++i) {
917 915
        Item n = _first[i];
918 916
        while (n != INVALID) {
919 917
          _level.set(n, _max_level);
920 918
          n = _next[n];
921 919
        }
922 920
        _first[i] = INVALID;
923 921
        _last[i] = INVALID;
924 922
      }
925 923
      if (_highest_active > l - 1) {
926 924
        _highest_active = l - 1;
927 925
        while (_highest_active >= 0 && activeFree(_highest_active))
928 926
          --_highest_active;
929 927
      }
930 928
    }
931 929

	
932 930
  private:
933 931

	
934 932
    int _init_level;
935 933

	
936 934
  public:
937 935

	
0 comments (0 inline)