Class BlockSourceFromPageManager
java.lang.Object
org.aksw.commons.io.binseach.BlockSourceFromPageManager
- All Implemented Interfaces:
BlockSource
A block source mainly for testing the rest of the block-based
machinery, such as binary search.
TODO Can we align block source and page manager?
Pages are backed by ByteBuffers and the assumption is, that no form of lazy loading is necessary.
The prime use case is memory mapped io, where ranges of file contents are made accessible via a ByteBuffer.
Hence, a Page only has a 'new buffer' method, which provides a mere duplicate on the buffer associated with the page.
Closing the page implicitly invalidates all buffers.
The PageNavigator provides a continuous view over a range of pages.
In contrast, blocks need to be sequentially read. Our abstraction makes it possible to both only read
as much data as necessary as well as view a sequence of blocks as a continuous segment.
E.g. when performing binary search, only the first record of a block has to
be decoded in order to examine the key.
The main difference between block and page is:
Pages provide access to the data using newBuffer: ByteBuffer - whereas blocks provide a
newChannel: Seekable method. Seekable is a subclass of Channel.
Now the gap is: Channels have a close method, ByteBuffers don't.
Under this perspective, closing the channels opened from a block is not necessary,
as closing the block invalidates the channels and unclosed channels do not keep the block open.
Blocks are created from the underlying buffer by chunking it into equal sizes
- Author:
- raven
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncontentAtOrAfter(long pos, boolean inclusive) contentAtOrBefore(long pos, boolean inclusive) longgetSizeOfBlock(long pos) booleanhasBlockAfter(long pos) booleanhasBlockBefore(long pos) longsize()Return the number of valid positions within blocks can be searched
-
Field Details
-
pageManager
-
-
Constructor Details
-
BlockSourceFromPageManager
public BlockSourceFromPageManager()
-
-
Method Details
-
contentAtOrBefore
- Specified by:
contentAtOrBeforein interfaceBlockSource- Throws:
IOException
-
contentAtOrAfter
- Specified by:
contentAtOrAfterin interfaceBlockSource- Throws:
IOException
-
hasBlockAfter
- Specified by:
hasBlockAfterin interfaceBlockSource- Throws:
IOException
-
hasBlockBefore
- Specified by:
hasBlockBeforein interfaceBlockSource- Throws:
IOException
-
getSizeOfBlock
- Specified by:
getSizeOfBlockin interfaceBlockSource- Throws:
IOException
-
size
Description copied from interface:BlockSourceReturn the number of valid positions within blocks can be searched- Specified by:
sizein interfaceBlockSource- Returns:
- Throws:
IOException
-