Java Arrays.binarySearch Examples

Java Arrays.binarySearch - 30 examples found. These are the top rated real world Java examples of java.util.Arrays.binarySearch extracted from open source projects. You can rate examples to help us improve the quality of examples.
  private boolean isSourceOppositeToTargetInt(
      long sourceSense, long targetSense, POS sourcePOS, POS targetPOS) {
    long key;
    if (targetSense > sourceSense) {
      key = (targetSense << 32) + sourceSense;
    } else {
      key = (sourceSense << 32) + targetSense;
    }

    if ((POS.NOUN == sourcePOS) && (POS.NOUN == targetPOS)) {
      if (Arrays.binarySearch(noun_opp, key) >= 0) {
        log.trace("Found ! using ! (ANTONYM) between nouns");
        return true;
      }
    } else {
      if ((POS.ADJECTIVE == sourcePOS) && (POS.ADJECTIVE == targetPOS)) {
        if (Arrays.binarySearch(adj_opp, key) >= 0) {
          log.trace("Found ! using ! (ANTONYM) between adjectives");
          return true;
        }
      } else {
        if ((POS.ADVERB == sourcePOS) && (POS.ADVERB == targetPOS)) {
          if (Arrays.binarySearch(adv_opp, key) >= 0) {
            log.trace("Found ! using ! (ANTONYM) between adverbs");
            return true;
          }
        }
      }
    }

    return false;
  }
  private boolean isSourceSynonymTargetInt(
      long sourceSense, long targetSense, POS sourcePOS, POS targetPOS) {
    if (sourceSense == targetSense) {
      return true;
    }

    long key;
    if (targetSense > sourceSense) {
      key = (targetSense << 32) + sourceSense;
    } else {
      key = (sourceSense << 32) + targetSense;
    }

    if ((POS.ADJECTIVE == sourcePOS) && (POS.ADJECTIVE == targetPOS)) {
      if (Arrays.binarySearch(adj_syn, key) >= 0) {
        log.trace("Found = using & (SIMILAR_TO) between adjectives");
        return true;
      }
    }
    if ((POS.NOUN == sourcePOS) && (POS.VERB == targetPOS)) {
      key = (targetSense << 32) + sourceSense;
      if (Arrays.binarySearch(nominalizations, key) >= 0) {
        log.trace("Found = using + (DERIVATION) between a noun and a verb");
        return true;
      }
    }
    if ((POS.VERB == sourcePOS) && (POS.NOUN == targetPOS)) {
      key = (sourceSense << 32) + targetSense;
      if (Arrays.binarySearch(nominalizations, key) >= 0) {
        log.trace("Found = using + (DERIVATION) between a verb and a noun");
        return true;
      }
    }
    return false;
  }
 public static final boolean accepts(final String acceptHeader, final String toAccept) {
   final String[] acceptValues = acceptHeader.split("\\s*(,|;)\\s*");
   Arrays.sort(acceptValues);
   return Arrays.binarySearch(acceptValues, toAccept) > -1
       || Arrays.binarySearch(acceptValues, toAccept.replaceAll("/.*$", "/*")) > -1
       || Arrays.binarySearch(acceptValues, "*/*") > -1;
 }
