MinKSet(int maxSize, Comparator<T> comp) { this.maxSize = maxSize; this.comp = comp; this.data = new Long2ObjectRBTreeMap<T>(); this.min = null; this.max = null; this.presentCount = 0; this.missingCount = 0; }
@Override protected Long2ObjectRBTreeMap<V> create(Kryo kryo, Input input, Class<? extends Long2ObjectRBTreeMap<V>> type, int size, LongComparator comparator) { return new Long2ObjectRBTreeMap<V>(comparator); } }
public Orders(OrderBook parent, Side side, LongComparator priceComparator) { this.parent = parent; this.side = side; this.levels = new Long2ObjectRBTreeMap<>(priceComparator); }
public Orders(LongComparator priceComparator) { this.levels = new Long2ObjectRBTreeMap<>(priceComparator); }
/** * Create an order book. * * @param listener a listener for outbound events from the order book */ public OrderBook(OrderBookListener listener) { this.bids = new Long2ObjectRBTreeMap<>(LongComparators.OPPOSITE_COMPARATOR); this.asks = new Long2ObjectRBTreeMap<>(LongComparators.NATURAL_COMPARATOR); this.orders = new Long2ObjectOpenHashMap<>(); this.listener = listener; }
@Override @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") public IntFieldWriter getIntFieldWriter(final String field) throws IOException { return new IntFieldWriter() { private final Long2ObjectSortedMap<IntArrayList> terms = new Long2ObjectRBTreeMap<IntArrayList>(); private IntArrayList currentDocList; private long term; @Override public void nextTerm(long term) throws IOException { if (currentDocList != null && currentDocList.size() > 0) terms.put(this.term, currentDocList); this.term = term; currentDocList = new IntArrayList(); } @Override public void nextDoc(int doc) throws IOException { if (doc >= numDocs) { throw new IllegalArgumentException("invalid doc: doc="+doc+", numDocs="+numDocs); } currentDocList.add(doc); } @Override public void close() throws IOException { if (currentDocList != null && currentDocList.size() > 0) terms.put(term, currentDocList); intFields.put(field, terms); memoryUsageEstimate += usage(field, terms); } }; }
/** Create an order book. */ public OrderBook() { this.bids = new Long2ObjectRBTreeMap<>(LongComparators.OPPOSITE_COMPARATOR); this.asks = new Long2ObjectRBTreeMap<>(LongComparators.NATURAL_COMPARATOR); this.orders = new Long2ObjectOpenHashMap<>(); }
@Nullable public MinKSet<RowSnapshot> add(@Nullable MinKSet<RowSnapshot>left, @Nullable MinKSet<RowSnapshot> right) { assert left != null; assert right != null; Comparator<RowSnapshot> comp = left.comp; RowSnapshot minRS, maxRS; long present = left.presentCount + right.presentCount; if (left.presentCount == 0) { minRS = right.min; maxRS = right.max; } else if (right.presentCount == 0) { minRS = right.min; maxRS = right.max; } else { minRS = comp.compare(left.min, right.min) < 0 ? left.min : right.min; maxRS = comp.compare(left.max, right.max) > 0 ? left.max : right.max; } Long2ObjectRBTreeMap<RowSnapshot> data = new Long2ObjectRBTreeMap<>(); data.putAll(left.data); data.putAll(right.data); while (data.size() > this.numSamples) { long maxKey = data.lastLongKey(); data.remove(maxKey); } return new MinKSet<RowSnapshot>(this.numSamples, data, comp, minRS, maxRS, present, 0); } }
maxString = (left.max.compareTo(right.max) > 0) ? left.max : right.max; Long2ObjectRBTreeMap<String> data = new Long2ObjectRBTreeMap<>(); data.putAll(left.data); data.putAll(right.data);
intFields.put(intField, new Long2ObjectRBTreeMap<IntArrayList>());
Long2ObjectSortedMap<IntArrayList> myIntTerms = intFields.get(intField); if (myIntTerms == null) { intFields.put(intField, myIntTerms = new Long2ObjectRBTreeMap<IntArrayList>()); memoryUsageEstimate += TREE_MAP_ENTRY_USAGE + usage(intField) + INT_2_OBJECT_RB_TREE_MAP_USAGE;
Long2ObjectRBTreeMap<String> map = new Long2ObjectRBTreeMap<String>(); for (long hashKey: mkRows.hashMap.keySet()) map.put(hashKey, col.getString(mkRows.hashMap.get(hashKey)));
currRow = rowIt.getNextRow(); Long2ObjectRBTreeMap<RowSnapshot> hMap = new Long2ObjectRBTreeMap<RowSnapshot>(); for (long hashKey: mkRows.hashMap.keySet()) hMap.put(hashKey, new RowSnapshot(data, mkRows.hashMap.get(hashKey), schema));