Exemplo n.º 1
0
        private void CreatePageListData(SafeSortedList <T, PageInfo> _pages, int offset, int rowindex, int counter, byte[] page, int blocknum)
        {
            int idx = rowindex + _rowSize * counter;

            // key bytes
            byte[] kk;
            byte   size;

            if (_externalStrings == false)
            {
                kk   = _T.GetBytes(_pages.GetKey(counter + offset));
                size = (byte)kk.Length;
                if (size > _maxKeySize)
                {
                    size = _maxKeySize;
                }
            }
            else
            {
                kk = new byte[4];
                Buffer.BlockCopy(Helper.GetBytes(counter + offset, false), 0, kk, 0, 4);
                size = 4;
            }
            // key size = 1 byte
            page[idx] = size;
            Buffer.BlockCopy(kk, 0, page, idx + 1, page[idx]);
            // offset = 4 bytes
            byte[] b = Helper.GetBytes(_pages.GetValue(offset + counter).PageNumber, false);
            Buffer.BlockCopy(b, 0, page, idx + 1 + _maxKeySize, b.Length);
            // add counts
            b = Helper.GetBytes(_pages.GetValue(offset + counter).UniqueCount, false);
            Buffer.BlockCopy(b, 0, page, idx + 1 + _maxKeySize + 4, b.Length);
            // FEATURE : add dup counts
        }
Exemplo n.º 2
0
        private Page <T> LoadPage(T key, out PageInfo pageinfo)
        {
            int pagenum = -1;
            // find page in list of pages

            bool found = false;
            int  pos   = 0;

            if (key != null)
            {
                pos = FindPageOrLowerPosition(key, ref found);
            }

            pageinfo = _pageList.GetValue(pos);
            pagenum  = pageinfo.PageNumber;

            Page <T> page;

            if (_cache.TryGetValue(pagenum, out page) == false)
            {
                //load page from disk
                page = _index.LoadPageFromPageNumber(pagenum);
                _cache.Add(pagenum, page);
            }
            return(page);
        }
Exemplo n.º 3
0
        public void Deserialize(MGRBData input)
        {
            foreach (var c in input.c)
            {
                Container con = null;
                if (c.t == CTYPE.ALLONES)
                {
                    con = new BitmapContainer(true);
                }
                else if (c.t == CTYPE.BITMAP)
                {
                    List <ulong> list    = new List <ulong>();
                    var          dataLen = c.d.Length;
                    for (int i = 0; i < dataLen; i += 8)
                    {
                        list.Add(ToULong(c.d, i));
                    }
                    con = new BitmapContainer(list.ToArray());
                }
                else if (c.t == CTYPE.OFFSET)
                {
                    List <ushort> list    = new List <ushort>();
                    var           dataLen = c.d.Length;
                    for (int i = 0; i < dataLen; i += 2)
                    {
                        list.Add(ToUShort(c.d, i));
                    }
                    con = new OffsetContainer(list);
                }
                else if (c.t == CTYPE.INV)
                {
                    List <ushort> list    = new List <ushort>();
                    var           dataLen = c.d.Length;
                    for (int i = 0; i < dataLen; i += 2)
                    {
                        list.Add(ToUShort(c.d, i));
                    }
                    con = new InvertedContainer(list);
                }
                //else
                //{
                //    List<ushort> list = new List<ushort>();
                //    var dataLen = c.d.Length;
                //    for (int i = 0; i < dataLen; i += 2)
                //    {
                //        list.Add(ToUShort(c.d, i));
                //    }
                //    con = new OffsetContainerSL(list);
                //}
                _containers.Add(c.i, con);
            }
            var k = _containers.Keys();
            var l = k.Length - 1;

            if (l >= 0)
            {
                _size = (k[l] << 16) + _containers.GetValue(l).Size;
            }
        }
Exemplo n.º 4
0
        //public Statistics GetStatistics()
        //{
        //    Statistics s = new Statistics();
        //    s.TotalSplitTime = _totalsplits;
        //    s.PageCount = _pageList.Count;

        //    return s;
        //}

        #region [  P R I V A T E  ]
        private WAHBitArray doMoreOp(RDBExpression exp, T key)
        {
            bool        found  = false;
            int         pos    = FindPageOrLowerPosition(key, ref found);
            WAHBitArray result = new WAHBitArray();

            if (pos < _pageList.Count)
            {
                // all the pages after
                for (int i = pos + 1; i < _pageList.Count; i++)
                {
                    doPageOperation(ref result, i);
                }
            }
            // key page
            Page <T> page = LoadPage(_pageList.GetValue(pos).PageNumber);

            T[] keys = page.tree.Keys();
            Array.Sort(keys);

            // find better start position rather than 0
            pos = Array.IndexOf <T>(keys, key);
            if (pos == -1)
            {
                pos = 0;
            }

            for (int i = pos; i < keys.Length; i++)
            {
                T   k  = keys[i];
                int bn = page.tree[k].DuplicateBitmapNumber;

                if (k.CompareTo(key) > 0)
                {
                    result = result.Or(_index.GetDuplicateBitmap(bn));
                }

                if (exp == RDBExpression.GreaterEqual && k.CompareTo(key) == 0)
                {
                    result = result.Or(_index.GetDuplicateBitmap(bn));
                }
            }
            return(result);
        }
