Retrieve() public static method

public static Retrieve ( byte ToArray, int atIndex ) : int
ToArray byte
atIndex int
return int
Ejemplo n.º 1
0
        void readHeader()
        {
            byte[] header = new byte[this.headersize];
            this.fromfile.Seek(this.seekStart, System.IO.SeekOrigin.Begin);
            this.fromfile.Read(header, 0, this.headersize);
            int index = 0;

            // check prefix
            foreach (byte b in HEADERPREFIX)
            {
                if (header[index] != b)
                {
                    throw new LinkedFileException("invalid header prefix");
                }
                index++;
            }
            // skip version (for now)
            index++;
            // read buffersize
            this.buffersize   = BufferFile.Retrieve(header, index);
            index            += BufferFile.INTSTORAGE;
            this.FreeListHead = BufferFile.RetrieveLong(header, index);
            this.sanityCheck();
            this.headerDirty = false;
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        public byte[] GetChunk(long HeadBufferNumber)
        {
            // get the head, interpret the length
            byte buffertype;
            long nextBufferNumber;

            byte[] buffer = this.ParseBuffer(HeadBufferNumber, out buffertype, out nextBufferNumber);
            int    length = BufferFile.Retrieve(buffer, 0);

            if (length < 0)
            {
                throw new LinkedFileException("negative length block? must be garbage: " + length);
            }
            if (buffertype != HEAD)
            {
                throw new LinkedFileException("first buffer not marked HEAD");
            }
            byte[] result = new byte[length];
            // read in the data from the first buffer
            int firstLength = this.buffersize - BufferFile.INTSTORAGE;

            if (firstLength > length)
            {
                firstLength = length;
            }
            Array.Copy(buffer, BufferFile.INTSTORAGE, result, 0, firstLength);
            int stored = firstLength;

            while (stored < length)
            {
                // get the next buffer
                long thisBufferNumber = nextBufferNumber;
                buffer = this.ParseBuffer(thisBufferNumber, out buffertype, out nextBufferNumber);
                int nextLength = this.buffersize;
                if (length - stored < nextLength)
                {
                    nextLength = length - stored;
                }
                Array.Copy(buffer, 0, result, stored, nextLength);
                stored += nextLength;
            }
            return(result);
        }