----------------------------------------------------------------- ! Assign a set equal to the intersection of two other sets. \param this_target is the index in this svec_setvec object of the set being assigned. \param this_left is the index in this svec_setvec object of the left operand for the intersection operation. It is OK for this_target and this_left to be the same va
| 1218 | svec_setvec object). |
| 1219 | */ |
| 1220 | void binary_intersection( |
| 1221 | size_t this_target , |
| 1222 | size_t this_left , |
| 1223 | size_t other_right , |
| 1224 | const svec_setvec& other ) |
| 1225 | { CPPAD_ASSERT_UNKNOWN( post_[this_left] == 0 ); |
| 1226 | CPPAD_ASSERT_UNKNOWN( other.post_[ other_right ] == 0 ); |
| 1227 | // |
| 1228 | CPPAD_ASSERT_UNKNOWN( this_target < start_.size() ); |
| 1229 | CPPAD_ASSERT_UNKNOWN( this_left < start_.size() ); |
| 1230 | CPPAD_ASSERT_UNKNOWN( other_right < other.start_.size() ); |
| 1231 | CPPAD_ASSERT_UNKNOWN( end_ == other.end_ ); |
| 1232 | // |
| 1233 | // check if one of the two operands is a subset of the the other |
| 1234 | size_t subset = is_subset(this_left, other_right, other); |
| 1235 | |
| 1236 | // case where left is a subset of right or left and right are equal |
| 1237 | if( subset == 1 || subset == 3 ) |
| 1238 | { assignment(this_target, this_left, *this); |
| 1239 | return; |
| 1240 | } |
| 1241 | // case where the right is a subset of left and they are not equal |
| 1242 | if( subset == 2 ) |
| 1243 | { assignment(this_target, other_right, other); |
| 1244 | return; |
| 1245 | } |
| 1246 | // if neither case holds, then both left and right are non-empty |
| 1247 | CPPAD_ASSERT_UNKNOWN( reference_count(this_left) > 0 ); |
| 1248 | CPPAD_ASSERT_UNKNOWN( other.reference_count(other_right) > 0 ); |
| 1249 | |
| 1250 | // must get all the start indices before modify start_this |
| 1251 | // (in case start_this is the same as start_left or start_right) |
| 1252 | size_t start_left = start_[this_left]; |
| 1253 | size_t start_right = other.start_[other_right]; |
| 1254 | |
| 1255 | |
| 1256 | // number of list elements that will be deleted by this operation |
| 1257 | size_t number_lost = drop(this_target); |
| 1258 | |
| 1259 | // drop any posting for the target set |
| 1260 | size_t post = post_[this_target]; |
| 1261 | if( post > 0 ) |
| 1262 | { // do not need to worry about target being same as left or right |
| 1263 | size_t capacity = data_[post + 1]; |
| 1264 | number_lost += capacity + 2; |
| 1265 | post_[this_target] = 0; |
| 1266 | } |
| 1267 | |
| 1268 | // initialize intersection as empty |
| 1269 | size_t start = 0; |
| 1270 | start_[this_target] = start; |
| 1271 | |
| 1272 | // initialize left |
| 1273 | CPPAD_ASSERT_UNKNOWN( start_left != 0 ); |
| 1274 | size_t current_left = start_left + 2; |
| 1275 | size_t value_left = data_[current_left]; |
| 1276 | CPPAD_ASSERT_UNKNOWN( value_left < end_ ); |
| 1277 |