Exemple #1
0
        public void TestGetSetWithSpecifiedStream()
        {
            MemoryEfficientBigULongArray arr = new MemoryEfficientBigULongArray(10, 1000, new MemoryStream());

            arr[3] = 400;
            Assert.AreEqual(400, arr[3]);
        }
Exemple #2
0
        public void TestGetSetBig()
        {
            MemoryEfficientBigULongArray arr = new MemoryEfficientBigULongArray(10, ulong.MaxValue);

            arr[3] = ulong.MaxValue;
            Assert.AreEqual(ulong.MaxValue, arr[3]);
        }
Exemple #3
0
        public void TestGetSetByteAligned()
        {
            MemoryEfficientBigULongArray arr = new MemoryEfficientBigULongArray(10, byte.MaxValue);

            arr[7] = 12;
            Assert.AreEqual(12, arr[7]);
        }
Exemple #4
0
        public void TestGetSet()
        {
            MemoryEfficientBigULongArray arr = new MemoryEfficientBigULongArray(10, 1000);

            arr[3] = 400;
            Assert.AreEqual(400, arr[3]);
        }
Exemple #5
0
        public void TestConstructorBiggerThan2Gb()
        {
            //Test that an array larger than 2GiB in size can be constructed
            const long LENGTH = 3L * 1024L * 1024L * 1024L; // 3GiB at 1byte per el

            MemoryEfficientBigULongArray arr = new MemoryEfficientBigULongArray(LENGTH, byte.MaxValue);
        }
        public static MemoryEfficientBigULongArray GenerateSearchResults(FourBitDigitBigArray fourBitDigitArray,
                                                                         IBigArray <ulong> suffixArray, int stringLength)
        {
            int    lessThan          = NumPrecomputedResults(stringLength);
            string toStringFormatter = "D" + stringLength;

            MemoryEfficientBigULongArray precomputedResults = new MemoryEfficientBigULongArray(
                lessThan * 2, (ulong)fourBitDigitArray.Length);

            long suffixArrayIdx = 0;

            for (int i = 0; i < lessThan; i++)
            {
                if (suffixArrayIdx < suffixArray.Length)
                {
                    //Convert what we're searching for to the digits to be searched for
                    string sSearch    = i.ToString(toStringFormatter);
                    byte[] bArrSearch = SearchString.StrToByteArr(sSearch);

                    long suffixArrayVal = (long)suffixArray[suffixArrayIdx];

                    //Find when this string starts
                    while (suffixArrayVal < fourBitDigitArray.Length &&
                           suffixArrayIdx < suffixArray.Length &&
                           SearchString.doesStartWithSuffix(fourBitDigitArray, bArrSearch, suffixArrayVal) == -1)
                    {
                        suffixArrayIdx++;
                        if (suffixArrayIdx < suffixArray.Length)
                        {
                            suffixArrayVal = (long)suffixArray[suffixArrayIdx];
                        }
                    }

                    precomputedResults[i * 2] = (ulong)suffixArrayIdx;

                    //Find when this string ends
                    while (suffixArrayVal < fourBitDigitArray.Length &&
                           suffixArrayIdx < suffixArray.Length &&
                           SearchString.doesStartWithSuffix(fourBitDigitArray, bArrSearch, suffixArrayVal) == 0)
                    {
                        suffixArrayIdx++;
                        if (suffixArrayIdx < suffixArray.Length)
                        {
                            suffixArrayVal = (long)suffixArray[suffixArrayIdx];
                        }
                    }

                    //Noe that here the exclusive maximum is stored, so if min == max the string wasn't found
                    precomputedResults[(i * 2) + 1] = (ulong)suffixArrayIdx;
                }
                else
                {
                    precomputedResults[i * 2]       = (ulong)suffixArray.Length;
                    precomputedResults[(i * 2) + 1] = (ulong)suffixArray.Length;
                }
            }

            return(precomputedResults);
        }
Exemple #7
0
        public void TestSetIndexTooBig()
        {
            MemoryEfficientBigULongArray arr = new MemoryEfficientBigULongArray(10, 1000);

            Assert.Throws <IndexOutOfRangeException>(() =>
            {
                arr[arr.Length] = 1;
            });
        }
