01: package it.unimi.dsi.mg4j.index;
02:
03: /*
04: * MG4J: Managing Gigabytes for Java
05: *
06: * Copyright (C) 2005-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.InputStream;
35:
36: /** A local bitstream index loaded in memory.
37: *
38: * <p>In-memory indices are created by loading into main memory
39: * an index.
40: *
41: * @author Sebastiano Vigna
42: * @since 1.1
43: */
44:
45: public class InMemoryIndex extends BitStreamIndex {
46: private static final long serialVersionUID = 0L;
47:
48: /** The byte array containing the index. */
49: protected final byte[] index;
50:
51: public InMemoryIndex(final byte[] index,
52: final int numberOfDocuments, final int numberOfTerms,
53: final long numberOfPostings,
54: final long numberOfOccurrences, final int maxCount,
55: final Payload payload, final Coding frequencyCoding,
56: final Coding pointerCoding, final Coding countCoding,
57: final Coding positionCoding, final int quantum,
58: final int height, final TermProcessor termProcessor,
59: final String field, final Properties properties,
60: final StringMap<? extends CharSequence> termMap,
61: final PrefixMap<? extends CharSequence> prefixMap,
62: final IntList sizes, final LongList offsets) {
63: super (numberOfDocuments, numberOfTerms, numberOfPostings,
64: numberOfOccurrences, maxCount, payload,
65: frequencyCoding, pointerCoding, countCoding,
66: positionCoding, quantum, height, -1, termProcessor,
67: field, properties, termMap, prefixMap, sizes, offsets);
68: this .index = index;
69: }
70:
71: @Override
72: public InputBitStream getInputBitStream(int bufferSizeUnused) {
73: return new InputBitStream(index);
74: }
75:
76: @Override
77: public InputStream getInputStream() {
78: return new FastByteArrayInputStream(index);
79: }
80: }
|