Example #4
0
 public void solve(int testNumber, FastScanner in, FastPrinter out) {
   int n = in.nextInt();
   int p = in.nextInt();
   int m = in.nextInt();
   Query[] qs = new Query[m];
   int[] z = new int[4 * m + 10];
   int cn = 0;
   for (int i = 0; i < m; i++) {
     int time = in.nextInt();
     int type = in.next().equals("save") ? 0 : 1;
     int a = in.nextInt();
     int b = in.nextInt();
     qs[i] = new Query(time, type, a, b);
     if (type == 0) {
       z[cn++] = a - 1;
       z[cn++] = b;
     } else {
       --a;
       z[cn++] = a - b + 1;
       z[cn++] = a;
       z[cn++] = a + b;
     }
   }
   z[cn++] = 0;
   z[cn++] = n;
   z = Arrays.copyOf(z, cn);
   z = ArrayUtils.sortAndUnique(z);
   int[] cnt = new int[z.length - 1];
   {
     for (int i = 0; i < z.length - 1; i++) {
       cnt[i] = z[i + 1] - z[i];
     }
   }
   SegmentTree tree = new SegmentTree(cnt);
   int last = 0;
   double all = 0;
   for (int i = 0; i < m; i++) {
     int time = qs[i].time;
     tree.addValue(0, cnt.length, 1. * p * (time - last), 0);
     last = time;
     if (qs[i].type == 0) {
       int l = qs[i].a - 1;
       int r = qs[i].b;
       l = Arrays.binarySearch(z, l);
       r = Arrays.binarySearch(z, r);
       double sum = tree.getSum(l, r);
       all += sum;
       out.println(all);
       tree.setZero(l, r);
     } else {
       int index = qs[i].a - 1;
       int d = qs[i].b;
       double x = all / (2 * SegmentTree.sum(d) + d);
       int id = Arrays.binarySearch(z, index);
       tree.addValue(Arrays.binarySearch(z, index - d + 1), id, x, x);
       tree.addValue(id, Arrays.binarySearch(z, index + d), d * x, -x);
       all = 0;
     }
   }
 }
 public static double[][] pxy(double[] x, double[] y, double min, double max, int nIntervals) {
   if (x.length != y.length) return null;
   double[][] count = new double[nIntervals][nIntervals];
   double[] intervals = new double[nIntervals];
   for (int i = 0; i < nIntervals; i++) {
     intervals[i] = min + (max - min) / nIntervals * (i + 1);
   }
   for (int i = 0; i < x.length; i++) {
     int posx = Arrays.binarySearch(intervals, x[i]);
     // if posx >= 0, it matches one of the interval limits:
     if (posx < 0) {
       if (posx == -1) posx = 0;
       else posx = -posx - 2;
     }
     for (int j = 0; j < y.length; j++) {
       int posy = Arrays.binarySearch(intervals, y[i]);
       if (posy < 0) {
         if (posy == -1) posy = 0;
         else posy = -posy - 2;
       }
       count[posx][posy]++;
     }
   }
   for (int i = 0; i < nIntervals; i++) {
     for (int j = 0; j < nIntervals; j++) {
       count[i][j] /= x.length;
     }
   }
   return count;
 }
Example #6
0
 // Makes sure QueryKeys have no problem going in and out of GGEP blocks
 public void testQueryKeysAndGGEP() throws Exception {
   MACCalculatorRepositoryManager macManager = new MACCalculatorRepositoryManager();
   Random rand = new Random();
   for (int i = 4; i < 17; i++) {
     byte[] qk = new byte[i];
     Arrays.sort(qk);
     // make sure the bytes have offensive characters....
     while ((Arrays.binarySearch(qk, (byte) 0x1c) < 0)
         || (Arrays.binarySearch(qk, (byte) 0x00) < 0)) {
       rand.nextBytes(qk);
       Arrays.sort(qk);
     }
     AddressSecurityToken addressSecurityToken = new AddressSecurityToken(qk, macManager);
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     addressSecurityToken.write(baos);
     GGEP in = new GGEP(true);
     in.put(GGEPKeys.GGEP_HEADER_QUERY_KEY_SUPPORT, baos.toByteArray());
     baos = new ByteArrayOutputStream();
     in.write(baos);
     GGEP out = new GGEP(baos.toByteArray(), 0, null);
     AddressSecurityToken queryKey2 =
         new AddressSecurityToken(
             out.getBytes(GGEPKeys.GGEP_HEADER_QUERY_KEY_SUPPORT), macManager);
     assertEquals("qks not equal, i = " + i, addressSecurityToken, queryKey2);
   }
 }