private boolean shuffleTwo(TableFilter[] f) { int a = 0, b = 0, i = 0; for (; i < 20; i++) { a = random.nextInt(f.length); b = random.nextInt(f.length); if (a == b) { continue; } if (a < b) { int temp = a; a = b; b = temp; } int s = a * f.length + b; if (switched.get(s)) { continue; } switched.set(s); break; } if (i == 20) { return false; } TableFilter temp = f[a]; f[a] = f[b]; f[b] = temp; return true; }
/** * Allocate a new object id. * * @return the id */ public int allocateObjectId() { synchronized (objectIds) { int i = objectIds.nextClearBit(0); objectIds.set(i); return i; } }
/** * Set bit at the given index to 'true'. * * @param i the index */ public void set(int i) { int addr = i >> ADDRESS_BITS; checkCapacity(addr); data[addr] |= getBitMask(i); if (maxLength < i) { maxLength = i; } }
/** * Enable or disable a number of bits. * * @param fromIndex the index of the first bit to enable or disable * @param toIndex one plus the index of the last bit to enable or disable * @param value the new value */ public void set(int fromIndex, int toIndex, boolean value) { // go backwards so that OutOfMemory happens // before some bytes are modified for (int i = toIndex - 1; i >= fromIndex; i--) { set(i, value); } if (value) { if (toIndex > maxLength) { maxLength = toIndex; } } else { if (toIndex >= maxLength) { maxLength = fromIndex; } } }
private void registerOutParameter(int parameterIndex) throws SQLException { try { checkClosed(); if (outParameters == null) { maxOutParameters = Math.min(getParameterMetaData().getParameterCount(), getCheckedMetaData().getColumnCount()); outParameters = new BitField(); } checkIndexBounds(parameterIndex); CommandParameter param = command.getParameters().get(--parameterIndex); if (param.getValue() == null) { param.setValue(ValueNull.INSTANCE, false); } outParameters.set(parameterIndex); } catch (Exception e) { throw logAndConvert(e); } }
/** * Get the index of the next bit that is not set. * * @param fromIndex where to start searching * @return the index of the next disabled bit */ public int nextClearBit(int fromIndex) { int i = fromIndex >> ADDRESS_BITS; int max = data.length; for (; i < max; i++) { if (data[i] == -1) { continue; } int j = Math.max(fromIndex, i << ADDRESS_BITS); for (int end = j + 64; j < end; j++) { if (!get(j)) { return j; } } } return max << ADDRESS_BITS; }
private void removeUnusedChunks(TreeSet<Long> removedPages) { int size = removedPages.size(); for (BTreeChunk c : findUnusedChunks(removedPages)) { c.fileStorage.close(); c.fileStorage.delete(); chunks.remove(c.id); chunkIds.clear(c.id); removedPages.removeAll(c.pagePositions); } if (size > removedPages.size()) { writeChunkMetaData(lastChunk.id, removedPages); } }
private void calculateGenetic() { TableFilter[] best = new TableFilter[filters.length]; TableFilter[] list = new TableFilter[filters.length]; for (int x = 0; x < MAX_GENETIC; x++) { if (canStop(x)) { break; } boolean generateRandom = (x & 127) == 0; if (!generateRandom) { System.arraycopy(best, 0, list, 0, filters.length); if (!shuffleTwo(list)) { generateRandom = true; } } if (generateRandom) { switched = new BitField(); System.arraycopy(filters, 0, best, 0, filters.length); shuffleAll(best); System.arraycopy(best, 0, list, 0, filters.length); } if (testPlan(list)) { switched = new BitField(); System.arraycopy(list, 0, best, 0, filters.length); } } }
/** * Combine the next 8 bits at the given index with OR. * The index must be a multiple of 8. * * @param i the index * @param x the next 8 bits (0 - 255) */ public void setByte(int i, int x) { int addr = i >> ADDRESS_BITS; checkCapacity(addr); data[addr] |= ((long) x) << (i & (7 << 3)); if (maxLength < i && x != 0) { maxLength = i + 7; } }
public synchronized void rollbackMetaTable(ServerSession session) { ArrayList<MetaRecord> records = new ArrayList<>(); Cursor cursor = metaIdIndex.find(systemSession, null, null); while (cursor.next()) { MetaRecord rec = new MetaRecord(cursor.get()); objectIds.set(rec.getId()); records.add(rec); } objectIds.set(0); starting = true; Collections.sort(records); for (MetaRecord rec : records) { rec.execute(this, systemSession, eventListener); } recompileInvalidViews(); starting = false; }
private void checkRegistered(int parameterIndex) throws SQLException { try { checkIndexBounds(parameterIndex); if (!outParameters.get(parameterIndex - 1)) { throw DbException.getInvalidValueException("parameterIndex", parameterIndex); } } catch (Exception e) { throw logAndConvert(e); } }
/** * Remove the given object from the meta data. * * @param session the session * @param id the id of the object to remove */ public void removeMeta(ServerSession session, int id) { if (id > 0 && !starting) { SearchRow r = meta.getTemplateSimpleRow(false); r.setValue(0, ValueInt.get(id)); Cursor cursor = metaIdIndex.find(session, r, r); if (cursor.next()) { Row found = cursor.get(); meta.removeRow(session, found); synchronized (objectIds) { objectIds.clear(id); } } } }
private TreeSet<Long> executeSave(boolean force) { DataBuffer buff = getDataBuffer(); int id = chunkIds.nextClearBit(1); chunkIds.set(id); BTreeChunk c = new BTreeChunk(id); chunks.put(c.id, c);
private void addMeta(ServerSession session, DbObject obj) { int id = obj.getId(); if (id > 0 && !starting && !obj.isTemporary()) { Row r = meta.getTemplateRow(); MetaRecord rec = new MetaRecord(obj); rec.setRecord(r); synchronized (objectIds) { objectIds.set(id); } // if (SysProperties.CHECK) { // verifyMetaLocked(session); // } meta.addRow(session, r); } }
else { for (int id : getAllChunkIds()) { chunkIds.set(id);