public static boolean unsignedIntersects ( ShortBuffer set1 , int length1 , ShortBuffer set2 , int length2 ) { if ( ( 0 == length1 ) || ( 0 == length2 ) ) { return false ; } int k1 = 0 ; int k2 = 0 ; // could be more efficient with galloping short s1 = set1 . get ( k1 ) ; short s2 = set2 . get ( k2 ) ; mainwhile : while ( true ) { if ( toIntUnsigned ( s2 ) < toIntUnsigned ( s1 ) ) { do { ++ k2 ; if ( k2 == length2 ) { break mainwhile ; } s2 = set2 . get ( k2 ) ; } while ( toIntUnsigned ( s2 ) < toIntUnsigned ( s1 ) ) ; } if ( toIntUnsigned ( s1 ) < toIntUnsigned ( s2 ) ) { do { ++ k1 ; if ( k1 == length1 ) { break mainwhile ; } s1 = set1 . get ( k1 ) ; } while ( toIntUnsigned ( s1 ) < toIntUnsigned ( s2 ) ) ; } else { return true ; } } return false ; }
Checks if two arrays intersect