Example #1
0
 void ColumnSet::AccumulateMasterColumns()
 {
     DCHECK(master_columns_.empty());
     for(std::vector<Column*>::iterator i=columns_.begin();
         i!=columns_.end(); ++i)
     {
         Column* column = *i;
         Column* master_column = column->GetLastMasterColumn();
         if(master_column && find(master_columns_.begin(),
             master_columns_.end(), master_column)==master_columns_.end())
         {
             master_columns_.push_back(master_column);
         }
         // At this point, GetLastMasterColumn may not == master_column
         // (may have to go through a few Columns)_. Reset master_column to
         // avoid hops.
         column->master_column_ = master_column;
     }
 }
Example #2
0
 void ColumnSet::CalculateMasterColumns()
 {
     for(std::vector<Column*>::iterator i=columns_.begin();
         i!=columns_.end(); ++i)
     {
         Column* column = *i;
         int same_size_column_index = column->same_size_column_;
         if(same_size_column_index != -1)
         {
             DCHECK(same_size_column_index>=0 &&
                 same_size_column_index<static_cast<int>(columns_.size()));
             Column* master_column = column->master_column_;
             Column* same_size_column = columns_[same_size_column_index];
             Column* same_size_column_master = same_size_column->master_column_;
             if(master_column == NULL)
             {
                 // Current column is not linked to any other column.
                 if(same_size_column_master == NULL)
                 {
                     // Both columns are not linked.
                     column->master_column_ = column;
                     same_size_column->master_column_ = column;
                     column->same_size_columns_.push_back(same_size_column);
                     column->same_size_columns_.push_back(column);
                 }
                 else
                 {
                     // Column to link to is linked with other columns.
                     // Add current column to list of linked columns in other columns
                     // master column.
                     same_size_column->GetLastMasterColumn()->
                         same_size_columns_.push_back(column);
                     // And update the master column for the current column to that
                     // of the same sized column.
                     column->master_column_ = same_size_column;
                 }
             }
             else
             {
                 // Current column is already linked with another column.
                 if(same_size_column_master == NULL)
                 {
                     // Column to link with is not linked to any other columns.
                     // Update it's master_column.
                     same_size_column->master_column_ = column;
                     // Add linked column to list of linked column.
                     column->GetLastMasterColumn()->same_size_columns_.
                         push_back(same_size_column);
                 }
                 else if(column->GetLastMasterColumn() !=
                     same_size_column->GetLastMasterColumn())
                 {
                     // The two columns are already linked with other columns.
                     std::vector<Column*>* same_size_columns =
                         &(column->GetLastMasterColumn()->same_size_columns_);
                     std::vector<Column*>* other_same_size_columns =
                         &(same_size_column->GetLastMasterColumn()->same_size_columns_);
                     // Add all the columns from the others master to current columns
                     // master.
                     same_size_columns->insert(same_size_columns->end(),
                         other_same_size_columns->begin(),
                         other_same_size_columns->end());
                     // The other master is no longer a master, clear its vector of
                     // linked columns, and reset its master_column.
                     other_same_size_columns->clear();
                     same_size_column->GetLastMasterColumn()->master_column_ = column;
                 }
             }
         }
     }
     AccumulateMasterColumns();
 }