Example #1
0
        private static void TstDecodeAdvanceToMultiples(long[] values, EliasFanoDecoder efd, long m)
        {
            // test advancing to multiples of m
            Debug.Assert(m > 0);
            long previousValue = -1L;
            long index         = 0;
            long mm            = m;

            efd.ToBeforeSequence();
            foreach (long expValue in values)
            {
                // mm > previousValue
                if (expValue >= mm)
                {
                    long advanceValue = efd.AdvanceToValue(mm);
                    Assert.IsFalse(EliasFanoDecoder.NO_MORE_VALUES == advanceValue, "advanceValue at end too early");
                    Assert.AreEqual(expValue, advanceValue);
                    Assert.AreEqual(index, efd.CurrentIndex());
                    previousValue = expValue;
                    do
                    {
                        mm += m;
                    } while (mm <= previousValue);
                }
                index++;
            }
            long advanceValue_ = efd.AdvanceToValue(mm);

            Assert.AreEqual(EliasFanoDecoder.NO_MORE_VALUES, advanceValue_);
        }
Example #2
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");
        }
Example #3
0
 private static void TstDecodeAllPrev(long[] values, EliasFanoDecoder efd)
 {
     efd.ToAfterSequence();
     for (int i = values.Length - 1; i >= 0; i--)
     {
         long previousValue = efd.PreviousValue();
         Assert.IsFalse(EliasFanoDecoder.NO_MORE_VALUES == previousValue, "previousValue at end too early");
         Assert.AreEqual(values[i], previousValue);
     }
     Assert.AreEqual(EliasFanoDecoder.NO_MORE_VALUES, efd.PreviousValue());
 }
 private static void TstDecodeAllPrev(long[] values, EliasFanoDecoder efd)
 {
     efd.ToAfterSequence();
     for (int i = values.Length - 1; i >= 0; i--)
     {
         long previousValue = efd.PreviousValue();
         Assert.IsFalse(EliasFanoDecoder.NO_MORE_VALUES == previousValue, "previousValue at end too early");
         Assert.AreEqual(values[i], previousValue);
     }
     Assert.AreEqual(EliasFanoDecoder.NO_MORE_VALUES, efd.PreviousValue());
 }
Example #5
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");
        }
 private static void TstDecodeAllNext(long[] values, EliasFanoDecoder efd)
 {
     efd.ToBeforeSequence();
     long nextValue = efd.NextValue();
     foreach (long expValue in values)
     {
         Assert.IsFalse(EliasFanoDecoder.NO_MORE_VALUES == nextValue, "nextValue at end too early");
         Assert.AreEqual(expValue, nextValue);
         nextValue = efd.NextValue();
     }
     Assert.AreEqual(EliasFanoDecoder.NO_MORE_VALUES, nextValue);
 }
Example #7
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");
        }
Example #8
0
        private static void TstDecodeAllNext(long[] values, EliasFanoDecoder efd)
        {
            efd.ToBeforeSequence();
            long nextValue = efd.NextValue();

            foreach (long expValue in values)
            {
                Assert.IsFalse(EliasFanoDecoder.NO_MORE_VALUES == nextValue, "nextValue at end too early");
                Assert.AreEqual(expValue, nextValue);
                nextValue = efd.NextValue();
            }
            Assert.AreEqual(EliasFanoDecoder.NO_MORE_VALUES, nextValue);
        }
