예제 #1
0
        private EliasFanoEncoder TstEFVI(long[] values, long indexInterval, long[] expIndexBits)
        {
            EliasFanoEncoder efEncVI = MakeEncoder(values, indexInterval);

            TstEqual("upperZeroBitPositionIndex", expIndexBits, efEncVI.IndexBits);
            return(efEncVI);
        }
예제 #2
0
 /// <summary>
 /// Construct a decoder for a given <seealso cref="EliasFanoEncoder"/>.
 /// The decoding index is set to just before the first encoded value.
 /// </summary>
 public EliasFanoDecoder(EliasFanoEncoder efEncoder)
 {
     this.EfEncoder = efEncoder;
     this.NumEncoded_Renamed = efEncoder.NumEncoded; // not final in EliasFanoEncoder
     this.NumIndexEntries = efEncoder.CurrentEntryIndex; // not final in EliasFanoEncoder
     this.IndexMask = (1L << efEncoder.NIndexEntryBits) - 1;
 }
예제 #3
0
 /// <summary>
 /// Construct a decoder for a given <seealso cref="EliasFanoEncoder"/>.
 /// The decoding index is set to just before the first encoded value.
 /// </summary>
 public EliasFanoDecoder(EliasFanoEncoder efEncoder)
 {
     this.EfEncoder          = efEncoder;
     this.NumEncoded_Renamed = efEncoder.NumEncoded;        // not final in EliasFanoEncoder
     this.NumIndexEntries    = efEncoder.CurrentEntryIndex; // not final in EliasFanoEncoder
     this.IndexMask          = (1L << efEncoder.NIndexEntryBits) - 1;
 }
예제 #4
0
 /// <summary>
 /// Construct a decoder for a given <seealso cref="EliasFanoEncoder"/>.
 /// The decoding index is set to just before the first encoded value.
 /// </summary>
 public EliasFanoDecoder(EliasFanoEncoder efEncoder)
 {
     this.efEncoder       = efEncoder;
     this.numEncoded      = efEncoder.numEncoded;        // not final in EliasFanoEncoder
     this.numIndexEntries = efEncoder.currentEntryIndex; // not final in EliasFanoEncoder
     this.indexMask       = (1L << efEncoder.nIndexEntryBits) - 1;
 }
예제 #5
0
        private static void TstEFS(long[] values, long[] expHighLongs, long[] expLowLongs)
        {
            EliasFanoEncoder efEncoder = MakeEncoder(values, EliasFanoEncoder.DEFAULT_INDEX_INTERVAL);

            TstEqual("upperBits", expHighLongs, efEncoder.UpperBits);
            TstEqual("lowerBits", expLowLongs, efEncoder.LowerBits);
            TstDecodeAll(efEncoder, values);
        }
예제 #6
0
        public virtual void TestIndexAdvanceToFirst()
        {
            long indexInterval = 2;

            long[]           twoLongs   = new long[] { 0, 2 };
            long[]           indexLongs = new long[] { 3 }; // high bits 1001
            EliasFanoEncoder efEncVI    = TstEFVI(twoLongs, indexInterval, indexLongs);

            Assert.AreEqual(0, efEncVI.Decoder.AdvanceToValue(0));
        }
예제 #7
0
        private static void TstEFSadvanceToAndBackToMultiples(long[] values, long maxValue, long minAdvanceMultiple)
        {
            EliasFanoEncoder efEncoder = MakeEncoder(values, EliasFanoEncoder.DEFAULT_INDEX_INTERVAL);

            for (long m = minAdvanceMultiple; m <= maxValue; m += 1)
            {
                TstDecodeAdvanceToMultiples(values, efEncoder.Decoder, m);
                TstDecodeBackToMultiples(values, efEncoder.Decoder, m);
            }
        }
예제 #8
0
        public virtual void TestIndexAdvanceToAfterLast()
        {
            long indexInterval = 2;

            long[]           twoLongs   = new long[] { 0, 2 };
            long[]           indexLongs = new long[] { 3 }; // high bits 1001
            EliasFanoEncoder efEncVI    = TstEFVI(twoLongs, indexInterval, indexLongs);

            Assert.AreEqual(EliasFanoDecoder.NO_MORE_VALUES, efEncVI.GetDecoder().AdvanceToValue(3));
        }
예제 #9
0
        public virtual void TestExample2NoIndex1() // Figure 2 from Vigna 2012 paper, no index, test broadword selection.
        {
            long indexInterval = 16;

            long[]           values     = new long[] { 5, 8, 8, 15, 32 }; // two low bits, high values 1,2,2,3,8.
            long[]           indexLongs = new long[0];                    // high bits 0b 0001 0000 0101 1010
            EliasFanoEncoder efEncVI    = TstEFVI(values, indexInterval, indexLongs);
            EliasFanoDecoder efDecVI    = efEncVI.Decoder;

            Assert.AreEqual(32, efDecVI.AdvanceToValue(22), "advance 22");
        }
예제 #10
0
        public virtual void TestExample2a() // Figure 2 from Vigna 2012 paper
        {
            long indexInterval = 4;

            long[]           values     = new long[] { 5, 8, 8, 15, 32 }; // two low bits, high values 1,2,2,3,8.
            long[]           indexLongs = new long[] { 8 + 12 * 16 };     // high bits 0b 0001 0000 0101 1010
            EliasFanoEncoder efEncVI    = TstEFVI(values, indexInterval, indexLongs);
            EliasFanoDecoder efDecVI    = efEncVI.Decoder;

            Assert.AreEqual(32, efDecVI.AdvanceToValue(22), "advance 22");
        }
