Beispiel #1
0
        public long GetLongHashCode([DisallowNull] LongHashSet <T> obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            long hashCode = 0; // default to 0 for empty set

            var comparer = LongEqualityComparer <T> .Default;

            foreach (T t in obj)
            {
                if (t != null)
                {
                    hashCode ^= comparer.GetLongHashCode(t); // same hashcode as as default comparer
                }
            }

            return(hashCode);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void keysIterator()
        internal virtual void KeysIterator()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.eclipse.collections.api.set.primitive.LongSet keys = org.eclipse.collections.impl.factory.primitive.LongSets.immutable.of(0L, 1L, 2L, 42L);
            LongSet keys = LongSets.immutable.of(0L, 1L, 2L, 42L);

            keys.forEach(k => _map.put(k, k * 10));

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.eclipse.collections.api.iterator.MutableLongIterator iter = map.longIterator();
            MutableLongIterator iter = _map.longIterator();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.eclipse.collections.api.set.primitive.MutableLongSet found = new org.eclipse.collections.impl.set.mutable.primitive.LongHashSet();
            MutableLongSet found = new LongHashSet();

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

            assertEquals(keys, found);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotIncludeNodesDeletedInSameTxInIndexSeek()
        public virtual void ShouldNotIncludeNodesDeletedInSameTxInIndexSeek()
        {
            // GIVEN
            CreateNodes(_db, _label, _nonMatching[0]);
            LongSet        toDelete = CreateNodes(_db, _label, _matching[0], _nonMatching[1], _matching[1], _nonMatching[2]);
            MutableLongSet expected = CreateNodes(_db, _label, _matching[2]);
            // WHEN
            MutableLongSet found = new LongHashSet();

            using (Transaction tx = _db.beginTx())
            {
                LongIterator deleting = toDelete.longIterator();
                while (deleting.hasNext())
                {
                    long id = deleting.next();
                    _db.getNodeById(id).delete();
                    expected.remove(id);
                }

                CollectNodes(found, _db.findNodes(_label, _key, _template, _searchMode));
            }
            // THEN
            assertThat(found, equalTo(expected));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSupportIndexSeekBackwardsOrder()
        public virtual void ShouldSupportIndexSeekBackwardsOrder()
        {
            // GIVEN
            CreateNodes(_db, _label, NonMatching);
            LongSet expected = CreateNodes(_db, _label, Values);

            // WHEN
            MutableLongSet found = new LongHashSet();

            string[] reversedKeys   = new string[Keys.Length];
            object[] reversedValues = new object[Keys.Length];
            for (int i = 0; i < Keys.Length; i++)
            {
                reversedValues[Keys.Length - 1 - i] = Values[i];
                reversedKeys[Keys.Length - 1 - i]   = Keys[i];
            }
            using (Transaction tx = _db.beginTx())
            {
                CollectNodes(found, IndexSeek.findNodes(reversedKeys, reversedValues, _db));
            }

            // THEN
            assertThat(found, equalTo(expected));
        }
 internal Enumerator(LongHashSet <T> hashSet)
 {
     _hashSet = hashSet;
     _version = hashSet._version;
     _index   = 0;
     _current = default !;
        public bool Equals(LongHashSet <T>?x, LongHashSet <T>?y)
        {
            // If they're the exact same instance, they're equal.
            if (ReferenceEquals(x, y))
            {
                return(true);
            }

            // They're not both null, so if either is null, they're not equal.
            if (x == null || y == null)
            {
                return(false);
            }

            // If both sets use the same comparer, they're equal if they're the same
            // size and one is a "subset" of the other.
            if (LongHashSet <T> .EqualityComparersAreEqual(x, y))
            {
                return(x.Count == y.Count && y.IsSubsetOfHashSetWithSameComparer(x));
            }

            // Otherwise, do an O(N^2) match.
            if (typeof(T).IsValueType)
            {
                foreach (T yi in y)
                {
                    bool found = false;
                    foreach (T xi in x)
                    {
                        if (LongEqualityComparer <T> .Default.Equals(yi, xi))
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        return(false);
                    }
                }
            }
            else
            {
                var defaultComparer = LongEqualityComparer <T> .Default;
                foreach (T yi in y)
                {
                    bool found = false;
                    foreach (T xi in x)
                    {
                        if (defaultComparer.Equals(yi, xi))
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void awaitIndexesOnlineMustWorkOnFulltextIndexes()
        public virtual void AwaitIndexesOnlineMustWorkOnFulltextIndexes()
        {
            string           prop1    = "prop1";
            string           prop2    = "prop2";
            string           prop3    = "prop3";
            string           val1     = "foo foo";
            string           val2     = "bar bar";
            string           val3     = "baz baz";
            Label            label1   = Label.label("FirstLabel");
            Label            label2   = Label.label("SecondLabel");
            Label            label3   = Label.label("ThirdLabel");
            RelationshipType relType1 = RelationshipType.withName("FirstRelType");
            RelationshipType relType2 = RelationshipType.withName("SecondRelType");
            RelationshipType relType3 = RelationshipType.withName("ThirdRelType");

            LongHashSet nodes1 = new LongHashSet();
            LongHashSet nodes2 = new LongHashSet();
            LongHashSet nodes3 = new LongHashSet();
            LongHashSet rels1  = new LongHashSet();
            LongHashSet rels2  = new LongHashSet();
            LongHashSet rels3  = new LongHashSet();

            using (Transaction tx = Db.beginTx())
            {
                for (int i = 0; i < 100; i++)
                {
                    Node node1 = Db.createNode(label1);
                    node1.SetProperty(prop1, val1);
                    nodes1.add(node1.Id);
                    Relationship rel1 = node1.CreateRelationshipTo(node1, relType1);
                    rel1.SetProperty(prop1, val1);
                    rels1.add(rel1.Id);

                    Node node2 = Db.createNode(label2);
                    node2.SetProperty(prop2, val2);
                    nodes2.add(node2.Id);
                    Relationship rel2 = node1.CreateRelationshipTo(node2, relType2);
                    rel2.SetProperty(prop2, val2);
                    rels2.add(rel2.Id);

                    Node node3 = Db.createNode(label3);
                    node3.SetProperty(prop3, val3);
                    nodes3.add(node3.Id);
                    Relationship rel3 = node1.CreateRelationshipTo(node3, relType3);
                    rel3.SetProperty(prop3, val3);
                    rels3.add(rel3.Id);
                }
                tx.Success();
            }

            // Test that multi-token node indexes can be waited for.
            using (Transaction tx = Db.beginTx())
            {
                Db.execute(format(NODE_CREATE, "nodeIndex", array(label1.Name(), label2.Name(), label3.Name()), array(prop1, prop2, prop3))).close();
                tx.Success();
            }

            using (Transaction tx = Db.beginTx())
            {
                Db.schema().awaitIndexesOnline(10, TimeUnit.SECONDS);
                tx.Success();
            }

            using (Transaction tx = Db.beginTx())
            {
                assertQueryFindsIds(Db, true, "nodeIndex", "foo", nodes1);
                assertQueryFindsIds(Db, true, "nodeIndex", "bar", nodes2);
                assertQueryFindsIds(Db, true, "nodeIndex", "baz", nodes3);
                tx.Success();
            }

            // Test that multi-token relationship indexes can be waited for.
            using (Transaction tx = Db.beginTx())
            {
                Db.execute(format(RELATIONSHIP_CREATE, "relIndex", array(relType1.Name(), relType2.Name(), relType3.Name()), array(prop1, prop2, prop3))).close();
                tx.Success();
            }

            using (Transaction tx = Db.beginTx())
            {
                Db.schema().awaitIndexesOnline(10, TimeUnit.SECONDS);
                tx.Success();
            }

            using (Transaction tx = Db.beginTx())
            {
                assertQueryFindsIds(Db, false, "relIndex", "foo", rels1);
                assertQueryFindsIds(Db, false, "relIndex", "bar", rels2);
                assertQueryFindsIds(Db, false, "relIndex", "baz", rels3);
                tx.Success();
            }
        }
Beispiel #8
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: public static org.eclipse.collections.api.set.primitive.MutableLongSet labels(final long... labels)
        public static MutableLongSet Labels(params long[] labels)
        {
            return(LongHashSet.newSetWith(labels));
        }