Example #9
0
        private static void TstDecodeBackToMultiples(long[] values, EliasFanoDecoder efd, long m)
        {
            // test backing to multiples of m
            if (Debugging.AssertsEnabled)
            {
                Debugging.Assert(m > 0);
            }
            efd.ToAfterSequence();
            int index = values.Length - 1;

            if (index < 0)
            {
                long advanceValue = efd.BackToValue(0);
                Assert.AreEqual(EliasFanoDecoder.NO_MORE_VALUES, advanceValue);
                return; // empty values, nothing to go back to/from
            }
            long expValue      = values[index];
            long previousValue = expValue + 1;
            long mm            = (expValue / m) * m;

            while (index >= 0)
            {
                expValue = values[index];
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(mm < previousValue);
                }
                if (expValue <= mm)
                {
                    long backValue_ = efd.BackToValue(mm);
                    Assert.IsFalse(EliasFanoDecoder.NO_MORE_VALUES == backValue_, "backToValue at end too early");
                    Assert.AreEqual(expValue, backValue_);
                    Assert.AreEqual(index, efd.CurrentIndex());
                    previousValue = expValue;
                    do
                    {
                        mm -= m;
                    } while (mm >= previousValue);
                }
                index--;
            }
            long backValue = efd.BackToValue(mm);

            Assert.AreEqual(EliasFanoDecoder.NO_MORE_VALUES, backValue);
        }
 private static void TstDecodeAllAdvanceToExpected(long[] values, EliasFanoDecoder efd)
 {
     efd.ToBeforeSequence();
     long previousValue = -1L;
     long index = 0;
     foreach (long expValue in values)
     {
         if (expValue > previousValue)
         {
             long advanceValue = efd.AdvanceToValue(expValue);
             Assert.IsFalse(EliasFanoDecoder.NO_MORE_VALUES == advanceValue, "advanceValue at end too early");
             Assert.AreEqual(expValue, advanceValue);
             Assert.AreEqual(index, efd.CurrentIndex());
             previousValue = expValue;
         }
         index++;
     }
     long advanceValue_ = efd.AdvanceToValue(previousValue + 1);
     Assert.AreEqual(EliasFanoDecoder.NO_MORE_VALUES, advanceValue_, "at end");
 }
Example #11
0
        private static void TstDecodeAllAdvanceToExpected(long[] values, EliasFanoDecoder efd)
        {
            efd.ToBeforeSequence();
            long previousValue = -1L;
            long index         = 0;

            foreach (long expValue in values)
            {
                if (expValue > previousValue)
                {
                    long advanceValue = efd.AdvanceToValue(expValue);
                    Assert.IsFalse(EliasFanoDecoder.NO_MORE_VALUES == advanceValue, "advanceValue at end too early");
                    Assert.AreEqual(expValue, advanceValue);
                    Assert.AreEqual(index, efd.CurrentIndex());
                    previousValue = expValue;
                }
                index++;
            }
            long advanceValue_ = efd.AdvanceToValue(previousValue + 1);

            Assert.AreEqual(EliasFanoDecoder.NO_MORE_VALUES, advanceValue_, "at end");
        }
 private static void TstDecodeBackToMultiples(long[] values, EliasFanoDecoder efd, long m)
 {
     // test backing to multiples of m
     Debug.Assert(m > 0);
     efd.ToAfterSequence();
     int index = values.Length - 1;
     if (index < 0)
     {
         long advanceValue = efd.BackToValue(0);
         Assert.AreEqual(EliasFanoDecoder.NO_MORE_VALUES, advanceValue);
         return; // empty values, nothing to go back to/from
     }
     long expValue = values[index];
     long previousValue = expValue + 1;
     long mm = (expValue / m) * m;
     while (index >= 0)
     {
         expValue = values[index];
         Debug.Assert(mm < previousValue);
         if (expValue <= mm)
         {
             long backValue_ = efd.BackToValue(mm);
             Assert.IsFalse(EliasFanoDecoder.NO_MORE_VALUES == backValue_, "backToValue at end too early");
             Assert.AreEqual(expValue, backValue_);
             Assert.AreEqual(index, efd.CurrentIndex());
             previousValue = expValue;
             do
             {
                 mm -= m;
             } while (mm >= previousValue);
         }
         index--;
     }
     long backValue = efd.BackToValue(mm);
     Assert.AreEqual(EliasFanoDecoder.NO_MORE_VALUES, backValue);
 }
 private static void TstDecodeAdvanceToMultiples(long[] values, EliasFanoDecoder efd, long m)
 {
     // test advancing to multiples of m
     Debug.Assert(m > 0);
     long previousValue = -1L;
     long index = 0;
     long mm = m;
     efd.ToBeforeSequence();
     foreach (long expValue in values)
     {
         // mm > previousValue
         if (expValue >= mm)
         {
             long advanceValue = efd.AdvanceToValue(mm);
             Assert.IsFalse(EliasFanoDecoder.NO_MORE_VALUES == advanceValue, "advanceValue at end too early");
             Assert.AreEqual(expValue, advanceValue);
             Assert.AreEqual(index, efd.CurrentIndex());
             previousValue = expValue;
             do
             {
                 mm += m;
             } while (mm <= previousValue);
         }
         index++;
     }
     long advanceValue_ = efd.AdvanceToValue(mm);
     Assert.AreEqual(EliasFanoDecoder.NO_MORE_VALUES, advanceValue_);
 }