List of usage examples for java.util TreeMap ceilingEntry
public Map.Entry<K, V> ceilingEntry(K key)
From source file:Main.java
public static void main(String[] args) { TreeMap<Integer, String> treemap = new TreeMap<Integer, String>(); // populating tree map treemap.put(2, "two"); treemap.put(1, "one"); treemap.put(3, "three"); treemap.put(6, "six"); treemap.put(5, "from java2s.com"); System.out.println("Ceiling entry for 4: " + treemap.ceilingEntry(4)); System.out.println("Ceiling entry for 5: " + treemap.ceilingEntry(5)); }
From source file:com.vgi.mafscaling.Rescale.java
private void calculateNewGs(ArrayList<Double> newVoltArray, ArrayList<Double> newGsArray) { TreeMap<Double, Integer> vgsTree = new TreeMap<Double, Integer>(); for (int i = origVoltArray.size() - 1; i >= 0; --i) vgsTree.put(origVoltArray.get(i), i); Map.Entry<Double, Integer> kv; double x0, y0, x, y, x1, y1; for (int i = 1; i < newVoltArray.size(); ++i) { x = newVoltArray.get(i);//w ww . j av a2 s.c om kv = vgsTree.floorEntry(x); if (kv == null) { newGsArray.add(0.0); continue; } x0 = kv.getKey(); if (x0 == x) { newGsArray.add(origGsArray.get(kv.getValue())); continue; } y0 = origGsArray.get(kv.getValue()); kv = vgsTree.ceilingEntry(x); if (kv == null) { newGsArray.add(0.0); continue; } x1 = kv.getKey(); y1 = origGsArray.get(kv.getValue()); y = Utils.linearInterpolation(x, x0, x1, y0, y1); newGsArray.add(y); } }
From source file:org.apache.hadoop.io.ElasticByteBufferPool.java
@Override public synchronized ByteBuffer getBuffer(boolean direct, int length) { TreeMap<Key, ByteBuffer> tree = getBufferTree(direct); Map.Entry<Key, ByteBuffer> entry = tree.ceilingEntry(new Key(length, 0)); if (entry == null) { return direct ? ByteBuffer.allocateDirect(length) : ByteBuffer.allocate(length); }//from w w w . j av a2s . c o m tree.remove(entry.getKey()); return entry.getValue(); }
From source file:org.apache.sysml.runtime.compress.PlanningBinPacker.java
private TreeMap<Float, List<List<Integer>>> packFirstFit(List<Integer> items, List<Float> itemWeights) { // when searching for a bin, the first bin in the list is used TreeMap<Float, List<List<Integer>>> bins = new TreeMap<Float, List<List<Integer>>>(); // first bin//from ww w .ja va 2s. co m bins.put(_binWeight, createBinList()); int numItems = items.size(); for (int i = 0; i < numItems; i++) { float itemWeight = itemWeights.get(i); Map.Entry<Float, List<List<Integer>>> entry = bins.ceilingEntry(itemWeight); if (entry == null) { // new bin float newBinWeight = _binWeight - itemWeight; List<List<Integer>> binList = bins.get(newBinWeight); if (binList == null) { bins.put(newBinWeight, createBinList(items.get(i))); } else { List<Integer> newBin = new ArrayList<Integer>(); newBin.add(items.get(i)); binList.add(newBin); } } else { // add to the first bin in the list List<Integer> assignedBin = entry.getValue().remove(0); assignedBin.add(items.get(i)); if (entry.getValue().size() == 0) bins.remove(entry.getKey()); float newBinWeight = entry.getKey() - itemWeight; List<List<Integer>> newBinsList = bins.get(newBinWeight); if (newBinsList == null) { // new bin bins.put(newBinWeight, createBinList(assignedBin)); } else { newBinsList.add(assignedBin); } } } return bins; }
From source file:org.apache.tajo.storage.thirdparty.orc.ByteBufferAllocatorPool.java
public ByteBuffer getBuffer(boolean direct, int length) { TreeMap<Key, ByteBuffer> tree = getBufferTree(direct); Map.Entry<Key, ByteBuffer> entry = tree.ceilingEntry(new Key(length, 0)); if (entry == null) { return direct ? ByteBuffer.allocateDirect(length) : ByteBuffer.allocate(length); }// ww w . ja v a2s .com tree.remove(entry.getKey()); return entry.getValue(); }
From source file:org.grouplens.samantha.modeler.featurizer.PercentileModel.java
private double getPercentileFromTreeMap(TreeMap<Double, Double> treeMap, double value) { Map.Entry<Double, Double> entry = treeMap.ceilingEntry(value); if (entry == null) { return 1.0; } else {/* w w w. j a va 2 s .c o m*/ return entry.getValue(); } }