Exemple #1
0
void get_involved_parts(
    const PartVector & union_parts,
    const Bucket & candidate,
    PartVector & involved_parts
    )
{
  involved_parts.clear();
  if (union_parts.size() == 0) {
    return;
  }

  // Used to convert part ordinals to part pointers:
  MetaData & meta_data = MetaData::get( * union_parts[0]);
  const PartVector & all_parts = meta_data.get_parts();

  const std::pair<const unsigned *,const unsigned *>
    bucket_part_begin_end_iterators = candidate.superset_part_ordinals(); // sorted and unique

  std::vector<unsigned> union_parts_ids;
  copy_ids( union_parts_ids , union_parts ); // sorted and unique
  std::vector<unsigned>::const_iterator union_part_id_it = union_parts_ids.begin();
  const unsigned * bucket_part_id_it = bucket_part_begin_end_iterators.first ;

  while ( union_part_id_it != union_parts_ids.end() &&
          bucket_part_id_it != bucket_part_begin_end_iterators.second )
  {
    if      ( *union_part_id_it  < *bucket_part_id_it ) {
      ++union_part_id_it ;
    }
    else if ( *bucket_part_id_it < *union_part_id_it )  {
      ++bucket_part_id_it ;
    }
    else {
      // Find every match:
      Part * const part = all_parts[ *union_part_id_it ];
      involved_parts.push_back( part );
      ++union_part_id_it;
      ++bucket_part_id_it;
    }
  }

}