@ -72,7 +72,7 @@ public final class kelondroStack extends kelondroRecords {
}
public kelondroStack ( File file , long buffersize , int [ ] columns , boolean exitOnFail ) {
// this creates a new tree
// this creates a new stack
super ( file , buffersize , thisOHBytes , thisOHHandles , columns , thisFHandles , columns . length /* txtProps */ , 80 /* txtPropWidth */ , exitOnFail ) ;
try {
setHandle ( root , null ) ; // define the root value
@ -85,7 +85,7 @@ public final class kelondroStack extends kelondroRecords {
}
public kelondroStack ( File file , long buffersize ) throws IOException {
// this opens a file with an existing tree
// this opens a file with an existing stack
super ( file , buffersize ) ;
if ( ( getHandle ( root ) = = null ) & & ( getHandle ( toor ) = = null ) ) clear ( ) ;
}
@ -112,12 +112,15 @@ public final class kelondroStack extends kelondroRecords {
public class Counter implements Iterator {
Handle nextHandle = null ;
public Counter ( ) {
nextHandle = getHandle ( root ) ;
}
public boolean hasNext ( ) {
return ( nextHandle ! = null ) ;
}
public Object next ( ) {
Handle ret = nextHandle ;
try {
@ -127,19 +130,19 @@ public final class kelondroStack extends kelondroRecords {
throw new kelondroException ( filename , "IO error at Counter:next()" ) ;
}
}
public void remove ( ) {
throw new UnsupportedOperationException ( "no remove here.." ) ;
}
}
public synchronized void push ( byte [ ] [ ] row ) throws IOException {
if ( row . length ! = columns ( ) ) throw new IllegalArgumentException ( "push: wrong row length " + row . length + "; must be " + columns ( ) ) ;
public synchronized void push ( kelondroRow . Entry row ) throws IOException {
// check if there is already a stack
if ( getHandle ( toor ) = = null ) {
if ( getHandle ( root ) ! = null ) throw new RuntimeException ( "push: internal organisation of root and toor" ) ;
// create node
Node n = newNode ( ) ;
n . setValue Cells( row ) ;
n . setValue Row( row . bytes ( ) ) ;
n . setOHHandle ( left , null ) ;
n . setOHHandle ( right , null ) ;
n . commit ( CP_NONE ) ;
@ -150,7 +153,7 @@ public final class kelondroStack extends kelondroRecords {
} else {
// expand the list at the end
Node n = newNode ( ) ;
n . setValue Cells( row ) ;
n . setValue Row( row . bytes ( ) ) ;
n . setOHHandle ( left , getHandle ( toor ) ) ;
n . setOHHandle ( right , null ) ;
Node n1 = getNode ( getHandle ( toor ) , null , 0 ) ;
@ -163,16 +166,16 @@ public final class kelondroStack extends kelondroRecords {
}
}
public synchronized byte [ ] [ ] pop ( ) throws IOException {
public synchronized kelondroRow . Entry pop ( ) throws IOException {
// return row ontop of the stack and shrink stack by one
return pop ( 0 ) ;
}
public synchronized byte [ ] [ ] pop ( int dist ) throws IOException {
public synchronized kelondroRow . Entry pop ( int dist ) throws IOException {
// return row relative to top of the stack and remove addressed element
Node n = topNode ( dist ) ;
if ( n = = null ) return null ;
byte [ ] [ ] ret = n . getValueCells ( ) ;
kelondroRow . Entry ret = row ( ) . newEntry ( n . getValueRow ( ) ) ;
// remove node
unlinkNode ( n ) ;
@ -181,29 +184,29 @@ public final class kelondroStack extends kelondroRecords {
return ret ;
}
public synchronized byte [ ] [ ] top ( ) throws IOException {
public synchronized kelondroRow . Entry top ( ) throws IOException {
// return row ontop of the stack
return top ( 0 ) ;
}
public synchronized byte [ ] [ ] top ( int dist ) throws IOException {
public synchronized kelondroRow . Entry top ( int dist ) throws IOException {
// return row ontop of the stack
// with dist == 0 this is the same function as with top()
Node n = topNode ( dist ) ;
if ( n = = null ) return null ;
return n. getValueCells ( ) ;
return row( ) . newEntry ( n . getValueRow ( ) ) ;
}
public synchronized byte [ ] [ ] pot ( ) throws IOException {
public synchronized kelondroRow . Entry pot ( ) throws IOException {
// return row on the bottom of the stack and remove record
return pot ( 0 ) ;
}
public synchronized byte [ ] [ ] pot ( int dist ) throws IOException {
public synchronized kelondroRow . Entry pot ( int dist ) throws IOException {
// return row relative to the bottom of the stack and remove addressed element
Node n = botNode ( dist ) ;
if ( n = = null ) return null ;
byte [ ] [ ] ret = n . getValueCells ( ) ;
kelondroRow . Entry ret = row ( ) . newEntry ( n . getValueCells ( ) ) ;
// remove node
unlinkNode ( n ) ;
@ -212,17 +215,17 @@ public final class kelondroStack extends kelondroRecords {
return ret ;
}
public synchronized byte [ ] [ ] bot ( ) throws IOException {
public synchronized kelondroRow . Entry bot ( ) throws IOException {
// return row on the bottom of the stack
return bot ( 0 ) ;
}
public synchronized byte [ ] [ ] bot ( int dist ) throws IOException {
public synchronized kelondroRow . Entry bot ( int dist ) throws IOException {
// return row on bottom of the stack
// with dist == 0 this is the same function as with bot()
Node n = botNode ( dist ) ;
if ( n = = null ) return null ;
return n. getValueCells ( ) ;
return row( ) . newEntry ( n . getValueRow ( ) ) ;
}
public synchronized ArrayList botList ( int dist ) throws IOException {
@ -272,7 +275,8 @@ public final class kelondroStack extends kelondroRecords {
}
private Node queueNode ( int dist , int side , int dir ) throws IOException {
// with dist == 0 this is the same function as with getNode(getHandle(side), null, 0)
// with dist == 0 this is the same function as with
// getNode(getHandle(side), null, 0)
Handle h = getHandle ( side ) ;
if ( h = = null ) return null ;
if ( dist > = size ( ) ) return null ; // that would exceed the stack
@ -280,15 +284,6 @@ public final class kelondroStack extends kelondroRecords {
return getNode ( h ) ;
}
/ *
public synchronized byte [ ] [ ] seekPop ( byte [ ] key , long maxdepth ) throws IOException {
}
public synchronized byte [ ] [ ] seekPot ( byte [ ] key , long maxdepth ) throws IOException {
}
* /
public Iterator iterator ( ) {
// iterates the elements in an ordered way. returns Node - type Objects
return new Counter ( ) ;
@ -302,7 +297,7 @@ public final class kelondroStack extends kelondroRecords {
String s ;
StringTokenizer st ;
int recs = 0 ;
byte [ ] [ ] buffer = new byte [ columns ( ) ] [ ] ;
kelondroRow . Entry buffer = row ( ) . newEntry ( ) ;
int c ;
int line = 0 ;
while ( ( s = f . readLine ( ) ) ! = null ) {
@ -313,7 +308,7 @@ public final class kelondroStack extends kelondroRecords {
// buffer the entry
c = 0 ;
while ( ( c < columns ( ) ) & & ( st . hasMoreTokens ( ) ) ) {
buffer [c + + ] = st . nextToken ( ) . trim ( ) . getBytes ( ) ;
buffer .setCol ( c + + , st . nextToken ( ) . trim ( ) . getBytes ( ) ) ;
}
if ( ( st . hasMoreTokens ( ) ) | | ( c ! = columns ( ) ) ) {
System . err . println ( "inapropriate number of entries in line " + line ) ;
@ -331,7 +326,10 @@ public final class kelondroStack extends kelondroRecords {
}
public String hp ( Handle h ) {
if ( h = = null ) return "NULL" ; else return h . toString ( ) ;
if ( h = = null )
return "NULL" ;
else
return h . toString ( ) ;
}
public void print ( ) throws IOException {
@ -341,12 +339,15 @@ public final class kelondroStack extends kelondroRecords {
Iterator it = iterator ( ) ;
while ( it . hasNext ( ) ) {
n = ( Node ) it . next ( ) ;
//n = getNode(h, null, 0);
System . out . println ( "> NODE " + hp ( n . handle ( ) ) +
"; left " + hp ( n . getOHHandle ( left ) ) + ", right " + hp ( n . getOHHandle ( right ) ) ) ;
System . out . print ( " KEY:'" + ( new String ( n . getValueCells ( ) [ 0 ] ) ) . trim ( ) + "'" ) ;
// n = getNode(h, null, 0);
System . out . println ( "> NODE " + hp ( n . handle ( ) ) + "; left "
+ hp ( n . getOHHandle ( left ) ) + ", right "
+ hp ( n . getOHHandle ( right ) ) ) ;
System . out . print ( " KEY:'"
+ ( new String ( n . getValueCells ( ) [ 0 ] ) ) . trim ( ) + "'" ) ;
for ( int j = 1 ; j < columns ( ) ; j + + )
System . out . print ( ", V[" + j + "]:'" + ( new String ( n . getValueCells ( ) [ j ] ) ) . trim ( ) + "'" ) ;
System . out . print ( ", V[" + j + "]:'"
+ ( new String ( n . getValueCells ( ) [ j ] ) ) . trim ( ) + "'" ) ;
System . out . println ( ) ;
}
System . out . println ( ) ;
@ -372,8 +373,8 @@ public final class kelondroStack extends kelondroRecords {
ret = null ;
} else if ( args [ 0 ] . equals ( "-g" ) ) {
fm = new kelondroStack ( new File ( args [ 1 ] ) , 0x100000 ) ;
byte [ ] [ ] ret2 = fm . pop ( ) ;
ret = ( ( ret2 = = null ) ? null : ret2 [1 ] ) ;
kelondroRow . Entry ret2 = fm . pop ( ) ;
ret = ( ( ret2 = = null ) ? null : ret2 .getColBytes ( 1 ) ) ;
fm . close ( ) ;
}
fm . close ( ) ;
@ -404,8 +405,8 @@ public final class kelondroStack extends kelondroRecords {
}
} else if ( args [ 0 ] . equals ( "-g" ) ) {
kelondroStack fm = new kelondroStack ( new File ( args [ 2 ] ) , 0x100000 ) ;
byte [ ] [ ] ret2 = fm . pop ( Integer . parseInt ( args [ 1 ] ) ) ;
ret = ( ( ret2 = = null ) ? null : ret2 [1 ] ) ;
kelondroRow . Entry ret2 = fm . pop ( Integer . parseInt ( args [ 1 ] ) ) ;
ret = ( ( ret2 = = null ) ? null : ret2 .getColBytes ( 1 ) ) ;
fm . close ( ) ;
}
} else if ( args . length = = 4 ) {
@ -420,7 +421,7 @@ public final class kelondroStack extends kelondroRecords {
fm . close ( ) ;
} else if ( args [ 0 ] . equals ( "-p" ) ) {
kelondroStack fm = new kelondroStack ( new File ( args [ 3 ] ) , 0x100000 ) ;
fm . push ( new byte [ ] [ ] { args [ 1 ] . getBytes ( ) , args [ 2 ] . getBytes ( ) } ) ;
fm . push ( fm . row ( ) . newEntry ( new byte [ ] [ ] { args [ 1 ] . getBytes ( ) , args [ 2 ] . getBytes ( ) } ) ) ;
fm . close ( ) ;
}
}