| 546 | } |
| 547 | |
| 548 | struct set_t *csp_set_intersection(CSOUND *csound, struct set_t *first, |
| 549 | struct set_t *second) |
| 550 | { |
| 551 | int ctr = 0; |
| 552 | int first_len; |
| 553 | struct set_t *result; |
| 554 | #ifdef SET_DEBUG |
| 555 | if (UNLIKELY(first == NULL)) |
| 556 | csound->Die(csound, "Invalid NULL Parameter first"); |
| 557 | if (UNLIKELY(!set_is_set(first))) |
| 558 | csound->Die(csound, "Invalid Parameter set not a first"); |
| 559 | if (UNLIKELY(second == NULL)) |
| 560 | csound->Die(csound, "Invalid NULL Parameter second"); |
| 561 | if (UNLIKELY(!set_is_set(second))) |
| 562 | csound->Die(csound, "Invalid Parameter set not a second"); |
| 563 | if (UNLIKELY(result == NULL)) |
| 564 | csound->Die(csound, "Invalid NULL Parameter result"); |
| 565 | if (UNLIKELY(first->ele_eq_func != second->ele_eq_func)) |
| 566 | csound->Die(csound, |
| 567 | "Invalid sets for comparison (different equality)"); |
| 568 | #endif |
| 569 | |
| 570 | result = csp_set_alloc(csound, |
| 571 | first->ele_eq_func, first->ele_print_func); |
| 572 | |
| 573 | first_len = csp_set_count(first); |
| 574 | |
| 575 | while (ctr < first_len) { |
| 576 | void *data = NULL; |
| 577 | data = csp_set_get_num(first, ctr); |
| 578 | if (csp_set_exists(second, data)) { |
| 579 | csp_set_add(csound, result, data); |
| 580 | } |
| 581 | ctr++; |
| 582 | } |
| 583 | |
| 584 | return result; |
| 585 | } |
no test coverage detected