コード例 #1
0
        public void AddOutOfRangeTest()
        {
            const int count = 100;

            IPersistentList <int> list = PersistentList <int> .Empty;

            foreach (int i in Enumerable.Range(1, count))
            {
                list = list.Add(i);
            }

            Assert.Throws <IndexOutOfRangeException>(() => list.Add(-1, 1));
            Assert.Throws <IndexOutOfRangeException>(() => list.Add(count + 1, 1));
        }
コード例 #2
0
        public void AddFirstTest()
        {
            const int count = 100;

            IPersistentList <int> list = PersistentList <int> .Empty;

            foreach (int i in Enumerable.Range(1, count))
            {
                list = list.Add(0, count - i + 1);
                Assert.Equal(i, list.Count);

                int index = 0;
                foreach (int j in list)
                {
                    Assert.Equal(count - i + index + 1, j);
                    index++;
                }
            }
        }
コード例 #3
0
        public void Insert(int i, object o)
#endif
        {
            if (small != null)
            {
                if (small.Count == BtreeThreshold)
                {
#if USE_GENERICS
                    large = Storage.CreateList <T>();
                    foreach (T obj in small)
                    {
                        large.Add(obj);
                    }
#else
                    large = Storage.CreateList();
                    foreach (object obj in small)
                    {
                        large.Add(obj);
                    }
#endif
                    large.Insert(i, o);
                    Modify();
                    small = null;
                }
                else
                {
#if USE_GENERICS
                    small.Insert(i, o);
#else
                    small.Insert(i, o);
#endif
                }
            }
            else
            {
                large.Insert(i, o);
            }
        }
コード例 #4
0
        public void SetItemTest()
        {
            const int count = 200;

            IPersistentList <int> list = PersistentList <int> .Empty;

            for (int i = 0; i < count; i++)
            {
                list = list.Add(i);
            }
            IPersistentList <int> list2 = list;

            for (int i = 0; i < count; i++)
            {
                list = list.Set(i, j => j + 1, out int oldValue);
                Assert.Equal(i, oldValue);
                list2 = list2.Set(i, i + 1, out oldValue);
                Assert.Equal(i, oldValue);
            }

            CheckListEquality(Enumerable.Range(1, count).ToArray(), list);
            CheckListEquality(Enumerable.Range(1, count).ToArray(), list2);
        }
コード例 #5
0
        private void AddRemoveAtTestImpl(InsertRemoveScenario scenario)
        {
            IPersistentList <int> list     = PersistentList <int> .Empty;
            List <int>            expected = new List <int>();

            int i = 0;

            foreach (int position in scenario.InsertionOrder)
            {
                list = list.Add(position, i);
                expected.Insert(position, i);
                CheckListEquality(expected, list);

                i++;
            }

            foreach (int position in scenario.RemovalOrder)
            {
                list = list.RemoveAt(position, out int removedValue);
                Assert.Equal(expected[position], removedValue);
                expected.RemoveAt(position);
                CheckListEquality(expected, list);
            }
        }
コード例 #6
0
 public void EmptyListTest(IPersistentList <int> empty)
 {
     CheckEmptyListBehaviour(empty);
     Assert.NotSame(empty, empty.Add(1));
 }
コード例 #7
0
    static public void  Main(string[] args)
    {
        int     i;
        Storage db = StorageFactory.Instance.CreateStorage();

        db.Open("testlist2.dbs", pagePoolSize);

#if USE_GENERICS
        IPersistentList <Record> root = (IPersistentList <Record>)db.Root;
        if (root == null)
        {
            root    = db.CreateList <Record>();
            db.Root = root;
        }
#else
        IPersistentList root = (IPersistentList)db.Root;
        if (root == null)
        {
            root    = db.CreateList();
            db.Root = root;
        }
#endif

        DateTime start = DateTime.Now;
        for (i = 0; i < nRecords / 2; i++)
        {
            Record rec = new Record();
            rec.i = i * 2;
            root.Add(rec);
        }
        for (i = 1; i < nRecords; i += 2)
        {
            Record rec = new Record();
            rec.i = i;
            root.Insert(i, rec);
        }

        db.Commit();
        Console.WriteLine("Elapsed time for inserting " + nRecords + " records: " + (DateTime.Now - start));

        start = DateTime.Now;
        for (i = 0; i < nRecords; i++)
        {
#if USE_GENERICS
            Record rec = root[i];
#else
            Record rec = (Record)root[i];
#endif
            Debug.Assert(rec.i == i);
        }
        Console.WriteLine("Elapsed time for performing " + nRecords + " gets: " + (DateTime.Now - start));

        start = DateTime.Now;
        i     = 0;
        foreach (Record rec in root)
        {
            Debug.Assert(rec.i == i);
            i += 1;
        }
        Debug.Assert(i == nRecords);
        Console.WriteLine("Elapsed time for iteration through " + nRecords + " records: " + (DateTime.Now - start));

        start = DateTime.Now;
        for (i = 0; i < nRecords; i++)
        {
#if USE_GENERICS
            Record rec = root[0];
#else
            Record rec = (Record)root[0];
#endif
            Debug.Assert(rec.i == i);
            root.RemoveAt(0);
            rec.Deallocate();
        }
        Debug.Assert(!root.GetEnumerator().MoveNext());
        Console.WriteLine("Elapsed time for deleting " + nRecords + " records: " + (DateTime.Now - start));
        db.Close();
    }
コード例 #8
0
 public void AddListing(Listing listing)
 {
     _listings.Add(listing);
 }