01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11: Suite 350, San Mateo, CA 94403, USA.
12:
13: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14: WARRANTY; without even the implied warranty of MERCHANTABILITY or
15: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16: for more details.
17:
18: You should have received a copy of the GNU General Public License along
19: with this program; if not, write to the Free Software Foundation, Inc.,
20: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21: package com.db4o.internal.freespace;
22:
23: import com.db4o.*;
24: import com.db4o.foundation.*;
25: import com.db4o.internal.*;
26: import com.db4o.internal.handlers.*;
27: import com.db4o.internal.ix.*;
28:
29: abstract class FreespaceIx {
30:
31: Index4 _index;
32:
33: IndexTransaction _indexTrans;
34:
35: IxTraverser _traverser;
36:
37: FreespaceVisitor _visitor;
38:
39: FreespaceIx(LocalObjectContainer file, MetaIndex metaIndex) {
40: _index = new Index4(file.getLocalSystemTransaction(),
41: new IntHandler(file), metaIndex, false);
42: _indexTrans = _index.globalIndexTransaction();
43: }
44:
45: abstract void add(int address, int length);
46:
47: abstract int address();
48:
49: public void debug() {
50: if (Debug.freespace) {
51: traverse(new Visitor4() {
52: public void visit(Object obj) {
53: System.out.println(obj);
54: }
55: });
56: }
57: }
58:
59: public int entryCount() {
60: return Tree.size(_indexTrans.getRoot());
61: }
62:
63: void find(int val) {
64: _traverser = new IxTraverser();
65: _traverser.findBoundsExactMatch(new Integer(val),
66: (IxTree) _indexTrans.getRoot());
67: }
68:
69: abstract int length();
70:
71: boolean match() {
72: _visitor = new FreespaceVisitor();
73: _traverser.visitMatch(_visitor);
74: return _visitor.visited();
75: }
76:
77: boolean preceding() {
78: _visitor = new FreespaceVisitor();
79: _traverser.visitPreceding(_visitor);
80: return _visitor.visited();
81: }
82:
83: abstract void remove(int address, int length);
84:
85: boolean subsequent() {
86: _visitor = new FreespaceVisitor();
87: _traverser.visitSubsequent(_visitor);
88: return _visitor.visited();
89: }
90:
91: public void traverse(Visitor4 visitor) {
92: Tree.traverse(_indexTrans.getRoot(), visitor);
93: }
94:
95: }
|