예제 #1
0
        public void Remove01()
        {
            var bitset = new BitSet(2000);

            bitset.Remove(750);
            Assert.IsFalse(bitset.Has(750));
            bitset.Add(750);
            Assert.IsTrue(bitset.Has(750));
            bitset.Remove(750);
            Assert.IsFalse(bitset.Has(750));

            bitset.Remove(0);
            Assert.IsFalse(bitset.Has(0));
            bitset.Add(0);
            Assert.IsTrue(bitset.Has(0));
            bitset.Remove(0);
            Assert.IsFalse(bitset.Has(0));

            bitset.Remove(1023);
            Assert.IsFalse(bitset.Has(1023));
            bitset.Add(1023);
            Assert.IsTrue(bitset.Has(1023));
            bitset.Remove(1023);
            Assert.IsFalse(bitset.Has(1023));

            bitset.Remove(750);
            Assert.IsFalse(bitset.Has(750));
        }
예제 #2
0
        public void Remove01u()
        {
            var bitset = new BitSet((uint)2000);

            bitset.Remove((uint)750);
            Assert.IsFalse(bitset.Has((uint)750));
            bitset.Add((uint)750);
            Assert.IsTrue(bitset.Has((uint)750));
            bitset.Remove((uint)750);
            Assert.IsFalse(bitset.Has((uint)750));

            bitset.Remove((uint)0);
            Assert.IsFalse(bitset.Has((uint)0));
            bitset.Add((uint)0);
            Assert.IsTrue(bitset.Has((uint)0));
            bitset.Remove((uint)0);
            Assert.IsFalse(bitset.Has((uint)0));

            bitset.Remove((uint)1023);
            Assert.IsFalse(bitset.Has((uint)1023));
            bitset.Add((uint)1023);
            Assert.IsTrue(bitset.Has((uint)1023));
            bitset.Remove((uint)1023);
            Assert.IsFalse(bitset.Has((uint)1023));

            bitset.Remove((uint)750);
            Assert.IsFalse(bitset.Has((uint)750));
        }
예제 #3
0
        public void MultipleWordsMultipleEntries()
        {
            var set = new BitSet(initialCapacity: 128);

            set.SetLength(128);

            set.Add(45);
            set.Add(64);
            set.Add(127);
            VerifyContents(set, 45, 127, 64);
        }
예제 #4
0
        public void OutOfRange01()
        {
            var bitset = new BitSet(1023);

            Assert.Throws <ArgumentOutOfRangeException>(() => bitset.Has(-1));
            Assert.Throws <ArgumentOutOfRangeException>(() => bitset.Has(1024));
            Assert.Throws <ArgumentOutOfRangeException>(() => bitset.Add(-1));
            Assert.Throws <ArgumentOutOfRangeException>(() => bitset.Add(1024));
            Assert.Throws <ArgumentOutOfRangeException>(() => bitset.Remove(-1));
            Assert.Throws <ArgumentOutOfRangeException>(() => bitset.Remove(1024));
            Assert.Throws <ArgumentOutOfRangeException>(() => bitset.Toggle(-1));
            Assert.Throws <ArgumentOutOfRangeException>(() => bitset.Toggle(1024));
        }
예제 #5
0
        public void ContentsAfterContraction()
        {
            var set = new BitSet(initialCapacity: 128);

            set.SetLength(128);

            set.Add(32);
            set.Add(127);
            set.Add(64);
            set.Add(63);

            set.SetLength(64);

            VerifyContents(set, 32, 63);
        }
예제 #6
0
        /// <summary>
        /// Updates the pip file system after adding a path
        /// </summary>
        /// <remarks>
        /// Not thread-safe
        /// </remarks>
        public void AddPath(PathTable pathTable, AbsolutePath path)
        {
            var index = GetIndexByPath(path);

            while (true)
            {
                if (index >= m_bitset.Length)
                {
                    // under unknown conditions, index might be larger than pathTable.Count
                    // let's just select the largest one, so there is enough space in the bitset
                    var newSize = BitSet.RoundToValidBitCount(Math.Max(pathTable.Count, index));
                    m_bitset.SetLength(newSize);

                    if (index < 0 || index >= m_bitset.Length)
                    {
                        Contract.Assert(false, $"The size of BitSet was increased, yet index={index} is still outside [0, {m_bitset.Length}) range. NewSize = {newSize}. PathTable.Count={pathTable.Count}");
                    }
                }

                if (m_bitset.Contains(index))
                {
                    break;
                }

                m_bitset.Add(index);
                index = GetParentIndex(pathTable, index);
            }
        }
