<commit_before>namespace Volante
{
    using System;
    using System.Collections;

    public class TestIndexResult : TestResult
    {
        public TimeSpan InsertTime;
        public TimeSpan IndexSearchTime;
        public TimeSpan IterationTime;
        public TimeSpan RemoveTime;
        public ICollection MemoryUsage; // values are of MemoryUsage type
    }

    public class TestIndex
    {
        public class Record : Persistent
        {
            public string strKey;
            public long intKey;
        }

        public class Root : Persistent
        {
            public Index<string, Record> strIndex;
            public Index<long, Record> intIndex;
        }

        internal static int pagePoolSize = 32 * 1024 * 1024;

        static public TestIndexResult Run(int nRecords, bool altBtree, bool inMemory, bool serializableTransaction)
        {
            int i;
            string dbName = "testidx.dbs";
            Tests.SafeDeleteFile(dbName);

            var res = new TestIndexResult()
            {
                Count = nRecords,
                TestName = String.Format("TestIndex(altBtree={0},inMemory={1},serializable={2}", altBtree, inMemory, serializableTransaction)
            };
            var tStart = DateTime.Now;

            IStorage db = StorageFactory.CreateStorage();
            if (altBtree || serializableTransaction)
                db.AlternativeBtree = true;

            if (inMemory)
                pagePoolSize = 0;

            db.Open(dbName, pagePoolSize);

            if (serializableTransaction)
                db.BeginThreadTransaction(TransactionMode.Serializable);

            Root root = (Root)db.Root;
            Tests.Assert(null == root);
            root = new Root();
            root.strIndex = db.CreateIndex<string, Record>(true);
            root.intIndex = db.CreateIndex<long, Record>(true);
            db.Root = root;
            var strIndex = root.strIndex;
            Tests.Assert(typeof(string) == strIndex.KeyType);
            var intIndex = root.intIndex;
            Tests.Assert(typeof(long) == intIndex.KeyType);

            DateTime start = DateTime.Now;
            long key = 1999;
            for (i = 0; i < nRecords; i++)
            {
                Record rec = new Record();
                key = (3141592621L * key + 2718281829L) % 1000000007L;
                rec.intKey = key;
                rec.strKey = System.Convert.ToString(key);
                intIndex[rec.intKey] = rec;
                strIndex[rec.strKey] = rec;
                if (i % 100000 == 0)
                {
                    db.Commit();
                }
            }

            if (serializableTransaction)
            {
                db.EndThreadTransaction();
                db.BeginThreadTransaction(TransactionMode.Serializable);
            }
            else
            {
                db.Commit();
            }

            res.InsertTime = DateTime.Now - start;
            start = System.DateTime.Now;

            key = 1999;
            for (i = 0; i < nRecords; i++)
            {
                key = (3141592621L * key + 2718281829L) % 1000000007L;
                Record rec1 = intIndex[key];
                Record rec2 = strIndex[Convert.ToString(key)];
                Tests.Assert(rec1 != null && rec1 == rec2);
            }
            res.IndexSearchTime = DateTime.Now - start;
            start = System.DateTime.Now;

            key = Int64.MinValue;
            i = 0;
            foreach (Record rec in intIndex)
            {
                Tests.Assert(rec.intKey >= key);
                key = rec.intKey;
                i += 1;
            }
            Tests.Assert(i == nRecords);

            String strKey = "";
            i = 0;
            foreach (Record rec in strIndex)
            {
                Tests.Assert(rec.strKey.CompareTo(strKey) >= 0);
                strKey = rec.strKey;
                i += 1;
            }
            Tests.Assert(i == nRecords);
            res.IterationTime = DateTime.Now - start;
            start = System.DateTime.Now;

            IDictionaryEnumerator de = intIndex.GetDictionaryEnumerator();
            long prev = long.MinValue;
            i = 0;
            while (de.MoveNext())
            {
                DictionaryEntry e1 = (DictionaryEntry)de.Current;
                DictionaryEntry e2 = de.Entry;
                Tests.Assert(e1.Equals(e2));
                long k = (long)e1.Key;
                long k2 = (long)de.Key;
                Tests.Assert(k == k2);
                Record v1 = (Record)e1.Value;
                Record v2 = (Record)de.Value;
                Tests.Assert(v1.Equals(v2));
                Tests.Assert(v1.intKey == k);
                Tests.Assert(k >= prev);
                prev = k;
                i++;
            }
            Tests.Assert(i == nRecords);
            Tests.AssertException<InvalidOperationException>(
                () => { var tmp = de.Current; });
            Tests.AssertException<InvalidOperationException>(
                () => { var tmp = de.Entry; });
            Tests.AssertException<InvalidOperationException>(
                () => { var tmp = de.Key; });
            Tests.AssertException<InvalidOperationException>(
                () => { var tmp = de.Value; });

            key = 1999;
            for (i = 0; i < nRecords; i++)
            {
                key = (3141592621L * key + 2718281829L) % 1000000007L;
                Record rec = intIndex.Get(key);
                Record removed = intIndex.RemoveKey(key);
                Tests.Assert(removed == rec);
                strIndex.Remove(new Key(System.Convert.ToString(key)), rec);
                rec.Deallocate();
            }
            res.RemoveTime = DateTime.Now - start;
            db.Close();

            res.ExecutionTime = DateTime.Now - tStart;<commit_msg>rename nRecords => count<commit_after>namespace Volante
{
    using System;
    using System.Collections;

    public class TestIndexResult : TestResult
    {
        public TimeSpan InsertTime;
        public TimeSpan IndexSearchTime;
        public TimeSpan IterationTime;
        public TimeSpan RemoveTime;
        public ICollection MemoryUsage; // values are of MemoryUsage type
    }

    public class TestIndex
    {
        public class Record : Persistent
        {
            public string strKey;
            public long intKey;
        }

        public class Root : Persistent
        {
            public Index<string, Record> strIndex;
            public Index<long, Record> intIndex;
        }

        internal static int pagePoolSize = 32 * 1024 * 1024;

        static public TestIndexResult Run(int count, bool altBtree, bool inMemory, bool serializableTransaction)
        {
            int i;
            string dbName = "testidx.dbs";
            Tests.SafeDeleteFile(dbName);

            var res = new TestIndexResult()
            {
                Count = count,
                TestName = String.Format("TestIndex(altBtree={0},inMemory={1},serializable={2}", altBtree, inMemory, serializableTransaction)
            };
            var tStart = DateTime.Now;

            IStorage db = StorageFactory.CreateStorage();
            if (altBtree || serializableTransaction)
                db.AlternativeBtree = true;

            if (inMemory)
                pagePoolSize = 0;

            db.Open(dbName, pagePoolSize);

            if (serializableTransaction)
                db.BeginThreadTransaction(TransactionMode.Serializable);

            Root root = (Root)db.Root;
            Tests.Assert(null == root);
            root = new Root();
            root.strIndex = db.CreateIndex<string, Record>(true);
            root.intIndex = db.CreateIndex<long, Record>(true);
            db.Root = root;
            var strIndex = root.strIndex;
            Tests.Assert(typeof(string) == strIndex.KeyType);
            var intIndex = root.intIndex;
            Tests.Assert(typeof(long) == intIndex.KeyType);

            DateTime start = DateTime.Now;
            long key = 1999;
            for (i = 0; i < count; i++)
            {
                Record rec = new Record();
                key = (3141592621L * key + 2718281829L) % 1000000007L;
                rec.intKey = key;
                rec.strKey = System.Convert.ToString(key);
                intIndex[rec.intKey] = rec;
                strIndex[rec.strKey] = rec;
                if (i % 100000 == 0)
                {
                    db.Commit();
                }
            }

            if (serializableTransaction)
            {
                db.EndThreadTransaction();
                db.BeginThreadTransaction(TransactionMode.Serializable);
            }
            else
            {
                db.Commit();
            }

            res.InsertTime = DateTime.Now - start;
            start = System.DateTime.Now;

            key = 1999;
            for (i = 0; i < count; i++)
            {
                key = (3141592621L * key + 2718281829L) % 1000000007L;
                Record rec1 = intIndex[key];
                Record rec2 = strIndex[Convert.ToString(key)];
                Tests.Assert(rec1 != null && rec1 == rec2);
            }
            res.IndexSearchTime = DateTime.Now - start;
            start = System.DateTime.Now;

            key = Int64.MinValue;
            i = 0;
            foreach (Record rec in intIndex)
            {
                Tests.Assert(rec.intKey >= key);
                key = rec.intKey;
                i += 1;
            }
            Tests.Assert(i == count);

            String strKey = "";
            i = 0;
            foreach (Record rec in strIndex)
            {
                Tests.Assert(rec.strKey.CompareTo(strKey) >= 0);
                strKey = rec.strKey;
                i += 1;
            }
            Tests.Assert(i == count);
            res.IterationTime = DateTime.Now - start;
            start = System.DateTime.Now;

            IDictionaryEnumerator de = intIndex.GetDictionaryEnumerator();
            long prev = long.MinValue;
            i = 0;
            while (de.MoveNext())
            {
                DictionaryEntry e1 = (DictionaryEntry)de.Current;
                DictionaryEntry e2 = de.Entry;
                Tests.Assert(e1.Equals(e2));
                long k = (long)e1.Key;
                long k2 = (long)de.Key;
                Tests.Assert(k == k2);
                Record v1 = (Record)e1.Value;
                Record v2 = (Record)de.Value;
                Tests.Assert(v1.Equals(v2));
                Tests.Assert(v1.intKey == k);
                Tests.Assert(k >= prev);
                prev = k;
                i++;
            }
            Tests.Assert(i == count);
            Tests.AssertException<InvalidOperationException>(
                () => { var tmp = de.Current; });
            Tests.AssertException<InvalidOperationException>(
                () => { var tmp = de.Entry; });
            Tests.AssertException<InvalidOperationException>(
                () => { var tmp = de.Key; });
            Tests.AssertException<InvalidOperationException>(
                () => { var tmp = de.Value; });

            key = 1999;
            for (i = 0; i < count; i++)
            {
                key = (3141592621L * key + 2718281829L) % 1000000007L;
                Record rec = intIndex.Get(key);
                Record removed = intIndex.RemoveKey(key);
                Tests.Assert(removed == rec);
                strIndex.Remove(new Key(System.Convert.ToString(key)), rec);
                rec.Deallocate();
            }
            res.RemoveTime = DateTime.Now - start;
            db.Close();

            res.ExecutionTime = DateTime.Now - tStart;
{'fraction_non_alphanumeric': 0.10011010417548911, 'fraction_numerical': 0.025747437960531888, 'mean_word_length': 1.3634907926341073, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 6, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2206868', 'n_tokens_mistral': 3319, 'n_tokens_neox': 2980, 'n_words': 675}