Tabnine Logo
Arrays.binarySearch
Code IndexAdd Tabnine to your IDE (free)

How to use
binarySearch
method
in
java.util.Arrays

Best Java code snippets using java.util.Arrays.binarySearch (Showing top 20 results out of 13,221)

Refine searchRefine arrow

  • Arrays.sort
  • ObjectInputStream.defaultReadObject
origin: apache/flink

private static int[] toFieldPosMap(int[] selectedFields) {
  int[] fieldIdxs = Arrays.copyOf(selectedFields, selectedFields.length);
  Arrays.sort(fieldIdxs);
  int[] fieldPosMap = new int[selectedFields.length];
  for (int i = 0; i < selectedFields.length; i++) {
    int pos = Arrays.binarySearch(fieldIdxs, selectedFields[i]);
    fieldPosMap[pos] = i;
  }
  return fieldPosMap;
}
origin: shekhargulati/99-problems

  public static boolean findPair(int[] s1, int[] s2, int x) {
    /*
      Sort one array let say s2
      for each el in s1
        do a binary search in s2 for x-el
        if found return el and (x-el)
     */
    Arrays.sort(s2);
    for (int f : s1) {
      int s = x - f;
      if (Arrays.binarySearch(s2, s) >= 0) {
        return true;
      }
    }
    return false;
  }
}
origin: alibaba/druid

public Keywords(Map<String, Token> keywords){
  this.keywords = keywords;
  this.hashArray = new long[keywords.size()];
  this.tokens = new Token[keywords.size()];
  int index = 0;
  for (String k : keywords.keySet()) {
    hashArray[index++] = Utils.fnv_64_lower(k);
  }
  Arrays.sort(hashArray);
  for (Map.Entry<String, Token> entry : keywords.entrySet()) {
    long k = Utils.fnv_64_lower(entry.getKey());
    index = Arrays.binarySearch(hashArray, k);
    tokens[index] = entry.getValue();
  }
}
origin: alibaba/mdrill

/** {@inheritDoc} */
public boolean retainAll( byte[] array ) {
  boolean changed = false;
  Arrays.sort( array );
  byte[] data = _data;
  for ( int i = _pos; i-- > 0; ) {
    if ( Arrays.binarySearch( array, data[i] ) < 0 ) {
      remove( i, 1 );
      changed = true;
    }
  }
  return changed;
}
origin: alibaba/mdrill

/** {@inheritDoc} */
public boolean retainAll( float[] array ) {
  boolean changed = false;
  Arrays.sort( array );
  float[] data = _data;
  for ( int i = _pos; i-- > 0; ) {
    if ( Arrays.binarySearch( array, data[i] ) < 0 ) {
      remove( i, 1 );
      changed = true;
    }
  }
  return changed;
}
origin: alibaba/mdrill

/** {@inheritDoc} */
public boolean retainAll( char[] array ) {
  boolean changed = false;
  Arrays.sort( array );
  char[] data = _data;
  for ( int i = _pos; i-- > 0; ) {
    if ( Arrays.binarySearch( array, data[i] ) < 0 ) {
      remove( i, 1 );
      changed = true;
    }
  }
  return changed;
}
origin: alibaba/mdrill

/** {@inheritDoc} */
public boolean retainAll( int[] array ) {
  boolean changed = false;
  Arrays.sort( array );
  int[] data = _data;
  for ( int i = _pos; i-- > 0; ) {
    if ( Arrays.binarySearch( array, data[i] ) < 0 ) {
      remove( i, 1 );
      changed = true;
    }
  }
  return changed;
}
origin: alibaba/mdrill

/** {@inheritDoc} */
public boolean retainAll( short[] array ) {
  boolean changed = false;
  Arrays.sort( array );
  short[] data = _data;
  for ( int i = _pos; i-- > 0; ) {
    if ( Arrays.binarySearch( array, data[i] ) < 0 ) {
      remove( i, 1 );
      changed = true;
    }
  }
  return changed;
}
origin: alibaba/mdrill

