Beispiel #1
0
 public ClassEntry Search(uint cid)
 {
     //time consuming operations, that's the reason for cache
     if (m_cid_cache.ContainsKey(cid))
     {
         ClassEntry t = (ClassEntry)m_cid_cache[cid];
         t.BreakLinks();
         t.BuildLinks(m_LRU, m_LRU.Next);
         return(t);
     }
     else
     {
         //do the sequential search, :(
         OOD.Imp.Storage.BTree.BTEnumerator bt = m_tree.GetEnumerator();
         while (bt.MoveNext())
         {
             KCatalog key = (KCatalog)bt.Current;
             Debug.Assert(key != null);
             if (key.ClassInfo != null && key.ClassInfo.CId == cid)
             {
                 //found
                 _put_in_cache(cid, key.ClassName, key.ClassInfo.FieldNames, key.ClassInfo.TopNodeSId);
                 return((ClassEntry)m_cid_cache[cid]);
             }
         }
         return(null);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Request a segment with size of length.
        /// </summary>
        /// <param name="length"></param>
        /// <returns>True if succeed, otherwise false.</returns>
        /// <preCondition></preCondition>
        /// <PostCondition>A free segment will offset as the starting place and length as size
        /// is cleared from this free space tree.</PostCondition>
        public bool RequireSegment(int length, ref uint offset)
        {
            //do the sequential search
            OOD.Imp.Storage.BTree.BTEnumerator enumerator = m_tree.GetEnumerator();
            KOffset finding = null;

//			while (enumerator.MoveNext())
//			{
//				KOffset temp = (KOffset)enumerator.Current;
//				if (temp != null && temp.Length.Num >= length)
//				{
//					finding = temp;
//					break;
//				}
//			}
            if (finding == null)
            {
                //no free space find in the b-tree, create a new segment after the file end
                offset = (uint)m_dbFile.Length;
                m_dbFile.SetLength(offset + length);
            }
            else
            {
                //find new space in the tree
                offset = finding.Offset;
                int len = finding.Length.Num;
                if (m_tree.Delete(finding) == false)
                {
                    throw new OOD.Exception.ProgramLogicError(
                              this,
                              "Delete free space failed.");
                }

                if (finding.Length.Num > length)
                {
                    //put the left back
                    finding.Offset     = (uint)(offset + length);
                    finding.Length.Num = len - length;
                    if (m_tree.Insert(finding) == false)
                    {
                        throw new OOD.Exception.ProgramLogicError(
                                  this,
                                  "Insert free space failed.");
                    }
                }
            }

            return(true);
        }