예제 #7
0
        public void SingleWordSingleEntry()
        {
            var set = new BitSet(initialCapacity: 64);

            set.SetLength(64);

            set.Add(32);
            VerifyContents(set, 32);
        }
예제 #8
0
        public void Add01u()
        {
            var bitset = new BitSet((uint)1023);

            Assert.IsFalse(bitset.Has((uint)250));
            bitset.Add((uint)250);
            Assert.IsTrue(bitset.Has((uint)250));

            Assert.IsFalse(bitset.Has((uint)0));
            bitset.Add((uint)0);
            Assert.IsTrue(bitset.Has((uint)0));

            Assert.IsFalse(bitset.Has((uint)1023));
            bitset.Add((uint)1023);
            Assert.IsTrue(bitset.Has((uint)1023));

            bitset.Add((uint)250);
            Assert.IsTrue(bitset.Has((uint)250));
        }
예제 #9
0
        public void Add01()
        {
            var bitset = new BitSet(1023);

            Assert.IsFalse(bitset.Has(250));
            bitset.Add(250);
            Assert.IsTrue(bitset.Has(250));

            Assert.IsFalse(bitset.Has(0));
            bitset.Add(0);
            Assert.IsTrue(bitset.Has(0));

            Assert.IsFalse(bitset.Has(1023));
            bitset.Add(1023);
            Assert.IsTrue(bitset.Has(1023));

            bitset.Add(250);
            Assert.IsTrue(bitset.Has(250));
        }
예제 #10
0
        public void SetUp()
        {
            _one   = new BitSet(1);
            _three = new BitSet(-1, 1);
            _full  = new BitSet(4);

            for (var i = 0; i < 4; i++)
            {
                _full.Add(i);
            }
        }
예제 #11
0
        public void ContentsAfterExpansion()
        {
            var set = new BitSet(initialCapacity: 64);

            set.SetLength(64);

            set.Add(32);
            set.SetLength(128);

            VerifyContents(set, 32);
        }
예제 #12
0
        public void Clear01()
        {
            var bitset = new BitSet(20);

            foreach (var item in new[] { 0, 1, 2, 3, 4 })
            {
                bitset.Add(item);
            }
            Assert.AreNotEqual(0, bitset.Count);
            bitset.Clear();
            Assert.AreEqual(0, bitset.Count);
        }
예제 #13
0
        public void MultipleWordsAllEntries()
        {
            var set = new BitSet(initialCapacity: 128);

            set.SetLength(128);

            for (int i = 0; i < 128; i++)
            {
                set.Add(i);
            }

            VerifyContents(set, Enumerable.Range(0, 128).ToArray());
        }
예제 #14
0
        public void SingleWordAllEntries()
        {
            var set = new BitSet(initialCapacity: 64);

            set.SetLength(64);

            for (int i = 0; i < 64; i++)
            {
                set.Add(i);
            }

            VerifyContents(set, Enumerable.Range(0, 64).ToArray());
        }
예제 #15
0
        public void Count01u()
        {
            var bitset = new BitSet(15);
            var inputs = new uint[] { 0, 1, 2, 3, 4 };

            foreach (var item in inputs)
            {
                bitset.Add(item);
                bitset.Add(item);
            }
            Assert.AreEqual(bitset.Count, 5);
            for (int i = 0; i < 2; i++)
            {
                bitset.Remove(inputs[i]);
                bitset.Remove(inputs[i]);
            }
            Assert.AreEqual(bitset.Count, 3);
            foreach (var item in inputs)
            {
                bitset.Toggle(item);
            }
            Assert.AreEqual(bitset.Count, 2);
        }
예제 #16
0
        public void Clear()
        {
            var set = new BitSet(initialCapacity: 128);

            set.SetLength(128);

            for (int i = 0; i < 128; i++)
            {
                set.Add(i);
            }

            set.Clear();

            VerifyContents(set);
        }
예제 #17
0
        public void FullCapacity01u()
        {
            uint max    = 50;
            var  bitset = new BitSet(max);

            for (uint i = 0; i <= max; i++)
            {
                bitset.Add(i);
            }
            Assert.AreEqual(max + 1, bitset.Count);
            for (uint i = 0; i <= max; i++)
            {
                Assert.IsTrue(bitset.Has(i));
            }
        }
예제 #18
0
        public void Set_CopiesToArrayProperly(int count)
        {
            var set = new BitSet(count);

            for (var i = 0; i < count; i++)
            {
                set.Add(i);
            }

            var array = new int[set.Count];

            set.CopyTo(array, 0);

            set.SetEquals(array);
        }