Exemplo n.º 5
0
        internal MGRB(SafeSortedList <int, Container> containers)
        {
            _containers = containers;
            var k = _containers.Keys();
            var l = k.Length - 1;

            if (l >= 0)
            {
                _size = (k[l] << 16) + _containers.GetValue(l).Size;
            }
        }
Exemplo n.º 6
0
        private void CreatePageListData(SafeSortedList <T, PageInfo> _pages, int i, byte[] page, int index, int j)
        {
            int idx = index + _rowSize * j;

            // key bytes
            byte[] kk   = _T.GetBytes(_pages.GetKey(j + i));
            byte   size = (byte)kk.Length;

            if (size > _maxKeySize)
            {
                size = _maxKeySize;
            }
            // key size = 1 byte
            page[idx] = size;
            Buffer.BlockCopy(kk, 0, page, idx + 1, page[idx]);
            // offset = 4 bytes
            byte[] b = Helper.GetBytes(_pages.GetValue(i + j).PageNumber, false);
            Buffer.BlockCopy(b, 0, page, idx + 1 + _maxKeySize, b.Length);
            // add counts
            b = Helper.GetBytes(_pages.GetValue(i + j).UniqueCount, false);
            Buffer.BlockCopy(b, 0, page, idx + 1 + _maxKeySize + 4, b.Length);
            // FEATURE : add dup counts
        }
Exemplo n.º 7
0
        internal MGRB(SafeSortedList <int, Container> containers, long size)
        {
            _containers = containers;
            var k = _containers.Keys();

            _size = size;
            if (size <= 0)//== -1)
            {
                _size = 0;
                var l = k.Length - 1;
                if (l >= 0)
                {
                    _size = (k[l] << 16) + _containers.GetValue(l).Size;
                }
            }
        }
Exemplo n.º 8
0
        public MGRB Query(T from, T to, int maxsize)
        {
            MGRB bits = new MGRB();
            T    temp = default(T);

            if (from.CompareTo(to) > 0) // check values order
            {
                temp = from;
                from = to;
                to   = temp;
            }
            // find first page and do > than
            bool found    = false;
            int  startpos = FindPageOrLowerPosition(from, ref found);
            // find last page and do < than
            int  endpos   = FindPageOrLowerPosition(to, ref found);
            bool samepage = startpos == endpos;

            // from key page
            Page <T> page = LoadPage(_pageList.GetValue(startpos).PageNumber);

            T[] keys = page.tree.Keys();
            Array.Sort(keys);

            // find better start position rather than 0
            int pos = Array.BinarySearch <T>(keys, from); // FEATURE : rewrite??

            if (pos < 0)
            {
                pos = ~pos;
            }

            for (int i = pos; i < keys.Length; i++)
            {
                T   k  = keys[i];
                int bn = page.tree[k].DuplicateBitmapNumber;

                if (samepage)
                {
                    if (k.CompareTo(from) >= 0 && k.CompareTo(to) <= 0) // if from,to same page
                    {
                        bits = bits.Or(_index.GetDuplicateBitmap(bn));
                    }
                }
                else
                {
                    if (k.CompareTo(from) >= 0)
                    {
                        bits = bits.Or(_index.GetDuplicateBitmap(bn));
                    }
                }
            }
            if (!samepage)
            {
                // to key page
                page = LoadPage(_pageList.GetValue(endpos).PageNumber);
                keys = page.tree.Keys();
                Array.Sort(keys);
                // find better end position rather than last key
                pos = Array.BinarySearch <T>(keys, to);
                if (pos < 0)
                {
                    pos = ~pos;
                }

                for (int i = 0; i <= pos; i++)
                {
                    T   k  = keys[i];
                    int bn = page.tree[k].DuplicateBitmapNumber;

                    if (k.CompareTo(to) <= 0)
                    {
                        bits = bits.Or(_index.GetDuplicateBitmap(bn));
                    }
                }
                // do all pages in between
                for (int i = startpos + 1; i < endpos; i++)
                {
                    doPageOperation(ref bits, i);
                }
            }
            return(bits);
        }