alibIntersectS
Finds the intersection and complement of a sorted array and a second array. The first array must be sorted since this routine does binary searches through the first array to locate those elements that also occur in the second array. Performance-wise, this restriction is an advantage because for a large array, it is generally much faster to sort the array and binary-search it than it is to search the unsorted array. Sorting can be either increasing or decreasing, and duplicate values are acceptable. No restrictions are imposed on the other array. For unsorted data, multidimensional data, or complex data, see
alibIntersect. The PV-WAVE API for this routine is the
WHEREIN Function with the
Sorted keyword.
Prototypes
alibIntersectSb( wvlong m, wvlong n, UCHAR *p, UCHAR *q, UCHAR *r )
alibIntersectSs( wvlong m, wvlong n, short *p, short *q, UCHAR *r )
alibIntersectSi( wvlong m, wvlong n, int *p, int *q, UCHAR *r )
alibIntersectSl( wvlong m, wvlong n, wvlong *p, wvlong *q, UCHAR *r )
alibIntersectSf( wvlong m, wvlong n, float *p, float *q, UCHAR *r )
alibIntersectSd( wvlong m, wvlong n, double *p, double *q, UCHAR *r )
Parameters
m — (Input) The number of elements in the first array.
n — (Input) The number of elements in the second array.
*p — (Input) The m-element sorted array. Sorting can be either increasing or decreasing, and duplicate values are OK.
*q — (Input) The n-element array.
*r — (Input/Output) The m-element array. On return, array r contains only 0's and 1's, where r[i] is 1 if and only if the number p[i] occurs in array q.
Example
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "alib.h"
void main() {
/* make some example data */
UCHAR jb[5], b[5]={0,1,1,2,4}, b0[4]={3,4,5,1};
wvlong nb, *kb;
/* for array b find the intersection and complement with array
b0 */
alibinit( NULL, NULL, NULL, NULL );
alibIntersectSb( 5, 4, b, b0, jb );
/* 0's and 1's locate the complement and the intersection,
respectively */
alibPrintArrayb( 1, 1, 1, 5, jb, NULL );
/* now retrieve the indices into b of its intersection with
b0 */
nb = alibCountb( 5, jb );
kb = (wvlong*)malloc(nb*sizeof(wvlong));
alibFindb( nb, jb, kb );
alibPrintArrayl( 1, 1, 1, nb, kb, NULL );
}
Output:
0 1 1 0 1
1 2 4
Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.