예제 #19
0
        public void Set_IsFilled_Properly(int count)
        {
            var set = new BitSet(count);

            for (var i = 0; i < count; i++)
            {
                set.Add(i);

                Assert.AreEqual(i + 1, set.Count);
            }

            for (var i = 0; i < count; i++)
            {
                Assert.IsTrue(set.Contains(i));
            }
        }
예제 #20
0
        public void IEnumerable01u()
        {
            var bitset = new BitSet((uint)255);
            var inputs = new uint[] { 0, 30, 31, 32, 33, 100, 200, 255 };

            foreach (var item in inputs)
            {
                bitset.Add(item);
            }
            var size = 0;

            foreach (var item in bitset)
            {
                size++;
            }
            Assert.AreEqual(inputs.Length, size);
        }
예제 #21
0
        public void Big()
        {
            var set = new BitSet(initialCapacity: 64 * 1024);

            set.SetLength(64 * 1024);

            var rng   = new Random(99);
            var added = new int[2 * 1024];

            for (int i = 0; i < added.Length; i++)
            {
                added[i] = rng.Next(0, 64 * 1024);
                set.Add(added[i]);
            }

            VerifyContents(set, added);
        }
예제 #22
0
        public void Set_EnumeratesProperly(int count)
        {
            var set = new BitSet(count);

            for (var i = 0; i < count; i++)
            {
                set.Add(i);
            }

            var list = new List <int>();

            foreach (var i in set)
            {
                list.Add(i);
            }

            set.SetEquals(list);
        }
예제 #23
0
        /// <summary>
        /// Updates the pip file system after adding a path
        /// </summary>
        /// <remarks>
        /// Not thread-safe
        /// </remarks>
        public void AddPath(PathTable pathTable, AbsolutePath path)
        {
            var index = GetIndexByPath(path);

            while (true)
            {
                if (index >= m_bitset.Length)
                {
                    var newSize = BitSet.RoundToValidBitCount(pathTable.Count);
                    m_bitset.SetLength(newSize);
                }

                if (m_bitset.Contains(index))
                {
                    break;
                }

                m_bitset.Add(index);
                index = GetParentIndex(pathTable, index);
            }
        }
예제 #24
0
 /** Rules like "a : ;" and "a : {...} ;" should not generate
  *  try/catch blocks for RecognitionException.  To detect this
  *  it's probably ok to just look for any reference to an atom
  *  that can match some input.  W/o that, the rule is unlikey to have
  *  any else.
  */
 public virtual bool IsEmptyRule( GrammarAST block )
 {
     BitSet nonEmptyTerminals = new BitSet();
     nonEmptyTerminals.Add(ANTLRParser.TOKEN_REF);
     nonEmptyTerminals.Add(ANTLRParser.STRING_LITERAL);
     nonEmptyTerminals.Add(ANTLRParser.CHAR_LITERAL);
     nonEmptyTerminals.Add(ANTLRParser.WILDCARD);
     nonEmptyTerminals.Add(ANTLRParser.RULE_REF);
     return FindFirstTypeOutsideRewrite(block, nonEmptyTerminals) == null;
 }
예제 #25
0
        public void Add_ReturnsFalse_ForExistingElement()
        {
            _one.Add(0);

            Assert.IsFalse(_one.Add(0));
        }
예제 #26
0
 public void Add_ThrowsException_ForElementGreaterThanMax()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => _three.Add(2));
 }
