import System from './System' ; export default class Arrays { public static equals ( first , second ) { if ( ! first ) { return false ; } if ( ! second ) { return false ; } if ( ! first . length ) { return false ; } if ( ! second . length ) { return false ; } if ( first . length !== second . length ) { return false ; } for ( let i = 0 , length = first . length ; i < length ; i ++ ) { if ( first [ i ] !== second [ i ] ) { return false ; } } return true ; } public static hashCode ( a ) { if ( a === null ) { return 0 ; } let result = 1 ; for ( const element of a ) { result = 31 * result + element ; } return result ; } public static fillUint8Array ( a , value ) { for ( let i = 0 ; i !== a . length ; i ++ ) { a [ i ] = value ; } } public static copyOf ( original , newLength ) { const copy = new Int32Array ( newLength ) ; System . arraycopy ( original , 0 , copy , 0 , Math . min ( original . length , newLength ) ) ; return copy ; } public static binarySearch ( ar , el , comparator ? ) { if ( undefined === comparator ) { comparator = Arrays . numberComparator ; } let m = 0 ; let n = ar . length - 1 ; while ( m <= n ) { const k = ( n + m ) >> 1 ; const cmp = comparator ( el , ar [ k ] ) ; if ( cmp > 0 ) { m = k + 1 ; } else if ( cmp < 0 ) { n = k - 1 ; } else { return k ; } } return - m - 1 ; } public static numberComparator ( a , b ) { return a - b ; } }