Java Array Intersect intersect(boolean[] mask, int[] examples, boolean[] intersection)

Here you can find the source of intersect(boolean[] mask, int[] examples, boolean[] intersection)

Description

A generic intersect function that

License

Open Source License

Parameter

Parameter Description
mask An examples mask
examples The list of examples to intersect with
intersection The examples mask with the intersection of the first 2 arguments, must be the same size as mask.

Return

The number of true elements in the intersection mask.

Declaration

public static int intersect(boolean[] mask, int[] examples, boolean[] intersection) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Arrays;

public class Main {
    /**/*w w w.ja v a  2 s .c  o  m*/
     * A generic intersect function that
     * 
     * @param mask
     *            An examples mask
     * @param examples
     *            The list of examples to intersect with
     * @param intersection
     *            The examples mask with the intersection of the first 2
     *            arguments, must be the same size as mask.
     * @return The number of true elements in the intersection mask.
     */
    public static int intersect(boolean[] mask, int[] examples, boolean[] intersection) {
        if (intersection.length != mask.length)
            throw new RuntimeException("Argument and return value have different length.");
        Arrays.fill(intersection, false);
        int count = 0;
        for (int i = 0; i < examples.length; i++)
            if (mask[examples[i]]) {
                intersection[examples[i]] = true;
                count++;
            }
        return (count);
    }
}

Related

  1. arraysIntersect(Object[] array1, Object[] array2)
  2. byteIntersection(byte[] a, byte[] b)
  3. getArrayIntersection(int a[], int b[])
  4. getNonIntersection(int[] interval, int[] intervalToRemove)
  5. hasIntersection(String a1[], String a2[], int mode)
  6. intersect(int[] sorted1, int[] sorted2)
  7. intersect(int[]... arrays)
  8. intersect(String[] arr1, String[] arr2)
  9. intersect(String[] list1, String[] list2)