Ejemplo n.º 1
0
 private FastIDSet(FastIDSet copyFrom)
 {
     keys         = copyFrom.keys;
     loadFactor   = copyFrom.loadFactor;
     numEntries   = copyFrom.numEntries;
     numSlotsUsed = copyFrom.numSlotsUsed;
 }
Ejemplo n.º 2
0
        public void testVersusHashSet()
        {
            FastIDSet actual   = new FastIDSet(1);
            var       expected = new HashSet <int>(); //1000000
            var       r        = RandomUtils.getRandom();

            for (int i = 0; i < 1000000; i++)
            {
                double d   = r.nextDouble();
                var    key = r.nextInt(100);
                if (d < 0.4)
                {
                    Assert.AreEqual(expected.Contains(key), actual.Contains(key));
                }
                else
                {
                    if (d < 0.7)
                    {
                        Assert.AreEqual(expected.Add(key), actual.Add(key));
                    }
                    else
                    {
                        Assert.AreEqual(expected.Remove(key), actual.Remove(key));
                    }
                    Assert.AreEqual(expected.Count, actual.Count());
                    Assert.AreEqual(expected.Count == 0, actual.IsEmpty());
                }
            }
        }
Ejemplo n.º 3
0
        public void testContainsAndAdd()
        {
            FastIDSet set = new FastIDSet();

            Assert.False(set.Contains(1));
            set.Add(1);
            Assert.True(set.Contains(1));
        }
Ejemplo n.º 4
0
        public void testRehash()
        {
            FastIDSet set = buildTestFastSet();

            set.Remove(1);
            set.Rehash();
            Assert.False(set.Contains(1));
        }
Ejemplo n.º 5
0
        public void testContains()
        {
            FastIDSet set = buildTestFastSet();

            Assert.True(set.Contains(1));
            Assert.True(set.Contains(2));
            Assert.True(set.Contains(3));
            Assert.False(set.Contains(4));
        }
Ejemplo n.º 6
0
        private static FastIDSet buildTestFastSet()
        {
            FastIDSet set = new FastIDSet();

            set.Add(1);
            set.Add(2);
            set.Add(3);
            return(set);
        }
Ejemplo n.º 7
0
        public void testGrow()
        {
            FastIDSet set = new FastIDSet(1);

            set.Add(1);
            set.Add(2);
            Assert.True(set.Contains(1));
            Assert.True(set.Contains(2));
        }
Ejemplo n.º 8
0
        public void testClear()
        {
            FastIDSet set = new FastIDSet();

            set.Add(1);
            set.Clear();
            Assert.AreEqual(0, set.Count());
            Assert.True(set.IsEmpty());
            Assert.False(set.Contains(1));
        }
Ejemplo n.º 9
0
        public override bool Equals(Object other)
        {
            if (!(other is FastIDSet))
            {
                return(false);
            }
            FastIDSet otherMap = (FastIDSet)other;

            long[] otherKeys   = otherMap.keys;
            int    length      = keys.Length;
            int    otherLength = otherKeys.Length;
            int    max         = Math.Min(length, otherLength);

            int i = 0;

            while (i < max)
            {
                long key      = keys[i];
                long otherKey = otherKeys[i];
                if (key == NULL || key == REMOVED)
                {
                    if (otherKey != NULL && otherKey != REMOVED)
                    {
                        return(false);
                    }
                }
                else
                {
                    if (key != otherKey)
                    {
                        return(false);
                    }
                }
                i++;
            }
            while (i < length)
            {
                long key = keys[i];
                if (key != NULL && key != REMOVED)
                {
                    return(false);
                }
                i++;
            }
            while (i < otherLength)
            {
                long key = otherKeys[i];
                if (key != NULL && key != REMOVED)
                {
                    return(false);
                }
                i++;
            }
            return(true);
        }
Ejemplo n.º 10
0
        public void testSizeEmpty()
        {
            FastIDSet set = new FastIDSet();

            Assert.AreEqual(0, set.Count());
            Assert.True(set.IsEmpty());
            set.Add(1);
            Assert.AreEqual(1, set.Count());
            Assert.False(set.IsEmpty());
            set.Remove(1);
            Assert.AreEqual(0, set.Count());
            Assert.True(set.IsEmpty());
        }
Ejemplo n.º 11
0
        /// Convenience method to quickly compute just the size of the intersection with another {@link FastIDSet}.
        ///
        /// @param other
        ///          {@link FastIDSet} to intersect with
        /// @return number of elements in intersection
        public int IntersectionSize(FastIDSet other)
        {
            int count = 0;

            foreach (long key in other.keys)
            {
                if (key != NULL && key != REMOVED && keys[find(key)] != NULL)
                {
                    count++;
                }
            }
            return(count);
        }
Ejemplo n.º 12
0
        public bool RemoveAll(FastIDSet c)
        {
            bool changed = false;

            foreach (long k in c.keys)
            {
                if (k != NULL && k != REMOVED && Remove(k))
                {
                    changed = true;
                }
            }
            return(changed);
        }
Ejemplo n.º 13
0
        public void testIterator()
        {
            FastIDSet set      = buildTestFastSet();
            var       expected = new List <long>(3);

            expected.Add(1L);
            expected.Add(2L);
            expected.Add(3L);
            var it = set.GetEnumerator();

            while (it.MoveNext())
            {
                expected.Remove(it.Current);
            }
            Assert.True(expected.Count == 0);
        }
Ejemplo n.º 14
0
        public bool RetainAll(FastIDSet c)
        {
            bool changed = false;

            for (int i = 0; i < keys.Length; i++)
            {
                long k = keys[i];
                if (k != NULL && k != REMOVED && !c.Contains(k))
                {
                    keys[i] = REMOVED;
                    numEntries--;
                    changed = true;
                }
            }
            return(changed);
        }
Ejemplo n.º 15
0
        public void testReservedValues()
        {
            FastIDSet set = new FastIDSet();

            try {
                set.Add(Int64.MinValue);
                Assert.Fail("Should have thrown IllegalArgumentException");
            } catch (ArgumentException iae) { //IllegalArgumentException
                // good
            }
            Assert.False(set.Contains(Int64.MinValue));
            try {
                set.Add(long.MaxValue);
                Assert.Fail("Should have thrown IllegalArgumentException");
            } catch (ArgumentException iae) {
                // good
            }
            Assert.False(set.Contains(long.MaxValue));
        }