/** {@inheritDoc} */
public boolean retainAll( double[] array ) {
  boolean changed = false;
  Arrays.sort( array );
  double[] data = _data;
  for ( int i = _pos; i-- > 0; ) {
    if ( Arrays.binarySearch( array, data[i] ) < 0 ) {
      remove( i, 1 );
      changed = true;
    }
  }
  return changed;
}
origin: alibaba/mdrill

/** {@inheritDoc} */
public boolean retainAll( long[] array ) {
  boolean changed = false;
  Arrays.sort( array );
  long[] data = _data;
  for ( int i = _pos; i-- > 0; ) {
    if ( Arrays.binarySearch( array, data[i] ) < 0 ) {
      remove( i, 1 );
      changed = true;
    }
  }
  return changed;
}
origin: com.alibaba/fastjson

public void addAccept(String name) {
  if (name == null || name.length() == 0) {
    return;
  }
  long hash = TypeUtils.fnv1a_64(name);
  if (Arrays.binarySearch(this.acceptHashCodes, hash) >= 0) {
    return;
  }
  long[] hashCodes = new long[this.acceptHashCodes.length + 1];
  hashCodes[hashCodes.length - 1] = hash;
  System.arraycopy(this.acceptHashCodes, 0, hashCodes, 0, this.acceptHashCodes.length);
  Arrays.sort(hashCodes);
  this.acceptHashCodes = hashCodes;
}
origin: com.alibaba/fastjson

public void addDeny(String name) {
  if (name == null || name.length() == 0) {
    return;
  }
  long hash = TypeUtils.fnv1a_64(name);
  if (Arrays.binarySearch(this.denyHashCodes, hash) >= 0) {
    return;
  }
  long[] hashCodes = new long[this.denyHashCodes.length + 1];
  hashCodes[hashCodes.length - 1] = hash;
  System.arraycopy(this.denyHashCodes, 0, hashCodes, 0, this.denyHashCodes.length);
  Arrays.sort(hashCodes);
  this.denyHashCodes = hashCodes;
}
origin: alibaba/mdrill

/** {@inheritDoc} */
public boolean retainAll( short[] array ) {
  boolean changed = false;
  Arrays.sort( array );
  short[] set = _set;
  byte[] states = _states;
  for ( int i = set.length; i-- > 0; ) {
    if ( states[i] == FULL && ( Arrays.binarySearch( array, set[i] ) < 0) ) {
      removeAt( i );
      changed = true;
    }
  }
  return changed;
}
origin: alibaba/mdrill

/** {@inheritDoc} */
public boolean retainAll( byte[] array ) {
  boolean changed = false;
  Arrays.sort( array );
  byte[] values = _values;
  byte[] states = _states;
  for ( int i = values.length; i-- > 0; ) {
    if ( states[i] == FULL && ( Arrays.binarySearch( array, values[i] ) < 0) ) {
      removeAt( i );
      changed = true;
    }
  }
  return changed;
}
origin: alibaba/mdrill

/** {@inheritDoc} */
public boolean retainAll( float[] array ) {
  boolean changed = false;
  Arrays.sort( array );
  float[] values = _values;
  byte[] states = _states;
  for ( int i = values.length; i-- > 0; ) {
    if ( states[i] == FULL && ( Arrays.binarySearch( array, values[i] ) < 0) ) {
      removeAt( i );
      changed = true;
    }
  }
  return changed;
}
origin: alibaba/mdrill

/** {@inheritDoc} */
public boolean retainAll( long[] array ) {
  boolean changed = false;
  Arrays.sort( array );
  long[] set = _set;
  byte[] states = _states;
  for ( int i = set.length; i-- > 0; ) {
    if ( states[i] == FULL && ( Arrays.binarySearch( array, set[i] ) < 0) ) {
      removeAt( i );
      changed = true;
    }
  }
  return changed;
}
origin: alibaba/mdrill