예제 #27
0
        protected void InsertImaginaryIndentDedentTokens()
        {
            IToken t = stream.LT(1);

            stream.Consume();
            IList hiddenTokens;

            // if not a NEWLINE, doesn't signal indent/dedent work; just enqueue
            if (t.Type != PythonLexer.NEWLINE)
            {
                hiddenTokens = stream.GetTokens(lastTokenAddedIndex + 1, t.TokenIndex - 1);
                if (hiddenTokens != null)
                {
                    tokens.AddRange(hiddenTokens);
                }
                lastTokenAddedIndex = t.TokenIndex;
                tokens.Add(t);
                return;
            }

            // we know it's a newline

            BitSet hidden = BitSet.Of(PythonLexer.COMMENT,
                                      PythonLexer.LEADING_WS,
                                      PythonLexer.CONTINUED_LINE,
                                      PythonLexer.NEWLINE);

            hidden.Add(PythonLexer.WS);

            // save NEWLINE in the queue
            //System.out.println("found newline: "+t+" stack is "+StackString());
            hiddenTokens = stream.GetTokens(lastTokenAddedIndex + 1, t.TokenIndex - 1, hidden);

            if (hiddenTokens != null)
            {
                tokens.AddRange(hiddenTokens);
            }
            lastTokenAddedIndex = t.TokenIndex;
            tokens.Add(t);

            // grab first token of next line
            t = stream.LT(1);
            stream.Consume();
            hiddenTokens = stream.GetTokens(lastTokenAddedIndex + 1, t.TokenIndex - 1, hidden);

            if (hiddenTokens != null)
            {
                tokens.AddRange(hiddenTokens);
            }
            lastTokenAddedIndex = t.TokenIndex;

            // compute cpos as the char pos of next non-WS token in line
            int cpos = t.CharPositionInLine;             // column dictates indent/dedent

            if (t.Type == TokenTypes.EndOfFile)
            {
                cpos = -1;                 // pretend EOF always happens at left edge
            }
            else if (t.Type == PythonLexer.LEADING_WS)
            {
                cpos = t.Text.Length;
            }

            //System.out.println("next token is: "+t);

            // compare to last indent level
            int lastIndent = Peek();

            //System.out.println("cpos, lastIndent = "+cpos+", "+lastIndent);

            if (cpos > lastIndent)
            {             // they indented; track and gen INDENT
                Push(cpos);
                //System.out.println("Push("+cpos+"): "+StackString());
                IToken indent = new ClassicToken(PythonParser.INDENT, "");
                indent.CharPositionInLine = t.CharPositionInLine;
                indent.Line = t.Line;
                tokens.Add(indent);
            }
            else if (cpos < lastIndent)
            {             // they dedented
                // how far back did we dedent?
                int prevIndex = FindPreviousIndent(cpos);
                //System.out.println("dedented; prevIndex of cpos="+cpos+" is "+prevIndex);
                // generate DEDENTs for each indent level we backed up over
                for (int d = sp - 1; d >= prevIndex; d--)
                {
                    IToken dedent = new ClassicToken(PythonParser.DEDENT, "");
                    dedent.CharPositionInLine = t.CharPositionInLine;
                    dedent.Line = t.Line;
                    tokens.Add(dedent);
                }
                sp = prevIndex;                 // pop those off indent level
            }
            if (t.Type != PythonLexer.LEADING_WS)
            {             // discard WS
                tokens.Add(t);
            }
        }
        public void HandleText(HtmlTextNode node)
        {
            if (IsTag(node.Text))
            {
                node.Text = "";
            }

            char[] ch     = HttpUtility.HtmlDecode(node.Text).ToCharArray();
            int    start  = 0;
            int    length = ch.Length;

            textElementIdx++;

            if (flush)
            {
                FlushBlock();
                flush = false;
            }
            if (inIgnorableElement != 0)
            {
                return;
            }

            char c;
            bool startWhitespace = false;
            bool endWhitespace   = false;

            if (length == 0)
            {
                return;
            }
            int end = start + length;

            for (int i = start; i < end; i++)
            {
                if (IsWhiteSpace(ch [i]))
                {
                    ch [i] = ' ';
                }
            }
            while (start < end)
            {
                c = ch [start];
                if (c == ' ')
                {
                    startWhitespace = true;
                    start++;
                    length--;
                }
                else
                {
                    break;
                }
            }
            while (length > 0)
            {
                c = ch [start + length - 1];
                if (c == ' ')
                {
                    endWhitespace = true;
                    length--;
                }
                else
                {
                    break;
                }
            }
            if (length == 0)
            {
                if (startWhitespace || endWhitespace)
                {
                    if (!sbLastWasWhitespace)
                    {
                        textBuilder.Append(' ');
                        tokenBuilder.Append(' ');
                    }
                    sbLastWasWhitespace = true;
                }
                else
                {
                    sbLastWasWhitespace = false;
                }
                lastEvent = NBoilerpipeContentHandler.Event.WHITESPACE;
                return;
            }
            if (startWhitespace)
            {
                if (!sbLastWasWhitespace)
                {
                    textBuilder.Append(' ');
                    tokenBuilder.Append(' ');
                }
            }
            if (blockTagLevel == -1)
            {
                blockTagLevel = tagLevel;
            }
            textBuilder.Append(ch, start, length);
            tokenBuilder.Append(ch, start, length);
            if (endWhitespace)
            {
                textBuilder.Append(' ');
                tokenBuilder.Append(' ');
            }
            sbLastWasWhitespace = endWhitespace;
            lastEvent           = NBoilerpipeContentHandler.Event.CHARACTERS;
            currentContainedTextElements.Add(textElementIdx);
        }