src/lemon/unionfind.h
changeset 1339 26a88d12d1a6
parent 1164 80bb73097736
child 1359 1581f961cfaa
equal deleted inserted replaced
1:75e6085764ec 2:f686f688bd95
    96 
    96 
    97       return comp;
    97       return comp;
    98     }
    98     }
    99 
    99 
   100     /**
   100     /**
   101      * \brief Insert a new element into the structure.
   101      * \brief Inserts a new element into the structure.
   102      *
   102      *
   103      * This method inserts a new element into the data structure. 
   103      * This method inserts a new element into the data structure. 
   104      *
   104      *
   105      * It is not required to use this method:
   105      * It is not required to use this method:
   106      * if the map given to the constructor was filled 
   106      * if the map given to the constructor was filled 
   120 
   120 
   121     /**
   121     /**
   122      * \brief Joining the components of element \e a and element \e b.
   122      * \brief Joining the components of element \e a and element \e b.
   123      *
   123      *
   124      * This is the \e union operation of the Union-Find structure. 
   124      * This is the \e union operation of the Union-Find structure. 
   125      * Joins the component of elemenent \e a and component of
   125      * Joins the component of element \e a and component of
   126      * element \e b. If \e a and \e b are in the same component then
   126      * element \e b. If \e a and \e b are in the same component then
   127      * it returns false otherwise it returns true.
   127      * it returns false otherwise it returns true.
   128      */
   128      */
   129 
   129 
   130     bool join(T a, T b)
   130     bool join(T a, T b)
   261   public:
   261   public:
   262     UnionFindEnum(MapType& _m) : m(_m) {}
   262     UnionFindEnum(MapType& _m) : m(_m) {}
   263 
   263 
   264 
   264 
   265     /**
   265     /**
   266      * \brief Insert the given element into a new component.
   266      * \brief Inserts the given element into a new component.
   267      *
   267      *
   268      * This method creates a new component consisting only of the
   268      * This method creates a new component consisting only of the
   269      * given element.
   269      * given element.
   270      */
   270      */
   271 
   271 
   285       m.set(a, ai);
   285       m.set(a, ai);
   286 
   286 
   287     }
   287     }
   288 
   288 
   289     /**
   289     /**
   290      * \brief Insert the given element into the component of the others.
   290      * \brief Inserts the given element into the component of the others.
   291      *
   291      *
   292      * This methods insert the element \e a into the component of the
   292      * This methods inserts the element \e a into the component of the
   293      * element \e comp. 
   293      * element \e comp. 
   294      */
   294      */
   295 
   295 
   296     void insert(const T &a, const T &comp) {
   296     void insert(const T &a, const T &comp) {
   297       
   297       
   305       ++clit->size;
   305       ++clit->size;
   306     }
   306     }
   307 
   307 
   308 
   308 
   309     /**
   309     /**
   310      * \brief Find the leader of the component of the given element.
   310      * \brief Finds the leader of the component of the given element.
   311      *
   311      *
   312      * The method returns the leader of the component of the given element.
   312      * The method returns the leader of the component of the given element.
   313      */
   313      */
   314 
   314 
   315     T find(const T &a) const {
   315     T find(const T &a) const {
   319 
   319 
   320     /**
   320     /**
   321      * \brief Joining the component of element \e a and element \e b.
   321      * \brief Joining the component of element \e a and element \e b.
   322      *
   322      *
   323      * This is the \e union operation of the Union-Find structure. 
   323      * This is the \e union operation of the Union-Find structure. 
   324      * Joins the component of elemenent \e a and component of
   324      * Joins the component of element \e a and component of
   325      * element \e b. If \e a and \e b are in the same component then
   325      * element \e b. If \e a and \e b are in the same component then
   326      * returns false else returns true.
   326      * returns false else returns true.
   327      */
   327      */
   328 
   328 
   329     bool join(T a, T b) {
   329     bool join(T a, T b) {
   372       return _find(m[a])->size;
   372       return _find(m[a])->size;
   373     }
   373     }
   374 
   374 
   375 
   375 
   376     /**
   376     /**
   377      * \brief Split up the component of the element. 
   377      * \brief Splits up the component of the element. 
   378      *
   378      *
   379      * Splitting the component of the element into sigleton
   379      * Splitting the component of the element into sigleton
   380      * components (component of size one).
   380      * components (component of size one).
   381      */
   381      */
   382 
   382 
   403       return;
   403       return;
   404     }
   404     }
   405 
   405 
   406 
   406 
   407     /**
   407     /**
   408      * \brief Set the given element to the leader element of its component.
   408      * \brief Sets the given element to the leader element of its component.
   409      *
   409      *
   410      * Set the given element to the leader element of its component.
   410      * Sets the given element to the leader element of its component.
   411      */
   411      */
   412 
   412 
   413     void makeRep(const T &a) {
   413     void makeRep(const T &a) {
   414 
   414 
   415       IIter ia = m[a];
   415       IIter ia = m[a];
   427       ia->parent = ia;
   427       ia->parent = ia;
   428       la->parent = ia;
   428       la->parent = ia;
   429     }
   429     }
   430 
   430 
   431     /**
   431     /**
   432      * \brief Move the given element to an other component.
   432      * \brief Moves the given element to an other component.
   433      *
   433      *
   434      * This method moves the element \e a from its component
   434      * This method moves the element \e a from its component
   435      * to the component of \e comp.
   435      * to the component of \e comp.
   436      * If \e a and \e comp are in the same component then
   436      * If \e a and \e comp are in the same component then
   437      * it returns false otherwise it returns true.
   437      * it returns false otherwise it returns true.
   481       return true;
   481       return true;
   482     }
   482     }
   483 
   483 
   484 
   484 
   485     /**
   485     /**
   486      * \brief Remove the given element from the structure.
   486      * \brief Removes the given element from the structure.
   487      *
   487      *
   488      * Remove the given element from the structure.
   488      * Removes the given element from the structure.
   489      *
   489      *
   490      * Removes the element from its component and if the component becomes
   490      * Removes the element from its component and if the component becomes
   491      * empty then removes that component from the component list.
   491      * empty then removes that component from the component list.
   492      */
   492      */
   493     void erase(const T &a) {
   493     void erase(const T &a) {