Exemplo n.º 1
0
        public int GetAllKeys(IntArrayList offsets)
        {
            int count = _treeNode.Count;

            if (count > 0)
            {
                ProcessDeferredUpdates();
                SetPosition(0);
                for (int index = 0; index < count; index++)
                {
                    int offset;
                    MemoryReadNext(out offset);
                    offsets.Add(offset);
                }
            }
            return(count);
        }
Exemplo n.º 2
0
Arquivo: Caches.cs Projeto: mo5h/omeo
        public void RemoveAll()
        {
            IntArrayList keys = new IntArrayList(Count);

            for (ushort current = _top; current > 0;)
            {
                if (_cache[current].x != null)
                {
                    keys.Add(_cache[current].key);
                }
                current = _cache[current].next;
            }
            for (int i = 0; i < keys.Count; ++i)
            {
                Remove(keys[i]);
            }
        }
Exemplo n.º 3
0
Arquivo: Tries.cs Projeto: mo5h/omeo
 private void GetSubtree(int index, IntArrayList wards, bool tokensOnly)
 {
     if (index >= 0)
     {
         TrieNode node = LoadNodeByIndex(index);
         if (!tokensOnly || node.IsToken)
         {
             wards.Add(index);
         }
         index = node._firstChild;
         while (index != 0)
         {
             GetSubtree(index, wards, tokensOnly);
             node  = LoadNodeByIndex(index);
             index = node._sibling;
         }
     }
 }
Exemplo n.º 4
0
        public static IntArrayList IntersectSorted(IntArrayList list1, IntArrayList list2, IComparer comparer)
        {
            int count1 = list1.Count;
            int count2 = list2.Count;

            if (count1 == 0)
            {
                return(list1);
            }
            if (count2 == 0)
            {
                return(list2);
            }
            IntArrayList result = new IntArrayList(Math.Min(count1, count2));
            int          index1 = 0;
            int          index2 = 0;

            while (index1 < count1 && index2 < count2)
            {
                int compareResult = comparer.Compare(list1 [index1], list2  [index2]);
                if (compareResult == 0)
                {
                    result.Add(list1 [index1]);
                    index1++;
                }
                else if (compareResult < 0)
                {
                    index1++;
                }
                else
                {
                    index2++;
                }
            }
            return(result);
        }
Exemplo n.º 5
0
        public void SearchForRange(IFixedLengthKey beginKey, IFixedLengthKey endKey, IntArrayList offsets)
        {
            if (_treeNode.Count == 0)
            {
                return;
            }

            int             index, offset;
            KeyPair         pair;
            IFixedLengthKey deferredKey;
            int             deferredInsertionsIndex = ~GetDeferredInsertionIndex(beginKey, -1);

            IFixedLengthKey foundKey = SearchL(0, _rightBound, beginKey, -1, out index);

            if (foundKey != null && index != -1 && index < _rightBound)
            {
                int deferredDeletionsIndex = ~GetDeferredDeletionIndex(beginKey, -1);
                SetPosition(index);
                for ( ; index < _rightBound; ++index)
                {
                    IFixedLengthKey aKey = MemoryReadNext(out offset);
                    for ( ; deferredInsertionsIndex < _deferredInsertions.Count; ++deferredInsertionsIndex)
                    {
                        pair        = (KeyPair)_deferredInsertions[deferredInsertionsIndex];
                        deferredKey = pair._key;
                        if (deferredKey.CompareTo(aKey) > 0)
                        {
                            break;
                        }
                        if (beginKey.CompareTo(deferredKey) <= 0)
                        {
                            if (endKey.CompareTo(deferredKey) < 0)
                            {
                                break;
                            }
                            offsets.Add(pair._offset);
                        }
                    }
                    if (endKey.CompareTo(aKey) < 0)
                    {
                        break;
                    }
                    bool deleted = false;
                    while (deferredDeletionsIndex < _deferredDeletions.Count)
                    {
                        pair = (KeyPair)_deferredDeletions[deferredDeletionsIndex];
                        int compareResult = pair._key.CompareTo(aKey);
                        if (compareResult == 0)
                        {
                            compareResult = pair._offset - offset;
                        }
                        if (compareResult > 0)
                        {
                            break;
                        }
                        ++deferredDeletionsIndex;
                        if (compareResult == 0)
                        {
                            deleted = true;
                            break;
                        }
                    }
                    if (!deleted)
                    {
                        offsets.Add(offset);
                    }
                }
            }
            for ( ; deferredInsertionsIndex < _deferredInsertions.Count; ++deferredInsertionsIndex)
            {
                pair        = (KeyPair)_deferredInsertions[deferredInsertionsIndex];
                deferredKey = pair._key;
                if (beginKey.CompareTo(deferredKey) <= 0)
                {
                    if (endKey.CompareTo(deferredKey) < 0)
                    {
                        break;
                    }
                    offsets.Add(pair._offset);
                }
            }
        }