/** * 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; } }
/** * Allocate a new object id. * * @return the id */ public synchronized int allocateObjectId() { int i = objectIds.nextClearBit(0); objectIds.set(i); return i; }
private int dumpPageFreeList(PrintWriter writer, Data s, long pageId, long pageCount) { int pagesAddressed = PageFreeList.getPagesAddressed(pageSize); BitField used = new BitField(); for (int i = 0; i < pagesAddressed; i += 8) { int x = s.readByte() & 255; for (int j = 0; j < 8; j++) { if ((x & (1 << j)) != 0) { used.set(i + j); writer.print(' '); writer.print(used.get((int) i) ? '1' : '0'); if (!used.get((int) i)) { free++;
int free = used.nextClearBit(start); if (free >= pageCount) { if (start == 0) { if (exclude != null && exclude.get(free + getPos())) { start = exclude.nextClearBit(free + getPos()) - getPos(); if (start >= pageCount) { return -1; used.set(free); store.logUndo(this, data); store.update(this);
0, pkCols, IndexType.createPrimaryKey( false, false), true, null); objectIds.set(0); starting = true; Cursor cursor = metaIdIndex.find(systemSession, null, null); while (cursor.next()) { MetaRecord rec = new MetaRecord(cursor.get()); objectIds.set(rec.getId()); records.add(rec); for (int i = 0, len = f.length(); i < len; i++) { if (f.get(i) && !objectIds.get(i)) { trace.info("unused object id: " + i); objectIds.set(i);
public synchronized int allocateObjectId(boolean needFresh, boolean dataFile) { // TODO refactor: use hash map instead of bit field for object ids needFresh = true; int i; if (needFresh) { i = objectIds.getLastSetBit() + 1; if ((i & 1) != (dataFile ? 1 : 0)) { i++; } while (storageMap.get(i) != null || objectIds.get(i)) { i++; if ((i & 1) != (dataFile ? 1 : 0)) { i++; } } } else { i = objectIds.nextClearBit(0); } if (SysProperties.CHECK && objectIds.get(i)) { throw Message.getInternalError(); } objectIds.set(i); return i; }
/** * Check if the undo entry was already written for the given page. * * @param pageId the page * @return true if it was written */ boolean getUndo(int pageId) { return undo.get(pageId); }
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; }
public void set(int i) { int addr = getAddress(i); checkCapacity(addr); data[addr] |= getBitMask(i); }
/** * Add a page to the free list. * * @param pageId the page id to add */ void free(int pageId) { full = false; store.logUndo(this, data); used.clear(pageId - getPos()); store.update(this); }
/** * 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 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); } } }
public void flush() throws SQLException { synchronized (database) { database.checkPowerOff(); ObjectArray list = cache.getAllChanged(); CacheObject.sort(list); for (int i = 0; i < list.size(); i++) { Record rec = (Record) list.get(i); writeBack(rec); } for (int i = 0; i < fileBlockCount; i++) { i = deleted.nextSetBit(i); if (i < 0) { break; } if (deleted.get(i)) { writeDirectDeleted(i, 1); deleted.clear(i); } } } }
/** * Set bit at the given index to 'false'. * * @param i the index */ public void clear(int i) { int addr = i >> ADDRESS_BITS; if (addr >= data.length) { return; } data[addr] &= ~getBitMask(i); }
public void clear(int i) { int addr = getAddress(i); if (addr >= data.length) { return; } data[addr] &= ~getBitMask(i); }
/** * 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; } }
/** * Get the first free page starting at the given offset. * * @param first the page number to start the search * @return the page number, or -1 */ int getFirstFree(int first) { if (full) { return -1; } int start = Math.max(0, first - getPos()); int free = used.nextClearBit(start); if (free >= pageCount) { return -1; } return free + getPos(); }