Esempio n. 1
0
        /// <summary>
        /// Initialize data structures
        /// </summary>
        private void Initialize()
        {
            KeyHeader = new KeyHeaderDef();

            // Get root allocation
            KeyHeaderAlloc = sp.GetRootAllocation(DEFS.POOL_KEY);

            // If ROOT doesn't exist yet - initial allocation
            if (KeyHeaderAlloc == null)
            {
                // Allocate header space
                KeyHeaderAlloc = sp.AllocateSpace(KeyHeaderDef.KEYROOT_SIZE, DEFS.POOL_KEY, generateID: false);
                KeyHeaderAlloc.Write(KeyHeaderDef.A_DescriptorLast, -1);

                // Allocate descriptor space
                KeyDescriptorAlloc = sp.AllocateSpace(KeyDescriptorDef.DESCRIPTOR_CHUNK_SIZE, DEFS.POOL_KEY, generateID: false);

                //Set initial values to memory object
                KeyHeader.DescriptorAddress = KeyDescriptorAlloc.DescriptorAddress;
                KeyHeader.DescriptorLength  = KeyDescriptorDef.DESCRIPTOR_CHUNK_LENGTH;
                KeyHeader.DescriptorLast    = -1;
                KeyHeader.DescriptorUsed    = 0;
                KeyHeader.LastKey           = 0;

                // Save initial values
                KeyHeaderAlloc.Write(KeyHeaderDef.A_DescriptorAddress, KeyHeader.DescriptorAddress);
                KeyHeaderAlloc.Write(KeyHeaderDef.A_DescriptorLength, KeyHeader.DescriptorLength);
                KeyHeaderAlloc.Write(KeyHeaderDef.A_DescriptorLast, KeyHeader.DescriptorLast);
                KeyHeaderAlloc.Write(KeyHeaderDef.A_DescriptorUsed, KeyHeader.DescriptorUsed);
                KeyHeaderAlloc.Write(KeyHeaderDef.A_LastKey, KeyHeader.LastKey);

                // Create descriptor
                KeyDescriptor = new KeyDescriptorDef[KeyHeader.DescriptorLength];
            }
            else
            {
                // Read header
                KeyHeader.DescriptorAddress = KeyHeaderAlloc.ReadLong(KeyHeaderDef.A_DescriptorAddress);
                KeyHeader.DescriptorLength  = KeyHeaderAlloc.ReadInt(KeyHeaderDef.A_DescriptorLength);
                KeyHeader.DescriptorLast    = KeyHeaderAlloc.ReadInt(KeyHeaderDef.A_DescriptorLast);
                KeyHeader.DescriptorUsed    = KeyHeaderAlloc.ReadInt(KeyHeaderDef.A_DescriptorUsed);
                KeyHeader.LastKey           = KeyHeaderAlloc.ReadLong(KeyHeaderDef.A_LastKey);


                // Read descriptor
                KeyDescriptor      = new KeyDescriptorDef[KeyHeader.DescriptorLength];
                KeyDescriptorAlloc = sp.GetAllocationByDescriptor(KeyHeader.DescriptorAddress);

                for (int i = 0; i < KeyHeader.DescriptorLength; i++)
                {
                    KeyDescriptor[i].Address  = KeyDescriptorAlloc.ReadLong((KeyDescriptorDef.DESCRIPTOR_ITEM_LENGTH * i) + KeyDescriptorDef.A_Address);
                    KeyDescriptor[i].FirstKey = KeyDescriptorAlloc.ReadLong((KeyDescriptorDef.DESCRIPTOR_ITEM_LENGTH * i) + KeyDescriptorDef.A_FirstKey);
                    KeyDescriptor[i].Used     = KeyDescriptorAlloc.ReadInt((KeyDescriptorDef.DESCRIPTOR_ITEM_LENGTH * i) + KeyDescriptorDef.A_Used);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Constructor - create index descriptor
        /// </summary>
        /// <param name="s"></param>
        /// <param name="name"></param>
        /// <param name="unique"></param>
        internal VSIndex(VSpace space, string name, bool unique)
        {
            this.sp = space;

            this.ALLOCATION = sp.AllocateSpace(VSIndex.INDEX_DESCRIPTOR_LEN, DEFS.POOL_INDEX, true);

            this.ALLOCATION.Write(0, DEFS.INDEX_SIGNATURE);

            this.Name = name.Trim().ToLower();

            this.ROOT = 0;

            this.POOL = 0;

            this.UNIQUE = (short)(unique ? 1 : 0);

            this.space_name = DEFS.ParseIndexSpace(this.Name);
            this.index_name = DEFS.ParseIndexName(this.Name);
        }
Esempio n. 3
0
        /// <summary>
        /// Create new node
        /// </summary>
        /// <returns>id</returns>
        public long Create(byte[] key, long value, long parent, short pool)
        {
            long base_size = VARIABLE_POS + key.Length + 8;

            long alloc_size = (ix.UniqueIndex) ? base_size : DEFS.MIN_SPACE_ALLOCATION_CHUNK * 2;

            this.ALLOCATION = sp.AllocateSpace(alloc_size, pool);

            this.SG = DEFS.AVL_SIGNATURE;

            this.REF_COUNT = 1;

            this.KEYLEN = key.Length;

            this.ALLOCATION.Write(KEY_POS, key, key.Length);

            this.PARENT = parent;

            this.INDEX = ix.Id;            // Index Id

            this.REF = value;              // 1st ref value

            return(ID);
        }