Esempio n. 1
0
  /**
   * Search previous and following index entries around the requested position from the index.
   * Create a new index entry between these entries, if the distance between them is too big for
   * line-by-line reading. Effectively makes a binary search on the file to find a location that is
   * reasonably close to request position and precedes it.
   *
   * @param position
   * @return
   * @throws IOException
   * @throws GBrowserException
   */
  private long binarySearch(BpCoord position) throws IOException, GBrowserException {

    Entry<BpCoord, Long> floorEntry = index.floorEntry(position);
    Entry<BpCoord, Long> ceilingEntry = index.ceilingEntry(position);

    if (floorEntry == null) {
      // Request start is less than smallest index entry
      floorEntry = ceilingEntry;
    }

    if (ceilingEntry == null) {
      // Request start is greater than largest index entry
      ceilingEntry = floorEntry;
    }

    long floorFilePosition = floorEntry.getValue();
    long ceilingFilePosition = ceilingEntry.getValue();

    if (ceilingFilePosition - floorFilePosition > INDEX_INTERVAL) {

      splitIndexRegion(floorFilePosition, ceilingFilePosition);

      return binarySearch(position);
    }

    return floorEntry.getValue();
  }
Esempio n. 2
0
 String getSeparatorBetween(Tree right, Tree left) {
   if (right == null || left == null) {
     return null;
   }
   int leftHead = ShiftReduceUtils.headIndex(left);
   int rightHead = ShiftReduceUtils.headIndex(right);
   Map.Entry<Integer, String> nextSeparator = separators.ceilingEntry(leftHead);
   if (nextSeparator == null || nextSeparator.getKey() > rightHead) {
     return null;
   }
   return nextSeparator.getValue().substring(0, 1);
 }
  public static <T> T getNextKnownValue(
      Integer packetNumber, Unit unit, Map<Unit, TreeMap<Integer, T>> histogramMap) {
    TreeMap<Integer, T> packetNumberTMap = histogramMap.get(unit);

    if (packetNumberTMap == null) return null;

    if (packetNumberTMap.isEmpty()) return null;

    Map.Entry<Integer, T> entry = packetNumberTMap.ceilingEntry(packetNumber);

    if (entry != null) return entry.getValue();
    else return null;
  }
Esempio n. 4
0
  /* (non-Javadoc)
   * @see org.ejs.gui.images.IPaletteMapper#getRgbToGreyForGreyscaleMode(byte[])
   */
  @Override
  public byte[] getRgbToGreyForGreyscaleMode(byte[] rgb) {
    int lum = ColorMapUtils.getRGBLum(rgb);

    TreeMap<Integer, byte[]> map = getGreyToRgbMap();
    Entry<Integer, byte[]> entry = map.ceilingEntry(lum);
    if (entry == null) {
      entry = map.floorEntry(lum);
      if (entry == null) {
        throw new AssertionError();
      }
    }

    return entry.getValue();
  }
Esempio n. 5
0
 public Map.Entry<K, V> ceilingEntry(K key) {
   return realMap.ceilingEntry(key);
 }
  public void generator(String output) {
    try {
      outfile = new BufferedWriter(new FileWriter(output));
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    Random r = new Random();
    addEdge(0, 0);
    for (int n = 1; n < nodeNum; n++) {

      int outDegnum =
          outDegCPD.ceilingEntry(r.nextInt(this.outDeg.floorEntry(n).getValue())).getValue();
      if (Math.random() < beta) {
        Random rr = new Random();
        int rnd = rr.nextInt(n);
        List<Integer> ls = new ArrayList<Integer>();
        while (ls.size() < outDegnum) {
          if (!ls.contains(rnd)) {
            addEdge(n, rnd);
            ls.add(rnd);
          }
          rnd = rr.nextInt(n);
        }
      } else {
        int rnd = new Random().nextInt(n);
        List<Integer> ls = network.get(rnd);
        Set<Integer> index = new HashSet<Integer>();

        if (ls.size() >= outDegnum) {
          Random rr = new Random();
          while (index.size() < outDegnum) {
            int rIndex = rr.nextInt(ls.size());
            if (!index.contains(rIndex)) {
              index.add(rIndex);
              addEdge(n, ls.get(rIndex));
            }
          }
        } else {
          for (int i = 0; i < ls.size(); i++) {
            addEdge(n, ls.get(i));
          }
          int irnd = new Random().nextInt(n);
          int num = 0;
          while (num < (outDegnum - ls.size())) {
            if (!ls.contains(irnd)) {
              num++;
              addEdge(n, irnd);
              ls.add(irnd);
            }
            irnd = new Random().nextInt(n);
          }
        }
      }
    }

    try {
      outfile.flush();
      outfile.close();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }