Here you can find the source of unsignedIntersects(short[] set1, int length1, short[] set2, int length2)
Parameter | Description |
---|---|
set1 | first array |
length1 | length of first array |
set2 | second array |
length2 | length of second array |
public static boolean unsignedIntersects(short[] set1, int length1, short[] set2, int length2)
//package com.java2s; /*/*w w w . j a v a 2 s . com*/ * (c) the authors Licensed under the Apache License, Version 2.0. */ public class Main { /** * Checks if two arrays intersect * * @param set1 first array * @param length1 length of first array * @param set2 second array * @param length2 length of second array * @return true if they intersect */ public static boolean unsignedIntersects(short[] set1, int length1, short[] set2, int length2) { // galloping might be faster, but we do not expect this function to be slow if ((0 == length1) || (0 == length2)) { return false; } int k1 = 0; int k2 = 0; short s1 = set1[k1]; short s2 = set2[k2]; mainwhile: while (true) { if (toIntUnsigned(s2) < toIntUnsigned(s1)) { do { ++k2; if (k2 == length2) { break mainwhile; } s2 = set2[k2]; } while (toIntUnsigned(s2) < toIntUnsigned(s1)); } if (toIntUnsigned(s1) < toIntUnsigned(s2)) { do { ++k1; if (k1 == length1) { break mainwhile; } s1 = set1[k1]; } while (toIntUnsigned(s1) < toIntUnsigned(s2)); } else { return true; } } return false; } protected static int toIntUnsigned(short x) { return x & 0xFFFF; } }