示例#1
0
        static string tempdirectory = @"c:\tmp"; // set to a directory to test storing to/from files

        #endregion Fields

        #region Methods

        public static void abort(BplusDotNet.BplusTreeLong bpt)
        {
            Debug.WriteLine(" <h3>ABORT!</H3>");
            bpt.Abort();
            allinserts = (Hashtable) lastcommittedinserts.Clone();
            checkit(bpt);
        }
示例#2
0
 public static BplusDotNet.BplusTreeLong restart(BplusDotNet.BplusTreeLong bpt)
 {
     Debug.WriteLine(" <h3>RESTART!</H3>");
     commit(bpt);
     return BplusDotNet.BplusTreeLong.SetupFromExistingStream(bpt.fromfile, bpt.seekStart);
 }
示例#3
0
 public static void inserttest(BplusDotNet.BplusTreeLong bpt, string key, long map, bool del)
 {
     if (del)
     {
         Debug.WriteLine(" <h3>DELETE bpt["+key+"] = "+map+"</h3>");
         bpt.RemoveKey(key);
         allinserts.Remove(key);
     }
     else
     {
         Debug.WriteLine("<h3>bpt["+key+"] = "+map+"</h3>");
         bpt[key] = map;
         allinserts[key] = map;
     }
     checkit(bpt);
 }
示例#4
0
 public static void inserttest(BplusDotNet.BplusTreeLong bpt, string key, long map)
 {
     inserttest(bpt, key, map, false);
 }
示例#5
0
 public static BplusDotNet.xBplusTree getXTree(BplusDotNet.xBplusTree bpt, ref System.IO.Stream treefile, ref System.IO.Stream blockfile)
 {
     int CultureId = System.Globalization.CultureInfo.InvariantCulture.LCID;
     if (tempdirectory!=null)
     {
         // allocate in filesystem
         string treename = System.IO.Path.Combine(tempdirectory, "BPDNtreeX.dat");
         string blockname = System.IO.Path.Combine(tempdirectory, "BPDNblockX.dat");
         treefile = null;
         blockfile = null;
         if (bpt == null)
         {
             // allocate new
             if (System.IO.File.Exists(treename))
             {
                 System.IO.File.Delete(treename);
             }
             if (System.IO.File.Exists(blockname))
             {
                 System.IO.File.Delete(blockname);
             }
             bpt = BplusDotNet.xBplusTree.Initialize(treename, blockname, prefixlength, CultureId, nodesize, buffersize);
         }
         else
         {
             // reopen old
             bpt.Shutdown();
             bpt = BplusDotNet.xBplusTree.ReOpen(treename, blockname);
         }
     }
     else
     {
         // allocate in memory
         if (bpt==null)
         {
             // allocate new
             treefile = new System.IO.MemoryStream();
             blockfile = new System.IO.MemoryStream();;
             bpt = BplusDotNet.xBplusTree.Initialize(treefile, blockfile, keylength, CultureId, nodesize, buffersize);
         }
         else
         {
             // reopen
             bpt = BplusDotNet.xBplusTree.ReOpen(treefile, blockfile);
         }
     }
     bpt.LimitBucketSize(bucketsizelimit);
     return bpt;
 }
示例#6
0
 public static BplusDotNet.BplusTree getTree(BplusDotNet.BplusTree bpt, ref System.IO.Stream treefile, ref System.IO.Stream blockfile)
 {
     return getTree(bpt, ref treefile, ref blockfile, false);
 }
示例#7
0
 public static void deletetest(BplusDotNet.BplusTreeLong bpt, string key, long map)
 {
     inserttest(bpt, key, map, true);
 }
示例#8
0
 public static void commit(BplusDotNet.BplusTreeLong bpt)
 {
     Debug.WriteLine(" <h3>COMMIT!</H3>");
     bpt.Commit();
     lastcommittedinserts = (Hashtable)allinserts.Clone();
     checkit(bpt);
 }
示例#9
0
 public static void checkit(BplusDotNet.BplusTreeLong bpt)
 {
     Debug.WriteLine(bpt.toHtml());
     bpt.SanityCheck(true);
     ArrayList allkeys = new ArrayList();
     foreach (DictionaryEntry d in allinserts)
     {
         allkeys.Add(d.Key);
     }
     allkeys.Sort();
     allkeys.Reverse();
     foreach (object thing in allkeys)
     {
         string thekey = (string) thing;
         long thevalue = (long) allinserts[thing];
         if (thevalue!=bpt[thekey])
         {
             throw new ApplicationException("no match on retrieval "+thekey+" --> "+bpt[thekey]+" not "+thevalue);
         }
     }
     allkeys.Reverse();
     string currentkey = bpt.FirstKey();
     foreach (object thing in allkeys)
     {
         string testkey = (string) thing;
         if (currentkey==null)
         {
             throw new ApplicationException("end of keys found when expecting "+testkey);
         }
         if (!testkey.Equals(currentkey))
         {
             throw new ApplicationException("when walking found "+currentkey+" when expecting "+testkey);
         }
         currentkey = bpt.NextKey(testkey);
     }
 }