1
/* -*- tab-width: 4 -*-
3
* Electric(tm) VLSI Design System
5
* File: MemoryPageStorage.java
7
* Copyright (c) 2009 Sun Microsystems and Static Free Software
9
* Electric(tm) is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU Lesser General Public License as published by
11
* the Free Software Foundation; either version 3 of the License, or
12
* (at your option) any later version.
14
* Electric(tm) is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU Lesser General Public License for more details.
19
* You should have received a copy of the GNU Lesser General Public License
20
* along with Electric(tm); see the file COPYING. If not, write to
21
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
22
* Boston, Mass 02111-1307, USA.
24
package com.sun.electric.database.geometry.btree;
26
/** A PageStorage that uses plain old memory. */
27
public class MemoryPageStorage extends CachingPageStorage {
29
private CachedPageImpl[] pages;
32
public MemoryPageStorage(int pagesize) {
35
this.pages = new CachedPageImpl[1];
38
public int getNumPages() { return numpages; }
39
public int createPage() {
40
if (numpages >= pages.length) {
41
CachedPageImpl[] newpages = new CachedPageImpl[pages.length*2];
42
System.arraycopy(pages, 0, newpages, 0, pages.length);
45
pages[numpages] = new CachedPageImpl(numpages);
49
public void fsync(int pageid) { }
51
public void fsync() { }
52
public void writePage(int pageid, byte[] buf, int ofs) {
53
System.arraycopy(buf, ofs, pages[pageid].buf, 0, getPageSize());
55
public void readPage(int pageid, byte[] buf, int ofs) {
56
System.arraycopy(pages[pageid].buf, 0, buf, ofs, getPageSize());
58
public synchronized void close() { pages = null; }
59
public CachedPage getPage(int pageid, boolean readBytes) { return pages[pageid]; }
61
private class CachedPageImpl extends CachedPage {
64
private boolean dirty;
65
public CachedPageImpl(int pageid) { this.pageid = pageid; this.buf = new byte[getPageSize()]; }
66
public byte[] getBuf() { return buf; }
67
public int getPageId() { return pageid; }
68
public void touch() { }
69
public void setDirty() { this.dirty = true; }
70
public void flush() { this.dirty = false; }
71
public boolean isDirty() { return dirty; }
b'\\ No newline at end of file'