Exemplo n.º 1
0
        private void SplitPage(Page <T> page)
        {
            // split the page
            DateTime dt = FastDateTime.Now;

            Page <T> newpage = new Page <T>();

            newpage.DiskPageNumber  = _index.GetNewPageNumber();
            newpage.RightPageNumber = page.RightPageNumber;
            newpage.isDirty         = true;
            page.RightPageNumber    = newpage.DiskPageNumber;
            // get and sort keys
            T[] keys = page.tree.Keys();
            Array.Sort <T>(keys);
            // copy data to new
            for (int i = keys.Length / 2; i < keys.Length; i++)
            {
                newpage.tree.Add(keys[i], page.tree[keys[i]]);
                // remove from old page
                page.tree.Remove(keys[i]);
            }
            // set the first key
            newpage.FirstKey = keys[keys.Length / 2];
            // set the first key refs
            _pageList.Remove(page.FirstKey);
            _pageList.Remove(keys[0]);
            // dup counts
            _pageList.Add(keys[0], new PageInfo(page.DiskPageNumber, page.tree.Count, 0));
            page.FirstKey = keys[0];
            // FEATURE : dup counts
            _pageList.Add(newpage.FirstKey, new PageInfo(newpage.DiskPageNumber, newpage.tree.Count, 0));
            _cache.Add(newpage.DiskPageNumber, newpage);

            _totalsplits += FastDateTime.Now.Subtract(dt).TotalSeconds;
        }
Exemplo n.º 2
0
        private void SplitPage(Page <T> page)
        {
            // split the page
            DateTime dt = FastDateTime.Now;

            Page <T> newpage = new Page <T>();

            newpage.DiskPageNumber  = _index.GetNewPageNumber();
            newpage.RightPageNumber = page.RightPageNumber;
            newpage.isDirty         = true;
            page.RightPageNumber    = newpage.DiskPageNumber;
            _pageList.Remove(page.FirstKey);
            // get and sort keys
            T[] keys = page.tree.Keys.OrderBy(x => x).ToArray();

            // copy data to new
            for (int i = keys.Length / 2; i < keys.Length; i++)
            {
                newpage.tree.TryAdd(keys[i], page.tree[keys[i]]);
                // remove from old page
                page.tree.TryRemove(keys[i], out KeyInfo value);
            }
            // set the first key
            newpage.FirstKey = keys[keys.Length / 2]; // new key
            // remove keys from page list
            _pageList.Remove(newpage.FirstKey);
            page.FirstKey = keys[0]; // new key
            // re add to page list
            _pageList.Add(page.FirstKey, new PageInfo(page.DiskPageNumber, page.tree.Count(), 0));
            _pageList.Add(newpage.FirstKey, new PageInfo(newpage.DiskPageNumber, newpage.tree.Count(), 0));
            _cache.TryAdd(newpage.DiskPageNumber, newpage);

            _totalsplits += FastDateTime.Now.Subtract(dt).TotalSeconds;
        }
Exemplo n.º 3
0
 public void FreeMemory()
 {
     _index.FreeMemory();
     try
     {
         List <int> free = new List <int>();
         foreach (var c in _cache)
         {
             if (c.Value.isDirty == false)
             {
                 free.Add(c.Key);
             }
         }
         _log.Debug("releasing page count = " + free.Count + " out of " + _cache.Count);
         foreach (var i in free)
         {
             _cache.Remove(i);
         }
     }
     catch { }
 }
Exemplo n.º 4
0
 internal void FreeMemory()
 {
     try
     {
         List <int> free = new List <int>();
         foreach (var b in _cache)
         {
             if (b.Value.isDirty == false)
             {
                 free.Add(b.Key);
             }
         }
         log.Debug("releasing bmp count = " + free.Count + " out of " + _cache.Count);
         foreach (int i in free)
         {
             _cache.Remove(i);
         }
     }
     catch (Exception ex) {
         log.Error(ex);
     }
 }
Exemplo n.º 5
0
        public MGRB Optimize()
        {
            lock (_lock)
            {
                var keys   = _containers.Keys();
                var remove = new List <int>();

                for (int i = 0; i < keys.Length; i++)
                {
                    var k = keys[i];
                    var c = _containers[k];

                    if (c.CountOnes() == 0)
                    {
                        remove.Add(k);
                    }

                    //else if (c.CountZeros() < Container.CHGOVER)
                    //{
                    //    _containers[k] = new ZeroContainer();
                    //}

                    else if (c.ChangeRequired())
                    {
                        _containers[k] = c.Change();
                    }
                }

                foreach (var k in remove)
                {
                    _containers.Remove(k);
                }

                return(this);
            }
        }