size_t intersect( const PartVector & v , const PartVector & p , PartVector & r ) { // Both lists must be sorted, assume v.size() > p.size() const PartVector::const_iterator ev = v.end(); PartVector::const_iterator iv = v.begin(); const PartVector::const_iterator ep = p.end(); PartVector::const_iterator ip = p.begin(); for ( ; ip != ep && iv != ev ; ++ip ) { Part * const q = *ip ; iv = std::lower_bound( iv , ev , q , PartLess() ); if ( iv != ev && *iv == q ) { r.push_back( q ); } } return r.size() ; }
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; } } }