/** {@inheritDoc} */
public boolean retainAll( int[] array ) {
  boolean changed = false;
  Arrays.sort( array );
  int[] set = _set;
  byte[] states = _states;
  for ( int i = set.length; i-- > 0; ) {
    if ( states[i] == FULL && ( Arrays.binarySearch( array, set[i] ) < 0) ) {
      removeAt( i );
      changed = true;
    }
  }
  return changed;
}
origin: alibaba/mdrill

/** {@inheritDoc} */
public boolean retainAll( int[] array ) {
  boolean changed = false;
  Arrays.sort( array );
  int[] values = _values;
  byte[] states = _states;
  for ( int i = values.length; i-- > 0; ) {
    if ( states[i] == FULL && ( Arrays.binarySearch( array, values[i] ) < 0) ) {
      removeAt( i );
      changed = true;
    }
  }
  return changed;
}
origin: alibaba/mdrill

/** {@inheritDoc} */
public boolean retainAll( double[] array ) {
  boolean changed = false;
  Arrays.sort( array );
  double[] set = _set;
  byte[] states = _states;
  for ( int i = set.length; i-- > 0; ) {
    if ( states[i] == FULL && ( Arrays.binarySearch( array, set[i] ) < 0) ) {
      removeAt( i );
      changed = true;
    }
  }
  return changed;
}
origin: alibaba/mdrill

/** {@inheritDoc} */
public boolean retainAll( float[] array ) {
  boolean changed = false;
  Arrays.sort( array );
  float[] values = _values;
  byte[] states = _states;
  for ( int i = values.length; i-- > 0; ) {
    if ( states[i] == FULL && ( Arrays.binarySearch( array, values[i] ) < 0) ) {
      removeAt( i );
      changed = true;
    }
  }
  return changed;
}
java.utilArraysbinarySearch

Javadoc

Performs a binary search for value in the ascending sorted array array. Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.

Popular methods of Arrays

  • asList
    Returns a List of the objects in the specified array. The size of the List cannot be modified, i.e.
  • toString
    Returns a string representation of the contents of the specified array. The string representation co
  • equals
    Returns true if the two specified arrays of booleans areequal to one another. Two arrays are conside
  • sort
    Sorts the specified range of the array into ascending order. The range to be sorted extends from the
  • copyOf
    Copies the specified array, truncating or padding with false (if necessary) so the copy has the spec
  • fill
    Assigns the specified boolean value to each element of the specified array of booleans.
  • stream
  • hashCode
    Returns a hash code based on the contents of the specified array. For any two boolean arrays a and
  • copyOfRange
    Copies the specified range of the specified array into a new array. The initial index of the range (
  • deepEquals
    Returns true if the two specified arrays are deeply equal to one another. Unlike the #equals(Object[
  • deepToString
  • deepHashCode
    Returns a hash code based on the "deep contents" of the specified array. If the array contains other
  • deepToString,
  • deepHashCode,
  • setAll,
  • parallelSort,
  • parallelSetAll,
  • spliterator,
  • checkBinarySearchBounds,
  • checkOffsetAndCount,
  • checkStartAndEnd

Popular in Java

  • Creating JSON documents from java classes using gson
  • runOnUiThread (Activity)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • startActivity (Activity)
  • Rectangle (java.awt)
    A Rectangle specifies an area in a coordinate space that is enclosed by the Rectangle object's top-
  • BufferedInputStream (java.io)
    A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the i
  • FileNotFoundException (java.io)
    Thrown when a file specified by a program cannot be found.
  • LinkedList (java.util)
    Doubly-linked list implementation of the List and Dequeinterfaces. Implements all optional list oper
  • JButton (javax.swing)
  • Options (org.apache.commons.cli)
    Main entry-point into the library. Options represents a collection of Option objects, which describ
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now