Exemplo n.º 1
0
        public void Set(long position, bool val)
        {
            lock (_lock)
            {
                isDirty = true;
                if (_size < position && val == true)
                {
                    _size = position;
                }

                var       idx = (int)(position >> 16);
                Container c   = null;
                if (_containers.TryGetValue(idx, out c) == false)
                {
                    //if (Global.useSortedList)
                    //    c = new OffsetContainerSL();
                    //else
                    c = new OffsetContainer();
                    // add container
                    _containers.Add(idx, c);
                }
                c.Set(position & _MASK, val);

                //if (c.ChangeRequired())
                //    _containers[idx] = c.Change();
            }
        }
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 Commit(bool freeMemory)
        {
            if (_isDirty == false)
            {
                return;
            }
            using (new L(this))
            {
                log.Debug("writing " + _FileName);
                int[] keys = _cache.Keys();
                Array.Sort(keys);

                foreach (int k in keys)
                {
                    WAHBitArray bmp = null;
                    if (_cache.TryGetValue(k, out bmp) && bmp.isDirty)
                    {
                        SaveBitmap(k, bmp);
                        bmp.FreeMemory();
                        bmp.isDirty = false;
                    }
                }
                Flush();
                if (freeMemory)
                {
                    _cache = //new SafeDictionary<int, WAHBitArray>();
                             new SafeSortedList <int, WAHBitArray>();
                    log.Debug("  freeing cache");
                }
                _isDirty = false;
            }
        }
Exemplo n.º 4
0
        private WAHBitArray ExecutionPlan(string filter, int maxsize)
        {
            //_log.Debug("query : " + filter);
            DateTime dt = FastDateTime.Now;

            // query indexes
            string[] words = filter.Split(' ');
            //bool defaulttoand = true;
            //if (filter.IndexOfAny(new char[] { '+', '-' }, 0) > 0)
            //    defaulttoand = false;

            WAHBitArray found = null;// WAHBitArray.Fill(maxsize);

            foreach (string s in words)
            {
                int    c;
                bool   not  = false;
                string word = s;
                if (s == "")
                {
                    continue;
                }

                OPERATION op = OPERATION.AND;
                //if (defaulttoand)
                //    op = OPERATION.AND;

                if (word.StartsWith("+"))
                {
                    op   = OPERATION.OR;
                    word = s.Replace("+", "");
                }

                if (word.StartsWith("-"))
                {
                    op   = OPERATION.ANDNOT;
                    word = s.Replace("-", "");
                    not  = true;
                    if (found == null) // leading with - -> "-oak hill"
                    {
                        found = WAHBitArray.Fill(maxsize);
                    }
                }

                if (word.Contains("*") || word.Contains("?"))
                {
                    WAHBitArray wildbits = new WAHBitArray();

                    // do wildcard search
                    Regex reg = new Regex("^" + word.Replace("*", ".*").Replace("?", ".") + "$", RegexOptions.IgnoreCase);
                    foreach (string key in _words.Keys())
                    {
                        if (reg.IsMatch(key))
                        {
                            _words.TryGetValue(key, out c);
                            WAHBitArray ba = _bitmaps.GetBitmap(c);

                            wildbits = DoBitOperation(wildbits, ba, OPERATION.OR, maxsize);
                        }
                    }
                    if (found == null)
                    {
                        found = wildbits;
                    }
                    else
                    {
                        if (not) // "-oak -*l"
                        {
                            found = found.AndNot(wildbits);
                        }
                        else if (op == OPERATION.AND)
                        {
                            found = found.And(wildbits);
                        }
                        else
                        {
                            found = found.Or(wildbits);
                        }
                    }
                }
                else if (_words.TryGetValue(word.ToLowerInvariant(), out c))
                {
                    // bits logic
                    WAHBitArray ba = _bitmaps.GetBitmap(c);
                    found = DoBitOperation(found, ba, op, maxsize);
                }
                else if (op == OPERATION.AND)
                {
                    found = null;
                }
            }
            if (found == null)
            {
                return(new WAHBitArray());
            }

            // remove deleted docs
            WAHBitArray ret;

            if (_docMode)
            {
                ret = found.AndNot(_deleted.GetBits());
            }
            else
            {
                ret = found;
            }
            //_log.Debug("query time (ms) = " + FastDateTime.Now.Subtract(dt).TotalMilliseconds);
            return(ret);
        }