コード例 #1
0
 public ClassEntry Search(string className)
 {
     if (m_name_cache.ContainsKey(className))
     {
         ClassEntry result = (ClassEntry)m_name_cache[className];
         result.BreakLinks();
         result.BuildLinks(m_LRU, m_LRU.Next);
         return(result);
     }
     else
     {
         //not in cache, get it from disk
         KCatalog target = new KCatalog(className);
         KCatalog t      = (KCatalog)m_tree.Search(target);
         if (t != null)
         {
             _put_in_cache(t.ClassInfo.CId, className, t.ClassInfo.FieldNames, t.ClassInfo.TopNodeSId);
             return((ClassEntry)m_cid_cache[t.ClassInfo.CId]);
         }
         else
         {
             return(null);
         }
     }
 }
コード例 #2
0
ファイル: SegTree.cs プロジェクト: luanzhu/OOD.NET
        /// <summary>
        /// Given the segment id, return the offset, and the length of the segment related to the disk file.
        /// </summary>
        /// <param name="segId"></param>
        /// <param name="offset"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public bool GetAddr(uint segId, ref uint offset, ref int length)
        {
            KSegId target = new KSegId(segId);

            target = (KSegId)m_tree.Search(target);
            if (target != null && target.Addr != null)
            {
                offset = target.Addr.Offset;
                length = target.Addr.Length;
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #3
0
        public ObjectInfo SearchObject(object keyValue)
        {
            KClass key = new KClass(keyValue, OOD.Types.GetInternalType(keyValue.GetType()));
            KClass obj = (KClass)m_tree.Search(key);

            if (obj != null)
            {
                Debug.Assert(obj.SerializedOtherData != null);
                ObjectInfo result = new ObjectInfo(key.DataType, key.KValue, obj.SerializedOtherData.SerializedValues);

                return(result);
            }
            else
            {
                return(null);
            }
        }
コード例 #4
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);
            }
        }