001: // You can redistribute this software and/or modify it under the terms of
002: // the Ozone Library License version 1 published by ozone-db.org.
003: //
004: // The original code and portions created by SMB are
005: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
006: //
007: // $Id: DxDiskHashIterator.java,v 1.2 2002/06/08 00:49:38 mediumnet Exp $
008:
009: package org.ozoneDB.DxLib;
010:
011: /**
012: *
013: *
014: * @author <a href="http://www.softwarebuero.de/">SMB</a>
015: * @version $Revision: 1.2 $Date: 2002/06/08 00:49:38 $
016: */
017: public final class DxDiskHashIterator extends DxAbstractIterator {
018:
019: final static long serialVersionUID = 1L;
020:
021: DxKeyData current;
022:
023: DxDeque stack;
024:
025: DxDiskHashMap hm;
026:
027: public DxDiskHashIterator(DxDiskHashMap _hm) {
028: hm = _hm;
029: reset();
030: }
031:
032: public void reset() {
033: current = new DxKeyData(null, null);
034:
035: stack = new DxArrayDeque();
036:
037: DxDiskSubTable rootTable = hm.rootTable();
038: for (int i = 0; i < rootTable.table.length; i++) {
039: if (rootTable.table[i] != null) {
040: stack.push(rootTable.table[i]);
041: }
042: }
043:
044: // DxDiskHashNodeBranch nodeBranch = hm.newNodeBranch();
045: // nodeBranch.subTable = hm.rootTable();
046: // stack.push( nodeBranch );
047:
048: nextEntry();
049:
050: atFirstObject = true;
051: objectRemoved = false;
052: }
053:
054: public Object object() {
055: return current.data;
056: }
057:
058: public Object key() {
059: return current.key;
060: }
061:
062: public Object next() {
063: Object obj = object();
064:
065: if (atFirstObject) {
066: atFirstObject = false;
067: } else {
068: if (obj != null && !objectRemoved) {
069: nextEntry();
070: obj = object();
071: }
072: objectRemoved = false;
073: }
074: return obj;
075: }
076:
077: public Object removeObject() {
078: throw new UnsupportedOperationException("removeObject()");
079: // Object obj = object();
080: // if (obj != null && !objectRemoved) {
081: // DxBBnode delNode = node;
082: // if (node.re != null) {
083: // node = leftMost( node.re );
084: // } else {
085: // node = firstRightParent( node );
086: // }
087: // bbtree.removeForKey( delNode.key );
088: // objectRemoved = true;
089: // }
090: // return obj;
091: }
092:
093: /**
094: * Depth first serach via the stack.
095: */
096: private void nextEntry() {
097: try {
098: DxDiskHashNode node = (DxDiskHashNode) stack.pop();
099:
100: if (node == null) {
101: current.set(null, null);
102: } else if (node instanceof DxDiskHashNodeLeaf) {
103: DxDiskHashNodeLeaf nodeLeaf = (DxDiskHashNodeLeaf) node;
104: current.set(nodeLeaf.element().key,
105: nodeLeaf.element().data);
106: } else if (node instanceof DxDiskHashNodeBranch) {
107: DxDiskHashNodeBranch nodeBranch = (DxDiskHashNodeBranch) node;
108: DxDiskHashNode[] table = nodeBranch.subTable
109: .fetchedTable();
110:
111: for (int i = 0; i < table.length; i++) {
112: if (table[i] != null) {
113: stack.push(table[i]);
114: }
115: }
116: nextEntry();
117: } else {
118: throw new RuntimeException("Unknown node type: " + node);
119: }
120: } catch (Exception e) {
121: throw new RuntimeException(e.toString());
122: }
123: }
124: }
|