public Vector put(Range holder, Object value) {
    int pos = VectorUtil.binarySearch(ranges, holder, rangeComparator, true);
    if (pos == -1) {
      pos = 0;
    }
    Vector output = new Vector();

    int posHigh =
        VectorUtil.binarySearch(
            ranges, new RangeHolder(holder.getHigh(), holder.getHigh()), rangeComparator, true);

    Vector purged = new Vector();
    boolean positionRemoved = false;
    for (int i = (pos - 1 >= 0 ? pos - 1 : 0); i < posHigh && i < ranges.size(); i++) {
      Range clobberMe = (Range) ranges.elementAt(i);
      if (overlaps(clobberMe, holder)) {
        if (i == pos - 1) positionRemoved = true;
        output.addElement(data.remove(clobberMe));
        purged.addElement(clobberMe);
      }
    }
    for (int i = 0; i < purged.size(); i++) ranges.removeElement(purged.elementAt(i));

    if (positionRemoved) pos = pos - 1;

    ranges.insertElementAt(holder, pos);
    data.put(holder, value);
    return output;
  }
示例#2
0
    public VsmCacheModel invoke() {
      if (cfIndex != null) {
        documents = (Map<String, List<LinkedHashMap<String, Object>>>) cfIndex;
      } else {
        documents = VectorUtil.getFeaturesForAllClasses(db);
        vectorSpaceModelCache.put("CLASS_FEATURE_INDEX", documents);
      }

      if (vsmIndex != null) {
        featureIndexList = (List<Integer>) vsmIndex;
      } else {
        featureIndexList = VectorUtil.getFeatureIndexList(db);
        vectorSpaceModelCache.put("GLOBAL_FEATURE_INDEX", featureIndexList);
      }
      return this;
    }
 /**
  * Removes the EXACT range defined by (low,high). If no range is defined on exactly those
  * coordinates, no elements are removed
  */
 public Object remove(int low, int high) {
   RangeHolder holder = new RangeHolder(low, high);
   int pos = VectorUtil.binarySearch(ranges, holder, rangeComparator, false);
   Range found = (Range) ranges.elementAt(pos);
   if (found.equals(holder)) return data.remove(holder);
   else return null;
 }
 /**
  * Removes and returns the value whose key range contains the given key. If there is no such
  * value, null is returned.
  */
 public Object remove(int key) {
   RangeHolder holder = new RangeHolder(key, key + 1);
   int pos = VectorUtil.binarySearch(ranges, holder, rangeComparator, true) - 1;
   if (pos < 0) return null;
   Range rh = (Range) ranges.elementAt(pos);
   return data.remove(rh);
 }
  public double[] getInterval(int key) {
    double[] output = new double[2];
    RangeHolder holder = new RangeHolder(key, key + 1);
    int pos = VectorUtil.binarySearch(ranges, holder, rangeComparator, true) - 1;
    // System.err.println("ranges = "+ranges);
    if (ranges.size() == 0) {
      output[0] = Double.NEGATIVE_INFINITY;
      output[1] = Double.POSITIVE_INFINITY;
      return output;
    }

    if (pos < 0) {
      output[0] = Double.NEGATIVE_INFINITY;
      output[1] = (double) ((Range) ranges.elementAt(0)).getLow() - 1;
      return output;
    }

    if (pos >= ranges.size()) {
      output[0] = (double) ((Range) ranges.elementAt(ranges.size() - 1)).getHigh() + 1;
      output[1] = Double.POSITIVE_INFINITY;
      return output;
    }

    Range rh = (Range) ranges.elementAt(pos);
    if (contains(rh, key)) {
      output[0] = (double) rh.getLow();
      output[1] = (double) rh.getHigh();
    } else {
      output[0] = (double) rh.getHigh() + 1;
      if (pos < ranges.size() - 1) output[1] = ((Range) ranges.elementAt(pos + 1)).getLow() - 1;
      else output[1] = Double.POSITIVE_INFINITY;
    }

    return output;
  }
 /**
  * Returns the value whose key range contains the given key, or null if no range contains that
  * key.
  */
 public Object get(int key) {
   RangeHolder holder = new RangeHolder(key, key + 1);
   int pos = VectorUtil.binarySearch(ranges, holder, rangeComparator, true) - 1;
   if (pos < 0) return null;
   Range rh = (Range) ranges.elementAt(pos);
   if (contains(rh, key)) return data.get(rh);
   else return null;
 }
  public Vector get(int low, int high) {
    Vector output = new Vector();
    RangeHolder holder = new RangeHolder(low, high);

    int lowPos = VectorUtil.binarySearch(ranges, new RangeHolder(low, low), rangeComparator, true);
    if (lowPos == -1) lowPos = 0;

    int highPos =
        VectorUtil.binarySearch(ranges, new RangeHolder(high, high), rangeComparator, true);

    for (int i = (lowPos - 1 >= 0 ? lowPos - 1 : 0); i < highPos && i < ranges.size(); i++) {
      Range getMe = (Range) ranges.elementAt(i);
      if (overlaps(getMe, holder)) {
        output.addElement(data.get(getMe));
      }
    }

    return output;
  }
 public int[] getDefinedInterval(int key) {
   RangeHolder holder = new RangeHolder(key, key);
   int pos = VectorUtil.binarySearch(ranges, holder, rangeComparator, true) - 1;
   if (pos < 0 || pos >= ranges.size()) return null;
   Range r = (Range) ranges.elementAt(pos);
   if (r.getLow() <= key && r.getHigh() >= key) {
     int[] out = new int[2];
     out[0] = r.getLow();
     out[1] = r.getHigh();
     return out;
   } else return null;
 }
 // TODO: wtf?
 public int getIntervalIndex(int low, int high, boolean exact) {
   int lowPos =
       VectorUtil.binarySearch(ranges, new RangeHolder(low, high), rangeComparator, !exact);
   return lowPos;
 }