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.fastutil.io.FastByteArrayInputStream;
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:
37: /** A {@link BitStreamHPIndex} index loaded in memory.
38: *
39: * <p>In-memory indices are created by loading into main memory an index.
40: *
41: * @author Sebastiano Vigna
42: * @since 1.2
43: */
44:
45: public class InMemoryHPIndex extends BitStreamHPIndex {
46: private static final long serialVersionUID = 0L;
47:
48: /** The byte array containing the index. */
49: protected final byte[] index;
50: /** The byte array containing the positions. */
51: protected final byte[] positions;
52:
53: public InMemoryHPIndex(final byte[] index, final byte[] positions,
54: final int numberOfDocuments, final int numberOfTerms,
55: 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(index);
77: }
78:
79: @Override
80: public InputStream getInputStream() {
81: return new FastByteArrayInputStream(index);
82: }
83:
84: @Override
85: public InputBitStream getPositionsInputBitStream(
86: int bufferSizeUnused) throws IOException {
87: return new InputBitStream(positions);
88: }
89:
90: @Override
91: public InputStream getPositionsInputStream() throws IOException {
92: return new FastByteArrayInputStream(positions);
93: }
94: }
|