@Override public String toString() { return "page [" + getPos() + "] freeList" + (full ? "full" : ""); }
/** * 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(); }
@Override public void moveTo(Session session, int newPos) { // the old data does not need to be copied, as free-list pages // at the end of the file are not required store.free(getPos(), false); }
/** * Check if a page is already in use. * * @param pageId the page to check * @return true if it is in use */ boolean isUsed(int pageId) { return used.get(pageId - getPos()); }
int getLastUsed() { int last = used.length() - 1; return last <= 0 ? -1 : last + getPos(); }
int start = Math.max(0, first - getPos()); while (true) { int free = used.nextClearBit(start); if (exclude != null && exclude.get(free + getPos())) { start = exclude.nextClearBit(free + getPos()) - getPos(); if (start >= pageCount) { return -1; store.logUndo(this, data); store.update(this); return free + getPos();
/** * 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); }
/** * Mark a page as used. * * @param pageId the page id */ void allocate(int pageId) { int idx = pageId - getPos(); if (idx >= 0 && !used.get(idx)) { // set the bit first, because logUndo can // allocate other pages, and we must not // return the same page twice used.set(idx); store.logUndo(this, data); store.update(this); } }
@Override public void write() { data = store.createData(); data.writeByte((byte) Page.TYPE_FREE_LIST); data.writeShortInt(0); for (int i = 0; i < pageCount; i += 8) { data.writeByte((byte) used.getByte(i)); } store.writePage(getPos(), data); }
@Override public String toString() { return "page [" + getPos() + "] freeList" + (full ? "full" : ""); }
@Override public String toString() { return "page [" + getPos() + "] freeList" + (full ? "full" : ""); }
@Override public void moveTo(Session session, int newPos) { // the old data does not need to be copied, as free-list pages // at the end of the file are not required store.free(getPos(), false); }
/** * Check if a page is already in use. * * @param pageId the page to check * @return true if it is in use */ boolean isUsed(int pageId) { return used.get(pageId - getPos()); }
/** * Check if a page is already in use. * * @param pageId the page to check * @return true if it is in use */ boolean isUsed(int pageId) { return used.get(pageId - getPos()); }
@Override public void moveTo(Session session, int newPos) { // the old data does not need to be copied, as free-list pages // at the end of the file are not required store.free(getPos(), false); }
int getLastUsed() { int last = used.length() - 1; return last <= 0 ? -1 : last + getPos(); }
/** * 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); }
/** * 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); }
@Override public void write() { data = store.createData(); data.writeByte((byte) Page.TYPE_FREE_LIST); data.writeShortInt(0); for (int i = 0; i < pageCount; i += 8) { data.writeByte((byte) used.getByte(i)); } store.writePage(getPos(), data); }
@Override public void write() { data = store.createData(); data.writeByte((byte) Page.TYPE_FREE_LIST); data.writeShortInt(0); for (int i = 0; i < pageCount; i += 8) { data.writeByte((byte) used.getByte(i)); } store.writePage(getPos(), data); }