Пример #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void putOtherBitSet()
        public virtual void PutOtherBitSet()
        {
            // Given
            SimpleBitSet set      = new SimpleBitSet(16);
            SimpleBitSet otherSet = new SimpleBitSet(16);

            otherSet.Put(4);
            otherSet.Put(14);

            set.Put(3);
            set.Put(4);

            // When
            set.Put(otherSet);

            // Then
            assertFalse(set.Contains(0));
            assertFalse(set.Contains(1));
            assertFalse(set.Contains(15));
            assertFalse(set.Contains(7));

            assertTrue(set.Contains(3));
            assertTrue(set.Contains(4));
            assertTrue(set.Contains(14));
        }
Пример #2
0
        public virtual void Remove(SimpleBitSet other)
        {
            long stamp = writeLock();

            for (int i = 0; i < _data.Length; i++)
            {
                _data[i] = _data[i] & ~other._data[i];
            }
            unlockWrite(stamp);
        }
Пример #3
0
        public virtual void Put(SimpleBitSet other)
        {
            long stamp = writeLock();

            EnsureCapacity(other._data.Length - 1);
            for (int i = 0; i < _data.Length && i < other._data.Length; i++)
            {
                _data[i] = _data[i] | other._data[i];
            }
            unlockWrite(stamp);
        }
Пример #4
0
            public IntIteratorAnonymousInnerClass(SimpleBitSet outerInstance)
            {
                this.outerInstance = outerInstance;
                size = outerInstance.data.Length * 64;

                // Prefetch first
                while (next < size && !outerInstance.Contains(next))
                {
                    next++;
                }
            }
Пример #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void checkPointOnUnchangedSetMustDoNothing()
        public virtual void CheckPointOnUnchangedSetMustDoNothing()
        {
            SimpleBitSet set = new SimpleBitSet(16);
            int          key = 10;

            set.Put(key);
            long checkpoint = 0;

            checkpoint = set.CheckPointAndPut(checkpoint, key);
            assertThat(set.CheckPointAndPut(checkpoint, key), @is(checkpoint));
            assertTrue(set.Contains(key));
        }
Пример #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void checkPointOnUnchangedSetButWithDifferentKeyMustUpdateSet()
        public virtual void CheckPointOnUnchangedSetButWithDifferentKeyMustUpdateSet()
        {
            SimpleBitSet set = new SimpleBitSet(16);
            int          key = 10;

            set.Put(key);
            long checkpoint = 0;

            checkpoint = set.CheckPointAndPut(checkpoint, key);
            assertThat(set.CheckPointAndPut(checkpoint, key + 1), @is(not(checkpoint)));
            assertTrue(set.Contains(key + 1));
            assertFalse(set.Contains(key));
        }
Пример #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void checkPointMustBeAbleToExpandCapacity()
        public virtual void CheckPointMustBeAbleToExpandCapacity()
        {
            SimpleBitSet set  = new SimpleBitSet(16);
            int          key  = 10;
            int          key2 = 255;

            set.Put(key);
            long checkpoint = 0;

            checkpoint = set.CheckPointAndPut(checkpoint, key);
            assertThat(set.CheckPointAndPut(checkpoint, key2), @is(not(checkpoint)));
            assertTrue(set.Contains(key2));
            assertFalse(set.Contains(key));
        }
Пример #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void checkPointOnChangedSetMustClearState()
        public virtual void CheckPointOnChangedSetMustClearState()
        {
            SimpleBitSet set = new SimpleBitSet(16);
            int          key = 10;

            set.Put(key);
            long checkpoint = 0;

            checkpoint = set.CheckPointAndPut(checkpoint, key);
            set.Put(key + 1);
            assertThat(set.CheckPointAndPut(checkpoint, key), @is(not(checkpoint)));
            assertTrue(set.Contains(key));
            assertFalse(set.Contains(key + 1));
        }
Пример #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void resize()
        public virtual void Resize()
        {
            // Given
            SimpleBitSet set = new SimpleBitSet(8);

            // When
            set.Put(128);

            // Then
            assertTrue(set.Contains(128));

            assertFalse(set.Contains(126));
            assertFalse(set.Contains(129));
        }
Пример #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void putAndRemove()
        public virtual void PutAndRemove()
        {
            // Given
            SimpleBitSet set = new SimpleBitSet(16);

            // When
            set.Put(2);
            set.Put(7);
            set.Remove(2);

            // Then
            assertFalse(set.Contains(1));
            assertFalse(set.Contains(6));
            assertFalse(set.Contains(14));
            assertFalse(set.Contains(2));

            assertTrue(set.Contains(7));
        }
Пример #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowIterating()
        public virtual void ShouldAllowIterating()
        {
            // Given
            SimpleBitSet set = new SimpleBitSet(64);

            set.Put(4);
            set.Put(7);
            set.Put(63);
            set.Put(78);

            // When
            IntIterator    iterator = set.GetEnumerator();
            MutableIntList found    = new IntArrayList();

            while (iterator.hasNext())
            {
                found.add(iterator.next());
            }

            // Then
            assertThat(found, equalTo(IntLists.immutable.of(4, 7, 63, 78)));
        }
Пример #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void modificationsMustTakeWriteLocks()
        public virtual void ModificationsMustTakeWriteLocks()
        {
            // We can observe that a write lock was taken, by seeing that an optimistic read lock was invalidated.
            SimpleBitSet set   = new SimpleBitSet(16);
            long         stamp = set.tryOptimisticRead();

            set.Put(8);
            assertFalse(set.validate(stamp));
            stamp = set.tryOptimisticRead();

            set.Put(8);
            assertFalse(set.validate(stamp));
            stamp = set.tryOptimisticRead();

            SimpleBitSet other = new SimpleBitSet(16);

            other.Put(3);
            set.Put(other);
            assertFalse(set.validate(stamp));
            stamp = set.tryOptimisticRead();

            set.Remove(3);
            assertFalse(set.validate(stamp));
            stamp = set.tryOptimisticRead();

            set.Remove(3);
            assertFalse(set.validate(stamp));
            stamp = set.tryOptimisticRead();

            other.Put(8);
            set.Remove(other);
            assertFalse(set.validate(stamp));
            stamp = set.tryOptimisticRead();

            other.Put(8);
            set.Remove(other);
            assertFalse(set.validate(stamp));
        }