@Override public void remove(Session session, Row row) { if (closed) { throw DbException.throwInternalError(); } if (!treeMap.remove(getKey(row), row.getKey())) { throw DbException.throwInternalError("row not found"); } }
/** * Create a new map with the given dimensions and value type. * * @param <V> the value type * @param dimensions the number of dimensions * @param valueType the value type * @return the map */ public static <V> MVRTreeMap<V> create(int dimensions, DataType valueType) { return new MVRTreeMap<>(dimensions, valueType); }
private synchronized Object putOrAdd(SpatialKey key, V value, boolean alwaysAdd) { beforeWrite(); long v = writeVersion; Page p = root.copy(v); Object result; if (alwaysAdd || get(key) == null) { if (p.getMemory() > store.getPageSplitSize() && p.getKeyCount() > 3) { Page split = split(p, v); Object k1 = getBounds(p); Object k2 = getBounds(split); Object[] keys = { k1, k2 }; Page.PageReference[] children = { add(p, v, key, value); result = null; } else { result = set(p, v, key, value); newRoot(p); return result;
/** * Get the object for the given key. An exact match is required. * * @param p the page * @param key the key * @return the value, or null if not found */ protected Object get(Page p, Object key) { if (!p.isLeaf()) { for (int i = 0; i < p.getKeyCount(); i++) { if (contains(p, i, key)) { Object o = get(p.getChildPage(i), key); if (o != null) { return o; } } } } else { for (int i = 0; i < p.getKeyCount(); i++) { if (keyType.equals(p.getKey(i), key)) { return p.getValue(i); } } } return null; }
if (contains(p, i, key)) { index = i; break; if (c.getMemory() > store.getPageSplitSize() && c.getKeyCount() > 4) { Page split = split(c, writeVersion); p.setKey(index, getBounds(c)); p.setChild(index, c); p.insertNode(index, getBounds(split), split); add(p, writeVersion, key, value); return; add(c, writeVersion, key, value); Object bounds = p.getKey(index); keyType.increaseBounds(bounds, key);
@Override public Cursor findByGeometry(TableFilter filter, SearchRow first, SearchRow last, SearchRow intersection) { if (intersection == null) { return find(filter.getSession(), first, last); } return new SpatialCursor( treeMap.findIntersectingKeys(getKey(intersection)), table, filter.getSession()); }
/** {@inheritDoc} */ @Override public GridH2Row put(GridH2Row row) { Lock l = lock.writeLock(); l.lock(); try { checkClosed(); Value key = row.getValue(keyCol); assert key != null; Long rowId = keyToId.get(key); if (rowId != null) { Long oldRowId = treeMap.remove(getEnvelope(idToRow.get(rowId), rowId)); assert rowId.equals(oldRowId); } else { rowId = ++rowIds; keyToId.put(key, rowId); } GridH2Row old = idToRow.put(rowId, row); treeMap.put(getEnvelope(row, rowId), rowId); if (old == null) rowCnt++; // No replace. return old; } finally { l.unlock(); } }
@Override @SuppressWarnings("unchecked") public V get(Object key) { return (V) get(root, key); }
public MVRTreeMap(int dimensions, DataType valueType) { super(new SpatialDataType(dimensions), valueType); this.keyType = (SpatialDataType) getKeyType(); }
/** * Add all node keys (including internal bounds) to the given list. * This is mainly used to visualize the internal splits. * * @param list the list * @param p the root page */ public void addNodeKeys(ArrayList<SpatialKey> list, Page p) { if (p != null && !p.isLeaf()) { for (int i = 0; i < p.getKeyCount(); i++) { list.add((SpatialKey) p.getKey(i)); addNodeKeys(list, p.getChildPage(i)); } } }
@Override public void add(Session session, Row row) { if (closed) { throw DbException.throwInternalError(); } treeMap.add(getKey(row), row.getKey()); }
if (contains(p, i, key)) { index = i; break; if (c.getMemory() > store.getPageSplitSize() && c.getKeyCount() > 4) { Page split = split(c, writeVersion); p.setKey(index, getBounds(c)); p.setChild(index, c); p.insertNode(index, getBounds(split), split); add(p, writeVersion, key, value); return; add(c, writeVersion, key, value); Object bounds = p.getKey(index); keyType.increaseBounds(bounds, key);
/** * Get the object for the given key. An exact match is required. * * @param p the page * @param key the key * @return the value, or null if not found */ protected Object get(Page p, Object key) { if (!p.isLeaf()) { for (int i = 0; i < p.getKeyCount(); i++) { if (contains(p, i, key)) { Object o = get(p.getChildPage(i), key); if (o != null) { return o; } } } } else { for (int i = 0; i < p.getKeyCount(); i++) { if (keyType.equals(p.getKey(i), key)) { return p.getValue(i); } } } return null; }
@Override public Cursor findByGeometry(TableFilter filter, SearchRow first, SearchRow last, SearchRow intersection) { Session session = filter.getSession(); if (intersection == null) { return find(session, first, last); } Iterator<SpatialKey> cursor = spatialMap.findIntersectingKeys(getKey(intersection)); TransactionMap<SpatialKey, Value> map = getMap(session); Iterator<SpatialKey> it = map.wrapIterator(cursor, false); return new MVStoreCursor(session, it); }
@Override @SuppressWarnings("unchecked") public V get(Object key) { return (V) get(root, key); }
public MVRTreeMap(int dimensions, DataType valueType) { super(new SpatialDataType(dimensions), valueType); this.keyType = (SpatialDataType) getKeyType(); }