18
18
19
19
import java .io .IOException ;
20
20
import java .util .Arrays ;
21
- import org .apache .lucene .codecs .CodecUtil ;
22
21
import org .apache .lucene .store .DataInput ;
23
22
import org .apache .lucene .store .DataOutput ;
24
- import org .apache .lucene .store .IndexInput ;
25
23
import org .apache .lucene .util .Accountable ;
26
24
import org .apache .lucene .util .LongsRef ;
27
25
import org .apache .lucene .util .RamUsageEstimator ;
@@ -506,13 +504,13 @@ public void clear() {
506
504
}
507
505
508
506
/**
509
- * Save this mutable into <code>out</code>. Instantiating a reader from the generated data will
510
- * return a reader with the same number of bits per value.
507
+ * Save this mutable into <code>out</code>. This method does not write any metadata to the
508
+ * stream, meaning that it is your responsibility to store it somewhere else in order to be able
509
+ * to recover data from the stream later on.
511
510
*/
512
511
public void save (DataOutput out ) throws IOException {
513
512
Writer writer =
514
513
getWriterNoHeader (out , getFormat (), size (), getBitsPerValue (), DEFAULT_BUFFER_SIZE );
515
- writer .writeHeader ();
516
514
for (int i = 0 ; i < size (); ++i ) {
517
515
writer .add (get (i ));
518
516
}
@@ -632,14 +630,6 @@ protected Writer(DataOutput out, int valueCount, int bitsPerValue) {
632
630
this .bitsPerValue = bitsPerValue ;
633
631
}
634
632
635
- void writeHeader () throws IOException {
636
- assert valueCount != -1 ;
637
- CodecUtil .writeHeader (out , CODEC_NAME , VERSION_CURRENT );
638
- out .writeVInt (bitsPerValue );
639
- out .writeVInt (valueCount );
640
- out .writeVInt (getFormat ().getId ());
641
- }
642
-
643
633
/** The format used to serialize values. */
644
634
protected abstract PackedInts .Format getFormat ();
645
635
@@ -716,24 +706,6 @@ public static Reader getReaderNoHeader(
716
706
}
717
707
}
718
708
719
- /**
720
- * Restore a {@link Reader} from a stream.
721
- *
722
- * @param in the stream to read data from
723
- * @return a Reader
724
- * @throws IOException If there is a low-level I/O error
725
- * @lucene.internal
726
- */
727
- public static Reader getReader (DataInput in ) throws IOException {
728
- final int version = CodecUtil .checkHeader (in , CODEC_NAME , VERSION_START , VERSION_CURRENT );
729
- final int bitsPerValue = in .readVInt ();
730
- assert bitsPerValue > 0 && bitsPerValue <= 64 : "bitsPerValue=" + bitsPerValue ;
731
- final int valueCount = in .readVInt ();
732
- final Format format = Format .byId (in .readVInt ());
733
-
734
- return getReaderNoHeader (in , format , version , valueCount , bitsPerValue );
735
- }
736
-
737
709
/**
738
710
* Expert: Restore a {@link ReaderIterator} from a stream without reading metadata at the
739
711
* beginning of the stream. This method is useful to restore data from streams which have been
@@ -756,76 +728,6 @@ public static ReaderIterator getReaderIteratorNoHeader(
756
728
return new PackedReaderIterator (format , version , valueCount , bitsPerValue , in , mem );
757
729
}
758
730
759
- /**
760
- * Retrieve PackedInts as a {@link ReaderIterator}
761
- *
762
- * @param in positioned at the beginning of a stored packed int structure.
763
- * @param mem how much memory the iterator is allowed to use to read-ahead (likely to speed up
764
- * iteration)
765
- * @return an iterator to access the values
766
- * @throws IOException if the structure could not be retrieved.
767
- * @lucene.internal
768
- */
769
- public static ReaderIterator getReaderIterator (DataInput in , int mem ) throws IOException {
770
- final int version = CodecUtil .checkHeader (in , CODEC_NAME , VERSION_START , VERSION_CURRENT );
771
- final int bitsPerValue = in .readVInt ();
772
- assert bitsPerValue > 0 && bitsPerValue <= 64 : "bitsPerValue=" + bitsPerValue ;
773
- final int valueCount = in .readVInt ();
774
- final Format format = Format .byId (in .readVInt ());
775
- return getReaderIteratorNoHeader (in , format , version , valueCount , bitsPerValue , mem );
776
- }
777
-
778
- /**
779
- * Expert: Construct a direct {@link Reader} from a stream without reading metadata at the
780
- * beginning of the stream. This method is useful to restore data from streams which have been
781
- * created using {@link PackedInts#getWriterNoHeader(DataOutput, Format, int, int, int)}.
782
- *
783
- * <p>The returned reader will have very little memory overhead, but every call to {@link
784
- * Reader#get(int)} is likely to perform a disk seek.
785
- *
786
- * @param in the stream to read data from
787
- * @param format the format used to serialize
788
- * @param version the version used to serialize the data
789
- * @param valueCount how many values the stream holds
790
- * @param bitsPerValue the number of bits per value
791
- * @return a direct Reader
792
- * @lucene.internal
793
- */
794
- public static Reader getDirectReaderNoHeader (
795
- final IndexInput in , Format format , int version , int valueCount , int bitsPerValue ) {
796
- checkVersion (version );
797
- switch (format ) {
798
- case PACKED :
799
- return new DirectPackedReader (bitsPerValue , valueCount , in );
800
- case PACKED_SINGLE_BLOCK :
801
- return new DirectPacked64SingleBlockReader (bitsPerValue , valueCount , in );
802
- default :
803
- throw new AssertionError ("Unknown format: " + format );
804
- }
805
- }
806
-
807
- /**
808
- * Construct a direct {@link Reader} from an {@link IndexInput}. This method is useful to restore
809
- * data from streams which have been created using {@link PackedInts#getWriter(DataOutput, int,
810
- * int, float)}.
811
- *
812
- * <p>The returned reader will have very little memory overhead, but every call to {@link
813
- * Reader#get(int)} is likely to perform a disk seek.
814
- *
815
- * @param in the stream to read data from
816
- * @return a direct Reader
817
- * @throws IOException If there is a low-level I/O error
818
- * @lucene.internal
819
- */
820
- public static Reader getDirectReader (IndexInput in ) throws IOException {
821
- final int version = CodecUtil .checkHeader (in , CODEC_NAME , VERSION_START , VERSION_CURRENT );
822
- final int bitsPerValue = in .readVInt ();
823
- assert bitsPerValue > 0 && bitsPerValue <= 64 : "bitsPerValue=" + bitsPerValue ;
824
- final int valueCount = in .readVInt ();
825
- final Format format = Format .byId (in .readVInt ());
826
- return getDirectReaderNoHeader (in , format , version , valueCount , bitsPerValue );
827
- }
828
-
829
731
/**
830
732
* Create a packed integer array with the given amount of values initialized to 0. the valueCount
831
733
* and the bitsPerValue cannot be changed after creation. All Mutables known by this factory are
@@ -913,49 +815,6 @@ public static Writer getWriterNoHeader(
913
815
return new PackedWriter (format , out , valueCount , bitsPerValue , mem );
914
816
}
915
817
916
- /**
917
- * Create a packed integer array writer for the given output, format, value count, and number of
918
- * bits per value.
919
- *
920
- * <p>The resulting stream will be long-aligned. This means that depending on the format which is
921
- * used under the hoods, up to 63 bits will be wasted. An easy way to make sure that no space is
922
- * lost is to always use a <code>valueCount</code> that is a multiple of 64.
923
- *
924
- * <p>This method writes metadata to the stream, so that the resulting stream is sufficient to
925
- * restore a {@link Reader} from it. You don't need to track <code>valueCount</code> or <code>
926
- * bitsPerValue</code> by yourself. In case this is a problem, you should probably look at {@link
927
- * #getWriterNoHeader(DataOutput, Format, int, int, int)}.
928
- *
929
- * <p>The <code>acceptableOverheadRatio</code> parameter controls how readers that will be
930
- * restored from this stream trade space for speed by selecting a faster but potentially less
931
- * memory-efficient implementation. An <code>acceptableOverheadRatio</code> of {@link
932
- * PackedInts#COMPACT} will make sure that the most memory-efficient implementation is selected
933
- * whereas {@link PackedInts#FASTEST} will make sure that the fastest implementation is selected.
934
- * In case you are only interested in reading this stream sequentially later on, you should
935
- * probably use {@link PackedInts#COMPACT}.
936
- *
937
- * @param out the data output
938
- * @param valueCount the number of values
939
- * @param bitsPerValue the number of bits per value
940
- * @param acceptableOverheadRatio an acceptable overhead ratio per value
941
- * @return a Writer
942
- * @throws IOException If there is a low-level I/O error
943
- * @lucene.internal
944
- */
945
- public static Writer getWriter (
946
- DataOutput out , int valueCount , int bitsPerValue , float acceptableOverheadRatio )
947
- throws IOException {
948
- assert valueCount >= 0 ;
949
-
950
- final FormatAndBits formatAndBits =
951
- fastestFormatAndBits (valueCount , bitsPerValue , acceptableOverheadRatio );
952
- final Writer writer =
953
- getWriterNoHeader (
954
- out , formatAndBits .format , valueCount , formatAndBits .bitsPerValue , DEFAULT_BUFFER_SIZE );
955
- writer .writeHeader ();
956
- return writer ;
957
- }
958
-
959
818
/**
960
819
* Returns how many bits are required to hold values up to and including maxValue NOTE: This
961
820
* method returns at least 1.
0 commit comments