예제 #11
0
        public override bool Equals(object other)
        {
            if (!(other is EliasFanoEncoder))
            {
                return(false);
            }
            EliasFanoEncoder oefs = (EliasFanoEncoder)other;

            // no equality needed for upperBound
            return((this.NumValues == oefs.NumValues) && (this.NumEncoded == oefs.NumEncoded) && (this.NumLowBits == oefs.NumLowBits) && (this.NumIndexEntries == oefs.NumIndexEntries) && (this.IndexInterval == oefs.IndexInterval) && Arrays.Equals(this.UpperLongs, oefs.UpperLongs) && Arrays.Equals(this.LowerLongs, oefs.LowerLongs)); // no need to check index content
        }
예제 #12
0
        public virtual void TestTwoIndexEntries()
        {
            long indexInterval = 2;

            long[]           twoLongs   = new long[] { 0, 1, 2, 3, 4, 5 };
            long[]           indexLongs = new long[] { 4 + 8 * 16 }; // high bits 0b10101010101
            EliasFanoEncoder efEncVI    = TstEFVI(twoLongs, indexInterval, indexLongs);
            EliasFanoDecoder efDecVI    = efEncVI.Decoder;

            Assert.AreEqual(0, efDecVI.AdvanceToValue(0), "advance 0");
            Assert.AreEqual(5, efDecVI.AdvanceToValue(5), "advance 5");
            Assert.AreEqual(EliasFanoDecoder.NO_MORE_VALUES, efDecVI.AdvanceToValue(5), "advance 6");
        }
예제 #13
0
        public virtual void TestHashCodeEquals()
        {
            long[]           values     = new long[] { 5, 8, 8, 15, 32 };
            EliasFanoEncoder efEncoder1 = MakeEncoder(values, EliasFanoEncoder.DEFAULT_INDEX_INTERVAL);
            EliasFanoEncoder efEncoder2 = MakeEncoder(values, EliasFanoEncoder.DEFAULT_INDEX_INTERVAL);

            Assert.AreEqual(efEncoder1, efEncoder2);
            Assert.AreEqual(efEncoder1.GetHashCode(), efEncoder2.GetHashCode());

            EliasFanoEncoder efEncoder3 = MakeEncoder(new long[] { 1, 2, 3 }, EliasFanoEncoder.DEFAULT_INDEX_INTERVAL);

            Assert.IsFalse(efEncoder1.Equals(efEncoder3));
            Assert.IsFalse(efEncoder3.Equals(efEncoder1));
            Assert.IsFalse(efEncoder1.GetHashCode() == efEncoder3.GetHashCode()); // implementation ok for these.
        }
예제 #14
0
 private static EliasFanoEncoder MakeEncoder(long[] values, long indexInterval)
 {
     long upperBound = -1L;
     foreach (long value in values)
     {
         Assert.IsTrue(value >= upperBound); // test data ok
         upperBound = value;
     }
     EliasFanoEncoder efEncoder = new EliasFanoEncoder(values.Length, upperBound, indexInterval);
     foreach (long value in values)
     {
         efEncoder.EncodeNext(value);
     }
     return efEncoder;
 }
예제 #15
0
        private static EliasFanoEncoder MakeEncoder(long[] values, long indexInterval)
        {
            long upperBound = -1L;

            foreach (long value in values)
            {
                Assert.IsTrue(value >= upperBound); // test data ok
                upperBound = value;
            }
            EliasFanoEncoder efEncoder = new EliasFanoEncoder(values.Length, upperBound, indexInterval);

            foreach (long value in values)
            {
                efEncoder.EncodeNext(value);
            }
            return(efEncoder);
        }
예제 #16
0
 /// <summary>
 /// Construct an EliasFanoDocIdSet. For efficient encoding, the parameters should be chosen as low as possible. </summary>
 /// <param name="numValues"> At least the number of document ids that will be encoded. </param>
 /// <param name="upperBound">  At least the highest document id that will be encoded. </param>
 public EliasFanoDocIdSet(int numValues, int upperBound)
 {
     EfEncoder = new EliasFanoEncoder(numValues, upperBound);
 }
예제 #17
0
 public static bool SufficientlySmallerThanBitSet(long numValues, long upperBound)
 {
     return(EliasFanoEncoder.SufficientlySmallerThanBitSet(numValues, upperBound));
 }
예제 #18
0
 /// <summary>
 /// Construct an EliasFanoDocIdSet. For efficient encoding, the parameters should be chosen as low as possible. </summary>
 /// <param name="numValues"> At least the number of document ids that will be encoded. </param>
 /// <param name="upperBound">  At least the highest document id that will be encoded. </param>
 public EliasFanoDocIdSet(int numValues, int upperBound)
 {
     efEncoder = new EliasFanoEncoder(numValues, upperBound);
 }
예제 #19
0
 private static void TstDecodeAll(EliasFanoEncoder efEncoder, long[] values)
 {
     TstDecodeAllNext(values, efEncoder.Decoder);
     TstDecodeAllPrev(values, efEncoder.Decoder);
     TstDecodeAllAdvanceToExpected(values, efEncoder.Decoder);
 }
예제 #20
0
 private static void TstDecodeAll(EliasFanoEncoder efEncoder, long[] values)
 {
     TstDecodeAllNext(values, efEncoder.Decoder);
     TstDecodeAllPrev(values, efEncoder.Decoder);
     TstDecodeAllAdvanceToExpected(values, efEncoder.Decoder);
 }
예제 #21
0
        private static void TstEFS2(long[] values)
        {
            EliasFanoEncoder efEncoder = MakeEncoder(values, EliasFanoEncoder.DEFAULT_INDEX_INTERVAL);

            TstDecodeAll(efEncoder, values);
        }