5 #pragma warning( disable : 4786 )
21 MeshSet::CompactList& list,
27 MeshSet::CompactList& list,
36 template <
typename pair_iter_t >
115 if( list.
hnd[0] == h )
127 if( list.
hnd[0] == h || list.
hnd[1] == h )
135 ptr[0] = list.
hnd[0];
136 ptr[1] = list.
hnd[1];
139 list.
ptr[1] = ptr + 3;
144 if( std::find( list.
ptr[0], list.
ptr[1], h ) != list.
ptr[1] )
173 if( h == list.
hnd[0] )
184 if( h == list.
hnd[0] )
186 list.
hnd[0] = list.
hnd[1];
190 else if( h == list.
hnd[1] )
202 i = std::find( list.
ptr[0], list.
ptr[1], h );
203 if( i == list.
ptr[1] )
277 if( !(
mFlags & MESHSET_ORDERED ) && ( flg & MESHSET_ORDERED ) )
283 std::vector< EntityHandle > list( datalen );
284 memcpy( &list[0], data, datalen *
sizeof(
EntityHandle ) );
289 assert( list.size() % 2 == 0 );
290 std::vector< EntityHandle >::iterator i = list.begin();
291 while( i != list.end() )
305 else if( (
mFlags & MESHSET_ORDERED ) && !( flg & MESHSET_ORDERED ) )
311 std::vector< EntityHandle > ranges;
316 memcpy( data, &ranges[0], ranges.size() *
sizeof(
EntityHandle ) );
345 assert( 0 == count % 2 );
378 assert( 0 == count % 2 );
394 if( new_list_size <= 2 )
402 list[0] = clist.
hnd[0];
403 list[1] = clist.
hnd[1];
405 clist.
ptr[1] = list + new_list_size;
410 else if( new_list_size > 2 )
412 if( new_list_size > (
size_t)( clist.
ptr[1] - clist.
ptr[0] ) )
414 clist.
ptr[1] = clist.
ptr[0] + new_list_size;
421 clist.
hnd[0] = list[0];
422 clist.
hnd[1] = list[1];
436 return r.second < h.first;
440 template <
typename pair_iter_t >
455 list_ptr = clist.
hnd;
460 list_ptr = clist.
ptr[0];
461 list_size = clist.
ptr[1] - clist.
ptr[0];
465 assert( 0 == list_size % 2 );
470 pair_iter_t i = begin;
475 size_t insert_count = 0;
483 if( list_read == list_write )
489 tmp.first = i->first - 1;
490 tmp.second = i->second;
491 list_write = std::lower_bound( list_read, list_end, tmp,
MeshSetRComp() );
492 list_read = list_write;
497 while( list_read != list_end && list_read->second + 1 < i->first )
499 *list_write = *list_read;
505 for( ; i != end && ( list_read == list_end || i->second + 1 < list_read->first ); ++i )
509 if( list_read == list_write )
519 list_write->first = i->first;
520 list_write->second = i->second;
527 if( list_read != list_end )
536 if( i != end && i->first < working.first && i->second + 1 >= working.first )
539 for(
EntityHandle h = i->first; h < working.first; ++h )
541 working.first = i->first;
550 bool set_overlap = list_read != list_end && list_read->first <= working.second + 1;
552 bool inp_overlap = i != end && i->first <= working.second + 1;
555 if( inp_overlap && set_overlap )
558 if( list_read->second <= working.second ) ++list_read;
560 else if( i->second <= working.second )
566 else if( list_read->second <= i->second )
568 working.second = list_read->second;
573 working.second = i->second;
578 else if( inp_overlap )
585 if( list_read != list_end && list_read->first < last )
586 last = list_read->first - 1;
590 if( last > working.second )
593 for(
EntityHandle h = working.second + 1; h <= last; ++h )
596 working.second = last;
599 else if( set_overlap )
601 if( working.second < list_read->second ) working.second = list_read->second;
610 assert( list_write < list_read );
611 *list_write = working;
617 if( list_read == list_write )
618 list_read = list_write = list_end;
620 while( list_read < list_end )
622 *list_write = *list_read;
628 const size_t occupied_size = list_write - list;
629 const size_t new_list_size = occupied_size + insert_count;
639 assert( begin != end );
640 pair_iter_t ri = end;
642 list_write = list + new_list_size - 1;
643 list_read = list + occupied_size - 1;
644 for( ; list_write >= list; --list_write )
646 if( list_read >= list )
648 while( ri->first >= list_read->first && ri->second <= list_read->second )
650 assert( ri != begin );
654 if( list_read->first > ri->second )
656 *list_write = *list_read;
662 assert( insert_count > 0 );
666 list_write->first = ri->first;
667 list_write->second = ri->second;
671 if( 0 == --insert_count )
673 assert( list_read == list_write - 1 );
682 assert( !insert_count );
686 template <
typename pair_iter_t >
697 ptrdiff_t split_count = 0;
708 list_size = clist.
ptr[1] - clist.
ptr[0];
712 EntityHandle *
const list_end = list + list_size, *list_read = list;
713 pair_iter_t i = begin;
715 while( list_read != list_end && i != end )
718 while( i != end && i->second < list_read[0] )
720 if( i == end )
break;
724 if( list_read != list_write )
726 while( list_read != list_end && i->second < list_read[0] )
728 list_write[0] = list_read[0];
729 list_write[1] = list_read[1];
737 list_write = std::lower_bound( list_write, list_end, i->first );
739 list_write -= ( list_write - list ) % 2;
740 list_read = list_write;
744 if( list_read == list_end )
break;
747 if( i->second < list_read[0] )
754 list_write[0] = list_read[0];
755 list_write[1] = list_read[1];
758 for( ; i != end && i->first <= list_write[1]; ++i )
760 if( i->first <= list_write[0] )
763 if( i->second >= list_write[1] )
766 for(
EntityHandle h = list_write[0]; h <= list_write[1]; ++h )
772 else if( i->second >= list_write[0] )
775 for(
EntityHandle h = list_write[0]; h <= i->second; ++h )
777 list_write[0] = i->second + 1;
780 else if( i->first <= list_write[1] )
783 if( i->second >= list_write[1] )
786 for(
EntityHandle h = i->first; h <= list_write[1]; ++h )
788 list_write[1] = i->first - 1;
799 if( list_read - list_write <= 2 )
806 list_write[3] = list_write[1];
807 list_write[1] = i->first - 1;
808 list_write[2] = i->second + 1;
818 if( list_read == list_write )
819 list_read = list_write = list_end;
821 while( list_read < list_end )
823 list_write[0] = list_read[0];
824 list_write[1] = list_read[1];
830 const size_t occupied_size = list_write - list;
831 const size_t new_list_size = occupied_size + 2 * split_count;
839 assert( begin != end );
840 pair_iter_t ri = end;
842 list_write = list + new_list_size - 2;
843 list_read = list + occupied_size - 2;
844 for( ; list_write >= list; list_write -= 2 )
846 if( list_read >= list )
848 while( ri->second > list_read[1] )
850 assert( ri != begin );
854 if( list_read[0] > ri->second )
856 list_write[0] = list_read[0];
857 list_write[1] = list_read[1];
863 assert( split_count > 0 );
864 list_write[0] = ri->second + 1;
865 list_write[1] = list_read[1];
866 list_read[1] = ri->first - 1;
870 if( 0 == --split_count )
872 assert( list_read == list_write - 2 );
881 assert( !split_count );
885 template <
typename pair_iter_t >
895 for( pair_iter_t i = begin; i != end; ++i )
896 add_size += i->second - i->first + 1;
900 for( pair_iter_t i = begin; i != end; ++i )
929 list_size = clist.
ptr[1] - clist.
ptr[0];
934 for(
const EntityHandle* list_read = list; list_read != list_end; ++list_read )
936 if( range.
find( *list_read ) == range.
end() )
938 *list_write = *list_read;
968 list_size = clist.
ptr[1] - clist.
ptr[0];
971 const EntityHandle *
const list_end = list + list_size, *
const input_end = pair_list + 2 * num_pairs;
973 for(
const EntityHandle* list_read = list; list_read != list_end; ++list_read )
975 const EntityHandle* ptr = std::lower_bound( pair_list, input_end, *list_read );
976 if( ( ptr != input_end && ( *ptr == *list_read || ( ptr - pair_list ) % 2 ) ) &&
977 std::find( list_read + 1, list_end, *list_read ) == list_end )
980 if( adj && std::find( list, list_write, *list_read ) == list_write )
985 *list_write = *list_read;
1010 list = clist.
ptr[0];
1011 list_size = clist.
ptr[1] - clist.
ptr[0];
1014 const EntityHandle *
const list_end = list + list_size, *
const input_end = vect + vect_size;
1016 for(
const EntityHandle* list_read = list; list_read != list_end; ++list_read )
1018 if( std::find( vect, input_end, *list_read ) != input_end &&
1019 std::find( list_read + 1, list_end, *list_read ) == list_end )
1027 *list_write = *list_read;
1043 const size_t orig_size = count <
MeshSet::MANY ? (int)count : clist.
ptr[1] - clist.
ptr[0];
1046 for(
size_t i = 0; i < vect_size; ++i )
1048 memcpy( list + orig_size, vect,
sizeof(
EntityHandle ) * vect_size );
1057 typedef const std::pair< EntityHandle, EntityHandle >* pair_vect_t;
1058 pair_vect_t pair_vect =
reinterpret_cast< pair_vect_t
>( range_vect );
1096 typedef const std::pair< EntityHandle, EntityHandle >* pair_vect_t;
1097 pair_vect_t pair_vect =
reinterpret_cast< pair_vect_t
>( range_vect );
1123 size_t other_count = 0;
1125 if( !other_count )
return clear( my_handle, adj );
1126 assert( 0 == other_count % 2 );
1128 std::vector< EntityHandle > compliment;
1129 compliment.reserve( other_count + 4 );
1130 if( *other_vect > 0 )
1132 compliment.push_back( 0 );
1133 compliment.push_back( *other_vect - 1 );
1136 const EntityHandle*
const other_end = other_vect + other_count - 2;
1137 for( ; other_vect < other_end; other_vect += 2 )
1139 compliment.push_back( other_vect[0] + 1 );
1140 compliment.push_back( other_vect[1] - 1 );
1144 compliment.push_back( *other_vect + 1 );
1152 Range my_ents, other_ents;
1162 vect_out.reserve( 2 * vect_in_len );
1163 vect_out.resize( vect_in_len );
1164 std::copy( vect_in, vect_in + vect_in_len, vect_out.begin() );
1165 std::sort( vect_out.begin(), vect_out.end() );
1166 vect_out.erase( std::unique( vect_out.begin(), vect_out.end() ), vect_out.end() );
1169 vect_out.resize( vect_out.size() * 2 );
1170 for(
long i = vect_out.size() - 1; i >= 0; --i )
1171 vect_out[i] = vect_out[i / 2];
1174 std::vector< EntityHandle >::iterator r = vect_out.begin(), w = vect_out.begin();
1175 while( r != vect_out.end() )
1183 while( r != vect_out.end() && *w + 1 == *r )
1193 vect_out.erase( w, vect_out.end() );
1204 std::vector< EntityHandle > rangevect;
1206 typedef const std::pair< EntityHandle, EntityHandle >* pair_vect_t;
1207 pair_vect_t pair_vect = ( rangevect.empty() ) ? NULL :
reinterpret_cast< pair_vect_t
>( &rangevect[0] );
1209 count,
contentList, pair_vect, pair_vect + rangevect.size() / 2, my_h,
tracking() ? adj : 0 );
1223 std::vector< EntityHandle > rangevect;
1225 typedef const std::pair< EntityHandle, EntityHandle >* pair_vect_t;
1226 pair_vect_t pair_vect = ( rangevect.empty() ) ? NULL :
reinterpret_cast< pair_vect_t
>( &rangevect[0] );
1228 count,
contentList, pair_vect, pair_vect + rangevect.size() / 2, my_h,
tracking() ? adj : 0 );
1246 for(
size_t i = 0; i < num_ents; ++i )
1248 EntityHandle* p = std::find( vect, vect_end, old_entities[i] );
1259 adjfact->
add_adjacency( new_entities[i], my_handle,
false );
1261 *p = new_entities[i];
1262 p = std::find( p + 1, vect_end, old_entities[i] );
1263 }
while( p != vect_end );
1281 unsigned long result = 0;