Exemple #8
0
        public void TestSetValueTooBig()
        {
            MemoryEfficientBigULongArray arr = new MemoryEfficientBigULongArray(10, 1000);

            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                arr[1] = arr.MaxValue + 1;
            });
        }
Exemple #9
0
        public void TestGetIndexTooSmall()
        {
            MemoryEfficientBigULongArray arr = new MemoryEfficientBigULongArray(10, 1000);

            Assert.Throws <IndexOutOfRangeException>(() =>
            {
                ulong val = arr[-1];
            });
        }
Exemple #10
0
        public void TestGetSetBigArray()
        {
            long len = 1000000000;
            MemoryEfficientBigULongArray arr = new MemoryEfficientBigULongArray(len, (ulong)len - 1);

            long  setPos = 50;
            ulong setVal = 4;

            arr[setPos] = setVal;

            Assert.AreEqual(setVal, arr[setPos]);
        }
Exemple #11
0
        private static IBigArray <ulong> buildSuffixArray(string str)
        {
            //Initialise the array that will hold the suffix array
            MemoryEfficientBigULongArray suffixArray = new MemoryEfficientBigULongArray(str.Length);

            //Calculate the suffix array
            long status = SAIS.sufsort(str, suffixArray, str.Length);

            if (status != 0)
            {
                string error = String.Format("Error occurred whilst generating the suffix array: {0}", status);
                Console.WriteLine(error);
                throw new Exception(error);
            }

            return(suffixArray);
        }
Exemple #12
0
        public void TestGetSetMultipleValuesReverseOrder()
        {
            ulong[] ulongArr = { 23, 47, 1000, 247, 803, 2, 0, 403 };
            MemoryEfficientBigULongArray arr = new MemoryEfficientBigULongArray(ulongArr.Length, 1000);

            //Populate the arr
            for (int i = ulongArr.Length - 1; i >= 0; i--)
            {
                arr[i] = ulongArr[i];
            }

            //Check the values
            for (int i = ulongArr.Length - 1; i >= 0; i--)
            {
                Assert.AreEqual(ulongArr[i], arr[i]);
            }
        }
Exemple #13
0
        public void TestCalculateBitsPerValue()
        {
            Dictionary <ulong, byte> answers = new Dictionary <ulong, byte>()
            {
                { 1, 1 },
                { 2, 2 },
                { 3, 2 },
                { 7, 3 },
                { byte.MaxValue, 8 },
                { uint.MaxValue, 32 },
                { ulong.MaxValue, 64 }
            };

            foreach (KeyValuePair <ulong, byte> kvp in answers)
            {
                ulong num     = kvp.Key;
                byte  numBits = kvp.Value;

                byte actual = MemoryEfficientBigULongArray.calculateBitsPerValue(num);
                Assert.AreEqual(numBits, actual);
            }
        }
Exemple #14
0
 public void TestConstructorWithMaxValue()
 {
     MemoryEfficientBigULongArray arr = new MemoryEfficientBigULongArray(10, 1000);
 }
Exemple #15
0
 public void TestConstructorBig()
 {
     //number 7 requires minimum 3 bits, so thats (5bil * 3) / 8 bytes ~= 1.75GiB of RAM used
     MemoryEfficientBigULongArray arr = new MemoryEfficientBigULongArray(5000000000, 7);
 }
Exemple #16
0
 public void TestConstructor()
 {
     MemoryEfficientBigULongArray arr = new MemoryEfficientBigULongArray(10);
 }
Exemple #17
0
 public void TestConstructorWithStreamNoMaxValue()
 {
     MemoryEfficientBigULongArray arr = new MemoryEfficientBigULongArray(10, new MemoryStream());
 }
Exemple #18
0
        public void TestGetUnset()
        {
            MemoryEfficientBigULongArray arr = new MemoryEfficientBigULongArray(10, 1000);

            Assert.AreEqual(0, arr[5]);
        }
Exemple #19
0
        public void TestMaxValue()
        {
            MemoryEfficientBigULongArray arr = new MemoryEfficientBigULongArray(10, 1000);

            Assert.AreEqual(1000, arr.MaxValue);
        }
Exemple #20
0
        public void TestLength()
        {
            MemoryEfficientBigULongArray arr = new MemoryEfficientBigULongArray(10);

            Assert.AreEqual(10, arr.Length);
        }