示例#1
0
        bool operator()(GroupType const& x, GroupType const& y) const {
            if (x->empty() || y->empty())
                return true; // doesn't matter if one or both are empty;

            if ((*x)[0]->start() < (*y)[0]->start())
                return true;

            if ((*x)[0]->start() > (*y)[0]->start())
                return false;

            return (*x)[0]->stop() < (*y)[0]->stop();
        }
示例#2
0
      /**
       * Inserts a pair of disjoint elements. Determines whether they can be used to reorder existing sets of lables.
       * @param a : One part of pair
       * @param b : Other part of pair
       * @return : true if a new cluster was required for the insertion.
       */
      bool insert(const DisjointElement& a, const DisjointElement& b)
      {
        const size_t& aLabel = a.getRoot();
        const size_t& bLabel = b.getRoot();
        bool newItem = true;

        GroupType containingAny;
        GroupType containingNone;
        // ------------- Find equivalent sets
        for(GroupType::iterator i = m_groups.begin(); i != m_groups.end(); ++i)
        {
          GroupType::value_type& cluster =*i;
          if(cluster.find(aLabel) != cluster.end())
          {
            containingAny.push_back(cluster);
          }
          else if(cluster.find(bLabel) != cluster.end())
          {
            containingAny.push_back(cluster);
          }
          else
          {
            containingNone.push_back(cluster); // Current iterated set contains NEITHER of these labels. It can therfore be ignored.
          }
        }
        // ------------ Process equivalent sets
        if(containingAny.empty())
        {
          // Neither label is yet known to any set. We must add a new set for these
          GroupType::value_type newSet;
          newSet.insert(aLabel);
          newSet.insert(bLabel);
          m_groups.push_back(newSet);
        }
        else
        {
          // At least one set already contains at least one label. We merge all such sets into a master set.

          // implement copy and swap. Rebuild the sets.
          GroupType temp = containingNone;
          GroupType::value_type masterSet;
          masterSet.insert(aLabel); // Incase it doesn't already contain a
          masterSet.insert(bLabel); // Incase it doesn't already contain b
          for(auto i = containingAny.begin(); i != containingAny.end(); ++i)
          {
            GroupType::value_type& childSet = *i;
            masterSet.insert(childSet.begin(), childSet.end()); // Build the master set.
          }
          temp.push_back(masterSet);
          m_groups = temp; // Swap.
          newItem = false;
        }
        return newItem;
      }