Example #1
0
    static public void  Main(System.String[] args)
    {
        int     i;
        Storage db = StorageFactory.Instance.CreateStorage();

        db.Open("testbck1.dbs", pagePoolSize);
        Root root = (Root)db.Root;

        if (root == null)
        {
            root               = new Root();
            root.strIndex      = db.CreateIndex(typeof(System.String), true);
            root.intIndex      = db.CreateFieldIndex(typeof(Record), "intKey", true);
            root.compoundIndex = db.CreateFieldIndex(typeof(Record), new String[] { "strKey", "intKey" }, true);
            db.Root            = root;
        }
        FieldIndex intIndex      = root.intIndex;
        FieldIndex compoundIndex = root.compoundIndex;
        Index      strIndex      = root.strIndex;
        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);
            rec.realKey = (double)key;
            intIndex.Put(rec);
            strIndex.Put(new Key(rec.strKey), rec);
            compoundIndex.Put(rec);
        }
        db.Commit();
        System.Console.WriteLine("Elapsed time for inserting " + nRecords + " records: " + (DateTime.Now - start));

        start = DateTime.Now;
        System.IO.FileStream stream = new System.IO.FileStream("testbck2.dbs", FileMode.Create, FileAccess.Write);
        db.Backup(stream);
        stream.Close();
        System.Console.WriteLine("Elapsed time for backup completion: " + (DateTime.Now - start));

        db.Close();
        db.Open("testbck2.dbs", pagePoolSize);

        root          = (Root)db.Root;
        intIndex      = root.intIndex;
        strIndex      = root.strIndex;
        compoundIndex = root.compoundIndex;

        start = DateTime.Now;
        key   = 1999;
        for (i = 0; i < nRecords; i++)
        {
            key = (3141592621L * key + 2718281829L) % 1000000007L;
            String strKey = System.Convert.ToString(key);
            Record rec1   = (Record)intIndex.Get(new Key(key));
            Record rec2   = (Record)strIndex.Get(new Key(strKey));
            Record rec3   = (Record)compoundIndex.Get(new Key(strKey, key));
            Debug.Assert(rec1 != null);
            Debug.Assert(rec1 == rec2);
            Debug.Assert(rec1 == rec3);
            Debug.Assert(rec1.intKey == key);
            Debug.Assert(rec1.realKey == (double)key);
            Debug.Assert(strKey.Equals(rec1.strKey));
        }
        System.Console.WriteLine("Elapsed time for performing " + nRecords * 2 + " index searches: " + (DateTime.Now - start));
        db.Close();
    }
    static public void Main(string[] args)
    {
        int     i;
        Storage db = StorageFactory.Instance.CreateStorage();

        for (i = 0; i < args.Length; i++)
        {
            if ("altbtree" == args[i])
            {
                db.SetProperty("perst.alternative.btree", true);
            }
        }
        db.Open("testcidx.dbs", pagePoolSize);

#if USE_GENERICS
        MultiFieldIndex <Record> root = (MultiFieldIndex <Record>)db.Root;
        if (root == null)
        {
            root = db.CreateFieldIndex <Record>(new string[] { "intKey", "strKey" }, true);
#else
        FieldIndex root = (FieldIndex)db.Root;
        if (root == null)
        {
            root = db.CreateFieldIndex(typeof(Record), new string[] { "intKey", "strKey" }, true);
#endif
            db.Root = root;
        }
        DateTime start = DateTime.Now;
        long key       = 1999;
        for (i = 0; i < nRecords; i++)
        {
            Record rec = new Record();
            key        = (3141592621L * key + 2718281829L) % 1000000007L;
            rec.intKey = (int)((ulong)key >> 32);
            rec.strKey = Convert.ToString((int)key);
            root.Put(rec);
        }
        db.Commit();
        Console.WriteLine("Elapsed time for inserting " + nRecords + " records: " + (DateTime.Now - start));

        start = DateTime.Now;
        key   = 1999;
        int minKey = Int32.MaxValue;
        int maxKey = Int32.MinValue;
        for (i = 0; i < nRecords; i++)
        {
            key = (3141592621L * key + 2718281829L) % 1000000007L;
            int    intKey = (int)((ulong)key >> 32);
            String strKey = Convert.ToString((int)key);
#if USE_GENERICS
            Record rec = root.Get(new Key(new Object[] { intKey, strKey }));
#else
            Record rec = (Record)root.Get(new Key(new Object[] { intKey, strKey }));
#endif
            Debug.Assert(rec != null && rec.intKey == intKey && rec.strKey.Equals(strKey));
            if (intKey < minKey)
            {
                minKey = intKey;
            }
            if (intKey > maxKey)
            {
                maxKey = intKey;
            }
        }
        Console.WriteLine("Elapsed time for performing " + nRecords + " index searches: " + (DateTime.Now - start));

        start = DateTime.Now;
        int n          = 0;
        string prevStr = "";
        int prevInt    = minKey;
        foreach (Record rec in root.Range(new Key(minKey, ""),
                                          new Key(maxKey + 1, "???"),
                                          IterationOrder.AscentOrder))
        {
            Debug.Assert(rec.intKey > prevInt || rec.intKey == prevInt && rec.strKey.CompareTo(prevStr) > 0);
            prevStr = rec.strKey;
            prevInt = rec.intKey;
            n      += 1;
        }
        Debug.Assert(n == nRecords);

        n       = 0;
        prevInt = maxKey + 1;
        foreach (Record rec in root.Range(new Key(minKey, "", false),
                                          new Key(maxKey + 1, "???", false),
                                          IterationOrder.DescentOrder))
        {
            Debug.Assert(rec.intKey < prevInt || rec.intKey == prevInt && rec.strKey.CompareTo(prevStr) < 0);
            prevStr = rec.strKey;
            prevInt = rec.intKey;
            n      += 1;
        }
        Debug.Assert(n == nRecords);
        Console.WriteLine("Elapsed time for iterating through " + (nRecords * 2) + " records: " + (DateTime.Now - start));
        start = DateTime.Now;
        key   = 1999;
        for (i = 0; i < nRecords; i++)
        {
            key = (3141592621L * key + 2718281829L) % 1000000007L;
            int    intKey = (int)((ulong)key >> 32);
            String strKey = Convert.ToString((int)key);
#if USE_GENERICS
            Record rec = root.Get(new Key(new Object[] { intKey, strKey }));
#else
            Record rec = (Record)root.Get(new Key(new Object[] { intKey, strKey }));
#endif
            Debug.Assert(rec != null && rec.intKey == intKey && rec.strKey.Equals(strKey));
            Debug.Assert(root.Contains(rec));
            root.Remove(rec);
            rec.Deallocate();
        }
        Debug.Assert(!root.GetEnumerator().MoveNext());
        Debug.Assert(!root.Reverse().GetEnumerator().MoveNext());
        Console.WriteLine("Elapsed time for deleting " + nRecords + " records: " + (DateTime.Now - start));
        db.Close();
    }
}
Example #3
0
    static public void  Main(string[] args)
    {
        int     i;
        Storage db = StorageFactory.Instance.CreateStorage();

        for (i = 0; i < args.Length; i++)
        {
            if ("altbtree" == args[i])
            {
                db.SetProperty("perst.alternative.btree", true);
            }
        }
        db.Open("test1.dbs", pagePoolSize);
        Root root = (Root)db.Root;

        if (root == null)
        {
            root = new Root();
#if USE_GENERICS
            root.strIndex      = db.CreateIndex <string, Record>(true);
            root.intIndex      = db.CreateFieldIndex <long, Record>("intKey", true);
            root.compoundIndex = db.CreateFieldIndex <Record>(new string[] { "strKey", "intKey" }, true);
#else
            root.strIndex      = db.CreateIndex(typeof(System.String), true);
            root.intIndex      = db.CreateFieldIndex(typeof(Record), "intKey", true);
            root.compoundIndex = db.CreateFieldIndex(typeof(Record), new String[] { "strKey", "intKey" }, true);
#endif
            root.point.x = 1;
            root.point.y = 2;
            db.Root      = root;
        }
#if USE_GENERICS
        FieldIndex <long, Record> intIndex      = root.intIndex;
        MultiFieldIndex <Record>  compoundIndex = root.compoundIndex;
        Index <string, Record>    strIndex      = root.strIndex;
#else
        FieldIndex intIndex      = root.intIndex;
        FieldIndex compoundIndex = root.compoundIndex;
        Index      strIndex      = root.strIndex;
#endif

        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);
            rec.realKey = (double)key;
            intIndex.Put(rec);
            strIndex.Put(new Key(rec.strKey), rec);
            compoundIndex.Put(rec);
        }
        db.Commit();
        System.Console.WriteLine("Elapsed time for inserting " + nRecords + " records: " + (DateTime.Now - start));

        start = DateTime.Now;
        System.IO.StreamWriter writer = new System.IO.StreamWriter("test.xml");
        db.ExportXML(writer);
        writer.Close();
        System.Console.WriteLine("Elapsed time for XML export: " + (DateTime.Now - start));

        db.Close();
        db.Open("test2.dbs", pagePoolSize);

        start = DateTime.Now;
        System.IO.StreamReader reader = new System.IO.StreamReader("test.xml");
        db.ImportXML(reader);
        reader.Close();
        System.Console.WriteLine("Elapsed time for XML import: " + (DateTime.Now - start));

        root          = (Root)db.Root;
        intIndex      = root.intIndex;
        strIndex      = root.strIndex;
        compoundIndex = root.compoundIndex;
        Debug.Assert(root.point.x == 1 && root.point.y == 2);

        start = DateTime.Now;
        key   = 1999;
        for (i = 0; i < nRecords; i++)
        {
            key = (3141592621L * key + 2718281829L) % 1000000007L;
            String strKey = System.Convert.ToString(key);
#if USE_GENERICS
            Record rec1 = intIndex[key];
            Record rec2 = strIndex[strKey];
            Record rec3 = compoundIndex.Get(new Key(strKey, key));
#else
            Record rec1 = (Record)intIndex.Get(new Key(key));
            Record rec2 = (Record)strIndex.Get(new Key(strKey));
            Record rec3 = (Record)compoundIndex.Get(new Key(strKey, key));
#endif
            Debug.Assert(rec1 != null);
            Debug.Assert(rec1 == rec2);
            Debug.Assert(rec1 == rec3);
            Debug.Assert(rec1.intKey == key);
            Debug.Assert(rec1.realKey == (double)key);
            Debug.Assert(strKey.Equals(rec1.strKey));
        }
        System.Console.WriteLine("Elapsed time for performing " + nRecords * 2 + " index searches: " + (DateTime.Now - start));
        db.Close();
    }