public static DBProperty search(final Database db, final BTree index, final String key) throws IndexException { final DBProperty[] result= new DBProperty[1]; index.accept(new IBTreeVisitor(){ @Override public int compare(long record) throws IndexException { return db.getString(db.getRecPtr(record + KEY)).compare(key, true); } @Override public boolean visit(long record) throws IndexException { result[0] = new DBProperty(db, record); return false; // There should never be duplicates. } }); return result[0]; }
public static DBProperty search(final Database db, final BTree index, final String key) throws IndexException { final DBProperty[] result= new DBProperty[1]; index.accept(new IBTreeVisitor(){ @Override public int compare(long record) throws IndexException { return db.getString(db.getRecPtr(record + KEY)).compare(key, true); } @Override public boolean visit(long record) throws IndexException { result[0] = new DBProperty(db, record); return false; // There should never be duplicates. } }); return result[0]; }
public static Set<String> getKeySet(final Database db, final BTree index) throws IndexException { final Set<String> result= new HashSet<String>(); index.accept(new IBTreeVisitor(){ @Override public int compare(long record) throws IndexException { return 0; } @Override public boolean visit(long record) throws IndexException { result.add(new DBProperty(db, record).getKey().getString()); return true; // There should never be duplicates. } }); return result; }
public static Set<String> getKeySet(final Database db, final BTree index) throws IndexException { final Set<String> result= new HashSet<String>(); index.accept(new IBTreeVisitor(){ @Override public int compare(long record) throws IndexException { return 0; } @Override public boolean visit(long record) throws IndexException { result.add(new DBProperty(db, record).getKey().getString()); return true; // There should never be duplicates. } }); return result; }
public boolean visitAll(final Nd nd, long address, final SearchCriteria searchCriteria, final Visitor<T> visitor) { return get(nd, address).accept(new SearchCriteriaToBtreeVisitorAdapter(searchCriteria, nd) { @SuppressWarnings("unchecked") @Override protected boolean acceptResult(long resultAddress) { return visitor.visit((T)NdNode.load(nd, resultAddress)); } }); }
public List<T> findAll(final Nd nd, long address, final SearchCriteria searchCriteria) { final List<T> result = new ArrayList<T>(); get(nd, address).accept(new SearchCriteriaToBtreeVisitorAdapter(searchCriteria, nd) { @SuppressWarnings("unchecked") @Override protected boolean acceptResult(long resultAddress) { result.add((T)NdNode.load(nd, resultAddress)); return true; } }); return result; }
public List<T> findAll(final Nd nd, long address, final SearchCriteria searchCriteria) { final List<T> result = new ArrayList<T>(); get(nd, address).accept(new SearchCriteriaToBtreeVisitorAdapter(searchCriteria, nd) { @SuppressWarnings("unchecked") @Override protected boolean acceptResult(long resultAddress) { result.add((T)NdNode.load(nd, resultAddress)); return true; } }); return result; }
public boolean visitAll(final Nd nd, long address, final SearchCriteria searchCriteria, final Visitor<T> visitor) { return get(nd, address).accept(new SearchCriteriaToBtreeVisitorAdapter(searchCriteria, nd) { @SuppressWarnings("unchecked") @Override protected boolean acceptResult(long resultAddress) { return visitor.visit((T)NdNode.load(nd, resultAddress)); } }); }
public List<T> findAll(final Nd nd, long address, final SearchCriteria searchCriteria, final int count) { final List<T> result = new ArrayList<T>(); get(nd, address).accept(new SearchCriteriaToBtreeVisitorAdapter(searchCriteria, nd) { int remainingCount = count; @SuppressWarnings("unchecked") @Override protected boolean acceptResult(long resultAddress) { result.add((T) NdNode.load(nd, resultAddress)); this.remainingCount--; return this.remainingCount > 0; } }); return result; }
public List<T> findAll(final Nd nd, long address, final SearchCriteria searchCriteria, final int count) { final List<T> result = new ArrayList<T>(); get(nd, address).accept(new SearchCriteriaToBtreeVisitorAdapter(searchCriteria, nd) { int remainingCount = count; @SuppressWarnings("unchecked") @Override protected boolean acceptResult(long resultAddress) { result.add((T) NdNode.load(nd, resultAddress)); this.remainingCount--; return this.remainingCount > 0; } }); return result; }
/** * Deletes all properties, does not delete the record associated with the object itself * - that is it can be re-populated. * @throws IndexException */ public void clear() throws IndexException { this.index.accept(new IBTreeVisitor(){ @Override public int compare(long address) throws IndexException { return 0; } @Override public boolean visit(long address) throws IndexException { new DBProperty(DBProperties.this.db, address).delete(); return false; // there should never be duplicates } }); }
/** * Deletes all properties, does not delete the record associated with the object itself * - that is it can be re-populated. * @throws IndexException */ public void clear() throws IndexException { this.index.accept(new IBTreeVisitor(){ @Override public int compare(long address) throws IndexException { return 0; } @Override public boolean visit(long address) throws IndexException { new DBProperty(DBProperties.this.db, address).delete(); return false; // there should never be duplicates } }); }
/** * Returns the entire contents of the index as a single list. */ public List<T> asList(final Nd nd, long address) { final List<T> result = new ArrayList<T>(); get(nd, address).accept(new IBTreeVisitor() { @Override public int compare(long record) { return 0; } @SuppressWarnings("unchecked") @Override public boolean visit(long resultAddress) { result.add((T)NdNode.load(nd, resultAddress)); return true; } }); return result; } }
/** * Returns the entire contents of the index as a single list. */ public List<T> asList(final Nd nd, long address) { final List<T> result = new ArrayList<T>(); get(nd, address).accept(new IBTreeVisitor() { @Override public int compare(long record) { return 0; } @SuppressWarnings("unchecked") @Override public boolean visit(long resultAddress) { result.add((T)NdNode.load(nd, resultAddress)); return true; } }); return result; } }
@SuppressWarnings("unchecked") public T findBest(final Nd nd, long address, final SearchCriteria searchCriteria, final IResultRank rankFunction) { final long[] resultRank = new long[1]; final long[] result = new long[1]; get(nd, address).accept(new SearchCriteriaToBtreeVisitorAdapter(searchCriteria, nd) { @Override protected boolean acceptResult(long resultAddress) { long rank = rankFunction.getRank(nd, resultAddress); if (rank >= resultRank[0]) { resultRank[0] = rank; result[0] = resultAddress; } return true; } }); if (result[0] == 0) { return null; } return (T)NdNode.load(nd, result[0]); }
@SuppressWarnings("unchecked") public T findBest(final Nd nd, long address, final SearchCriteria searchCriteria, final IResultRank rankFunction) { final long[] resultRank = new long[1]; final long[] result = new long[1]; get(nd, address).accept(new SearchCriteriaToBtreeVisitorAdapter(searchCriteria, nd) { @Override protected boolean acceptResult(long resultAddress) { long rank = rankFunction.getRank(nd, resultAddress); if (rank >= resultRank[0]) { resultRank[0] = rank; result[0] = resultAddress; } return true; } }); if (result[0] == 0) { return null; } return (T)NdNode.load(nd, result[0]); }
/** * Debugging method for checking B-tree invariants * @return the empty String if B-tree invariants hold, otherwise * a human readable report * @throws IndexException */ public String getInvariantsErrorReport() throws IndexException { InvariantsChecker checker = new InvariantsChecker(); accept(checker); return checker.isValid() ? "" : checker.getMsg(); //$NON-NLS-1$ }
/** * Debugging method for checking B-tree invariants * @return the empty String if B-tree invariants hold, otherwise * a human readable report * @throws IndexException */ public String getInvariantsErrorReport() throws IndexException { InvariantsChecker checker = new InvariantsChecker(); accept(checker); return checker.isValid() ? "" : checker.getMsg(); //$NON-NLS-1$ }