Tree index mapping strings to strings.
Наследование: IStringTree
Пример #1
0
        public void Load(byte[] serialization)
        {
            int index     = 0;
            int byteCount = serialization.Length;

            if (this.values.Count != 0 || this.keys.Count != 0)
            {
                throw new BplusTreeException("load into nonempty xBucket not permitted");
            }
            while (index < byteCount)
            {
                // get key prefix and key
                int keylength = BufferFile.Retrieve(serialization, index);
                index += BufferFile.INTSTORAGE;
                byte[] keybytes = new byte[keylength];
                Array.Copy(serialization, index, keybytes, 0, keylength);
                string keystring = BplusTree.BytesToString(keybytes);
                index += keylength;
                // get value prefix and value
                int valuelength = BufferFile.Retrieve(serialization, index);
                index += BufferFile.INTSTORAGE;
                byte[] valuebytes = new byte[valuelength];
                Array.Copy(serialization, index, valuebytes, 0, valuelength);
                // record new key and value
                this.keys.Add(keystring);
                this.values.Add(valuebytes);
                index += valuelength;
            }
            if (index != byteCount)
            {
                throw new BplusTreeException("bad byte count in serialization " + byteCount);
            }
        }
Пример #2
0
        public override string PrefixForByteCount(string s, int maxbytecount)
        {
            byte[] inputbytes = BplusTree.StringToBytes(s);
            MD5    d          = MD5.Create();

            byte[] digest      = d.ComputeHash(inputbytes);
            var    resultbytes = new byte[maxbytecount];

            // copy digest translating to printable ascii
            for (int i = 0; i < maxbytecount; i++)
            {
                int r = digest[i % digest.Length];
                if (r > 127)
                {
                    r = 256 - r;
                }
                if (r < 0)
                {
                    r = -r;
                }
                //Console.WriteLine(" before "+i+" "+r);
                r = r % 79 + 40;               // printable ascii
                //Console.WriteLine(" "+i+" "+r);
                resultbytes[i] = (byte)r;
            }
            string result = BplusTree.BytesToString(resultbytes);

            return(result);
        }
Пример #3
0
        public byte[] dump()
        {
            ArrayList allbytes  = new ArrayList();
            int       byteCount = 0;

            for (int index = 0; index < this.keys.Count; index++)
            {
                string thisKey   = (string)this.keys[index];
                byte[] thisValue = (byte[])this.values[index];
                byte[] keyprefix = new byte[BufferFile.INTSTORAGE];
                byte[] keybytes  = BplusTree.StringToBytes(thisKey);
                BufferFile.Store(keybytes.Length, keyprefix, 0);
                allbytes.Add(keyprefix);
                allbytes.Add(keybytes);
                byte[] valueprefix = new byte[BufferFile.INTSTORAGE];
                BufferFile.Store(thisValue.Length, valueprefix, 0);
                allbytes.Add(valueprefix);
                allbytes.Add(thisValue);
            }
            foreach (object thing in allbytes)
            {
                byte[] thebytes = (byte[])thing;
                byteCount += thebytes.Length;
            }
            int outindex = 0;

            byte[] result = new byte[byteCount];
            foreach (object thing in allbytes)
            {
                byte[] thebytes  = (byte[])thing;
                int    thelength = thebytes.Length;
                Array.Copy(thebytes, 0, result, outindex, thelength);
                outindex += thelength;
            }
            if (outindex != byteCount)
            {
                throw new BplusTreeException("error counting bytes in dump " + outindex + "!=" + byteCount);
            }
            return(result);
        }
Пример #4
0
 public WebServer(BplusTree serviceTree)
 {
     _tree = serviceTree;
 }
Пример #5
0
 private static void InitKeyValueStore()
 {
     try
     {
         if (File.Exists("services.dat") && File.Exists("services.tree"))
         {
             _tree = BplusTree.ReOpen("services.tree", "services.dat");
         }
         else
         {
             _tree = BplusTree.Initialize("services.tree", "services.dat", 36);
         }
     }
     catch (Exception)
     {
         Log.Error("Error initialising service tree");
         //_tree = BplusTree.Initialize("services.tree", "services.dat", 36);
     }
 }