com.tagtraum.perf.datastructures
Class IntegerSortPipe
java.lang.Object
|
+--com.tagtraum.perf.datastructures.IntegerSortPipe
- All Implemented Interfaces:
- java.nio.channels.Channel, java.nio.channels.ReadableByteChannel, java.nio.channels.WritableByteChannel
- public class IntegerSortPipe
- extends java.lang.Object
- implements java.nio.channels.ReadableByteChannel, java.nio.channels.WritableByteChannel
Pipe that sorts ints that lie within a certain range. I.e. offset <= i <= capacity.
After instantiation you are expected to provide a ByteBuffer
to the
read(ByteBuffer)
-method. The ByteBuffer will be interpreted as an IntBuffer.
After you provided all int you wanted to sort, you may call the write(ByteBuffer)
-method
to receive the sorted ints. They will be written to the given ByteBuffer
.
Note that even if you provided the same int twice, it will occur only once in the sorted
output.
This class is designed to work with FileChannel.transferTo(long, long, WritableByteChannel)
and
FileChannel.transferFrom(ReadableByteChannel, long, long)
. Note that some versions of Sun JDK 1.4.0
have bugs in these methods and cause the VM to crash.
- Version:
- $Id: $
- Author:
- Hendrik Schreiber
- See Also:
IntegerSortPipe1
,
FileChannel.transferTo(long, long, WritableByteChannel)
,
FileChannel.transferFrom(ReadableByteChannel, long, long)
Method Summary |
void |
close()
|
boolean |
isOpen()
|
int |
read(java.nio.ByteBuffer sortedInts)
Call this method to read the sorted ints in a ByteBuffer. |
int |
write(java.nio.ByteBuffer unsortedInts)
Call this method to write unsorted ints in a ByteBuffer. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
IntegerSortPipe
public IntegerSortPipe(int capacity,
int offset)
read
public int read(java.nio.ByteBuffer sortedInts)
throws java.io.IOException
- Call this method to read the sorted ints in a ByteBuffer.
- Specified by:
read
in interface java.nio.channels.ReadableByteChannel
- Parameters:
sortedInts
- ByteBuffer with sorted ints (after this method returns)
- Returns:
- bytes written to the buffer
- Throws:
java.nio.channels.ClosedChannelException
- after you have started reading with
read(ByteBuffer)
until you have read all sorted ints.
java.io.IOException
write
public int write(java.nio.ByteBuffer unsortedInts)
throws java.io.IOException
- Call this method to write unsorted ints in a ByteBuffer.
- Specified by:
write
in interface java.nio.channels.WritableByteChannel
- Parameters:
unsortedInts
- ByteBuffer with ints (4 bytes each)
- Returns:
- bytes read from the buffer
- Throws:
java.nio.channels.ClosedChannelException
- after you have started reading with
read(ByteBuffer)
until you have read all sorted ints.
java.io.IOException
isOpen
public boolean isOpen()
- Specified by:
isOpen
in interface java.nio.channels.Channel
close
public void close()
throws java.io.IOException
- Specified by:
close
in interface java.nio.channels.Channel
java.io.IOException
Copyright © 2002 Hendrik Schreiber
http://www.tagtraum.com/performance/
This software can be distributed under LGPL