01: package it.unimi.dsi.mg4j.index;
02:
03: /*
04: * MG4J: Managing Gigabytes for Java
05: *
06: * Copyright (C) 2007 Sebastiano Vigna
07: *
08: * This library is free software; you can redistribute it and/or modify it
09: * under the terms of the GNU Lesser General Public License as published by the Free
10: * Software Foundation; either version 2.1 of the License, or (at your option)
11: * any later version.
12: *
13: * This library is distributed in the hope that it will be useful, but
14: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16: * for more details.
17: *
18: * You should have received a copy of the GNU Lesser General Public License
19: * along with this program; if not, write to the Free Software
20: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21: *
22: */
23:
24: import it.unimi.dsi.fastutil.ints.IntList;
25: import it.unimi.dsi.fastutil.longs.LongList;
26: import it.unimi.dsi.mg4j.index.CompressionFlags.Coding;
27: import it.unimi.dsi.mg4j.index.payload.Payload;
28: import it.unimi.dsi.io.ByteBufferInputStream;
29: import it.unimi.dsi.io.InputBitStream;
30: import it.unimi.dsi.util.Properties;
31: import it.unimi.dsi.util.StringMap;
32: import it.unimi.dsi.util.PrefixMap;
33:
34: import java.io.IOException;
35: import java.io.InputStream;
36: import java.nio.ByteBuffer;
37:
38: /** A memory-mapped {@link BitStreamHPIndex}. See the discussion in {@link MemoryMappedIndex} (and consider
39: * that since a high-performance index is actually split in two files, memory mapping is actually easier).
40: *
41: * @author Sebastiano Vigna
42: * @since 1.2
43: */
44:
45: public class MemoryMappedHPIndex extends BitStreamHPIndex {
46: private static final long serialVersionUID = 0L;
47:
48: /** The byte buffer containing the index. */
49: protected final ByteBuffer index;
50: /** The byte buffer containing the positions. */
51: protected final ByteBuffer positions;
52:
53: public MemoryMappedHPIndex(final ByteBuffer index,
54: final ByteBuffer positions, final int numberOfDocuments,
55: final int numberOfTerms, final long numberOfPostings,
56: final long numberOfOccurrences, final int maxCount,
57: final Payload payload, final Coding frequencyCoding,
58: final Coding pointerCoding, final Coding countCoding,
59: final Coding positionCoding, final int quantum,
60: final int height, final TermProcessor termProcessor,
61: final String field, final Properties properties,
62: final StringMap<? extends CharSequence> termMap,
63: final PrefixMap<? extends CharSequence> prefixMap,
64: final IntList sizes, final LongList offsets) {
65: super (numberOfDocuments, numberOfTerms, numberOfPostings,
66: numberOfOccurrences, maxCount, payload,
67: frequencyCoding, pointerCoding, countCoding,
68: positionCoding, quantum, height, -1, termProcessor,
69: field, properties, termMap, prefixMap, sizes, offsets);
70: this .index = index;
71: this .positions = positions;
72: }
73:
74: @Override
75: public InputBitStream getInputBitStream(int bufferSizeUnused) {
76: return new InputBitStream(getInputStream());
77: }
78:
79: @Override
80: public ByteBufferInputStream getInputStream() {
81: return new ByteBufferInputStream((ByteBuffer) index.duplicate()
82: .position(0));
83: }
84:
85: @Override
86: public InputBitStream getPositionsInputBitStream(
87: int bufferSizeUnused) throws IOException {
88: return new InputBitStream(getPositionsInputStream());
89: }
90:
91: @Override
92: public InputStream getPositionsInputStream() throws IOException {
93: return new ByteBufferInputStream((ByteBuffer) positions
94: .duplicate().position(0));
95: }
96: }
|