Пример #1
0
        public bool Insert(string className, string[] fields, uint topNodeSId, ref uint assignedCId)
        {
            if (m_name_cache.ContainsKey(className))
            {
                return(false);
            }

            //no duplicates allowed.
            if (Search(className) != null)
            {
                return(false);
            }

            assignedCId = m_next_cid++;
            KCatalog key  = new KCatalog(className);
            DCatalog data = new DCatalog(assignedCId, fields, topNodeSId);

            key.ClassInfo = data;

            bool succeed = m_tree.Insert(key);

            if (succeed)
            {
                _put_in_cache(assignedCId, className, fields, topNodeSId);
            }
            return(succeed);
        }
Пример #2
0
        public bool InsertObject(object keyValue, string[] serializedOtherFields)
        {
            KClass key = new KClass(keyValue, OOD.Types.GetInternalType(keyValue.GetType()));

            key.SerializedOtherData = new DClass(serializedOtherFields);

            return(m_tree.Insert(key));
        }
Пример #3
0
        /*  Needed operations:
         *	  1. Given an offset and length, set that range to be free space.
         *    2. Given an length, return the pair (offset, length) can be used.
         *		 that range will be removed from free space tree before this
         *       operation	returns.
         */

        /// <summary>
        /// Set the segment in the databse file to be free.
        /// </summary>
        /// <param name="offset"></param>
        /// <param name="length"></param>
        public void SetSegmentFree(uint offset, int length)
        {
            if (offset + length != m_dbFile.Length)
            {
                uint    nextSeg = (uint)(offset + length);
                KOffset target  = new KOffset(nextSeg);
                KOffset finding = (KOffset)m_tree.Search(target);
                if (finding == null)
                {
                    //combine to next segment is not possible, just go ahead to insert this one
                    target.Offset = offset;
                    target.Length = new DLength(length);
                    if (m_tree.Insert(target) == false)
                    {
                        throw new OOD.Exception.ProgramLogicError(
                                  this,
                                  "Insert into free space b-tree failed.");
                    }
                }
                else
                {
                    //combine these two free segment into a big one
                    length       += finding.Length.Num;
                    target.Length = new DLength(length);
                    target.Offset = offset;
                    if (m_tree.Delete(finding) == false || m_tree.Insert(target) == false)
                    {
                        throw new OOD.Exception.ProgramLogicError(
                                  this,
                                  "Delete free space failed.");
                    }
                }
            }
            else
            {
                //this is the last segment in the database file, just remove it from the file
                m_dbFile.SetLength(offset);
            }
        }
Пример #4
0
        public bool InsertAddr(uint segId, uint offset, int length)
        {
            KSegId newKey = new KSegId(segId, new DSegAddr(offset, length));

            return(m_tree.Insert(newKey));
        }