//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldConsiderNodesChangedInSameTxInIndexSeek() public virtual void ShouldConsiderNodesChangedInSameTxInIndexSeek() { // GIVEN CreateNodes(_db, _label, NonMatching[0]); LongSet toChangeToMatch = CreateNodes(_db, _label, NonMatching[1]); LongSet toChangeToNotMatch = CreateNodes(_db, _label, Values); MutableLongSet expected = CreateNodes(_db, _label, Values); // WHEN MutableLongSet found = new LongHashSet(); using (Transaction tx = _db.beginTx()) { LongIterator toMatching = toChangeToMatch.longIterator(); while (toMatching.hasNext()) { long id = toMatching.next(); SetProperties(id, Values); expected.add(id); } LongIterator toNotMatching = toChangeToNotMatch.longIterator(); while (toNotMatching.hasNext()) { long id = toNotMatching.next(); SetProperties(id, NonMatching[2]); expected.remove(id); } CollectNodes(found, IndexSeek.findNodes(Keys, Values, _db)); } // THEN assertThat(found, equalTo(expected)); }
private void VerifyResult(LongSet results) { assertEquals(3, results.size()); assertTrue(results.contains(1)); assertTrue(results.contains(2)); assertTrue(results.contains(3)); }
private Action BuildWriteAction(Action innerAction, LongSet forbiddenRecordIds) { int mappedFilesCount = _mappedFiles.Count; if (mappedFilesCount == 0) { return(innerAction); } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.io.File file = mappedFiles.get(rng.nextInt(mappedFilesCount)); File file = _mappedFiles[_rng.Next(mappedFilesCount)]; _filesTouched.Add(file); int recordId; do { recordId = _rng.Next(_filePageCount * _recordsPerPage); } while (forbiddenRecordIds.contains(recordId)); _recordsWrittenTo[file].Add(recordId); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int pageId = recordId / recordsPerPage; int pageId = recordId / _recordsPerPage; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int pageOffset = (recordId % recordsPerPage) * recordFormat.getRecordSize(); int pageOffset = (recordId % _recordsPerPage) * _recordFormat.RecordSize; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final Record record = recordFormat.createRecord(file, recordId); Record record = _recordFormat.createRecord(file, recordId); return(new WriteAction(this, file, recordId, pageId, pageOffset, record, innerAction)); }
/// <summary> /// Adds a new section to the Sections list. /// /// If the instruction is a branch instruction, unify the new section with an existing section /// that also branches to the same target. /// </summary> void AddSection(LongSet values, ILInstruction inst) { if (values.IsEmpty) { return; } Block targetBlock; if (inst.MatchBranch(out targetBlock)) { int index; if (targetBlockToSectionIndex.TryGetValue(targetBlock, out index)) { Sections[index] = new KeyValuePair <LongSet, ILInstruction>( Sections[index].Key.UnionWith(values), inst ); } else { targetBlockToSectionIndex.Add(targetBlock, Sections.Count); Sections.Add(new KeyValuePair <LongSet, ILInstruction>(values, inst)); } } else { Sections.Add(new KeyValuePair <LongSet, ILInstruction>(values, inst)); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void convertPrimitiveSetToJavaSet() internal virtual void ConvertPrimitiveSetToJavaSet() { LongSet longSet = newSetWith(1L, 3L, 5L); ISet <long> longs = PrimitiveLongCollections.ToSet(longSet); assertThat(longs, containsInAnyOrder(1L, 3L, 5L)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldConsiderNodesChangedInSameTxInIndexSeek() public virtual void ShouldConsiderNodesChangedInSameTxInIndexSeek() { // GIVEN CreateNodes(_db, _label, _nonMatching[0]); LongSet toChangeToMatch = CreateNodes(_db, _label, _nonMatching[1]); MutableLongSet toChangeToNotMatch = CreateNodes(_db, _label, _matching[0]); MutableLongSet expected = CreateNodes(_db, _label, _matching[1]); // WHEN MutableLongSet found = new LongHashSet(); using (Transaction tx = _db.beginTx()) { LongIterator toMatching = toChangeToMatch.longIterator(); while (toMatching.hasNext()) { long id = toMatching.next(); _db.getNodeById(id).setProperty(_key, _matching[2]); expected.add(id); } LongIterator toNotMatching = toChangeToNotMatch.longIterator(); while (toNotMatching.hasNext()) { long id = toNotMatching.next(); _db.getNodeById(id).setProperty(_key, _nonMatching[2]); expected.remove(id); } CollectNodes(found, _db.findNodes(_label, _key, _template, _searchMode)); } // THEN assertThat(found, equalTo(expected)); }
private PrepareStoreCopyResponse(File[] files, LongSet indexIds, long?transactionId, Status status) { this._files = files; this._indexIds = indexIds; this._transactionId = transactionId; this._status = status; }
private static LongIterator PrimitiveIdsByType(IntObjectMap <MutableLongSet> map, int type) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.eclipse.collections.api.set.primitive.LongSet relationships = map.get(type); LongSet relationships = map.get(type); return(relationships == null ? ImmutableEmptyLongIterator.INSTANCE : relationships.freeze().longIterator()); }
/// <summary> /// Analyzes the boolean condition, returning the set of values of the interesting /// variable for which the condition evaluates to true. /// </summary> private bool AnalyzeCondition(ILInstruction condition, out LongSet trueValues) { if (condition is Comp comp && MatchSwitchVar(comp.Left) && comp.Right.MatchLdcI(out long val)) { // if (comp(V OP val)) trueValues = MakeSetWhereComparisonIsTrue(comp.Kind, val, comp.Sign); return(true); }
public void UnionUniverse() { Assert.AreEqual(LongSet.Universe, LongSet.Universe.UnionWith(LongSet.Universe)); Assert.AreEqual(LongSet.Universe, LongSet.Universe.UnionWith(LongSet.Empty)); Assert.AreEqual(LongSet.Universe, LongSet.Universe.UnionWith(new LongSet(long.MaxValue))); var longSet = new LongSet(new[] { new LongInterval(1, 5), new LongInterval(6, 7) }.ToImmutableArray()); Assert.AreEqual(LongSet.Universe, longSet.UnionWith(LongSet.Universe)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: private DiffApplyingPrimitiveLongIterator(org.eclipse.collections.api.iterator.LongIterator source, org.eclipse.collections.api.set.primitive.LongSet addedElements, org.eclipse.collections.api.set.primitive.LongSet removedElements, @Nullable Resource resource) private DiffApplyingPrimitiveLongIterator(LongIterator source, LongSet addedElements, LongSet removedElements, Resource resource) { this._source = source; this._addedElements = addedElements.freeze(); this._addedElementsIterator = this._addedElements.longIterator(); this._removedElements = removedElements; this._resource = resource; this._phase = Phase.FilteredSource; }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReturnEmptySetOfIdsAndIgnoreIndexListing() public virtual void ShouldReturnEmptySetOfIdsAndIgnoreIndexListing() { LongSet expectedIndexIds = LongSets.immutable.of(42); when(_indexListingMock.IndexIds).thenReturn(expectedIndexIds); LongSet actualIndexIndexIds = _prepareStoreCopyFiles.NonAtomicIndexIds; assertTrue(actualIndexIndexIds.Empty); }
private void SeekQuery(IndexDescriptor descriptor, IndexQuery[] query) { IndexQuery.ExactPredicate[] exactPreds = AssertOnlyExactPredicates(query); TransactionState txState = _read.txState(); AddedAndRemoved changes = indexUpdatesForSeek(txState, descriptor, IndexQuery.asValueTuple(exactPreds)); _added = changes.Added.longIterator(); _removed = _removed(txState, changes.Removed); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: protected org.neo4j.kernel.api.ExplicitIndexHits query(org.apache.lucene.search.Query query, String keyForDirectLookup, Object valueForDirectLookup, org.neo4j.index.lucene.QueryContext additionalParametersOrNull) throws org.neo4j.internal.kernel.api.exceptions.explicitindex.ExplicitIndexNotFoundKernelException protected internal virtual ExplicitIndexHits Query(Query query, string keyForDirectLookup, object valueForDirectLookup, QueryContext additionalParametersOrNull) { IList <EntityId> simpleTransactionStateIds = new List <EntityId>(); ICollection <EntityId> removedIdsFromTransactionState = Collections.emptySet(); IndexSearcher fulltextTransactionStateSearcher = null; if (Transaction != null) { if (!string.ReferenceEquals(keyForDirectLookup, null)) { ((IList <EntityId>)simpleTransactionStateIds).AddRange(Transaction.getAddedIds(this, keyForDirectLookup, valueForDirectLookup)); } else { fulltextTransactionStateSearcher = Transaction.getAdditionsAsSearcher(this, additionalParametersOrNull); } removedIdsFromTransactionState = !string.ReferenceEquals(keyForDirectLookup, null) ? Transaction.getRemovedIds(this, keyForDirectLookup, valueForDirectLookup) : Transaction.getRemovedIds(this, query); } ExplicitIndexHits idIterator = null; IndexReference searcher; DataSource.ReadLock; try { searcher = DataSource.getIndexSearcher(IdentifierConflict); } finally { DataSource.releaseReadLock(); } if (searcher != null) { try { // Gather all added ids from fulltextTransactionStateSearcher and simpleTransactionStateIds. //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.eclipse.collections.api.set.primitive.LongSet idsModifiedInTransactionState = gatherIdsModifiedInTransactionState(simpleTransactionStateIds, fulltextTransactionStateSearcher, query); LongSet idsModifiedInTransactionState = GatherIdsModifiedInTransactionState(simpleTransactionStateIds, fulltextTransactionStateSearcher, query); // Do the combined search from store and fulltext tx state DocToIdIterator hits = new DocToIdIterator(Search(searcher, fulltextTransactionStateSearcher, query, additionalParametersOrNull, removedIdsFromTransactionState), removedIdsFromTransactionState, searcher, idsModifiedInTransactionState); idIterator = simpleTransactionStateIds.Count == 0 ? hits : new CombinedIndexHits(Arrays.asList(hits, new ConstantScoreIterator(simpleTransactionStateIds, Float.NaN))); } catch (IOException e) { throw new Exception("Unable to query " + this + " with " + query, e); } } // We've only got transaction state idIterator = idIterator == null ? new ConstantScoreIterator(simpleTransactionStateIds, 0) : idIterator; return(idIterator); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void appendSourceElementsDuringIteration() public virtual void AppendSourceElementsDuringIteration() { LongIterator source = iterator(4L, 5L); LongSet added = LongHashSet.newSetWith(1L, 2L); LongSet removed = LongHashSet.newSetWith(3L); LongIterator iterator = DiffApplyingPrimitiveLongIterator.Augment(source, added, removed); ISet <long> resultSet = toSet(iterator); assertThat(resultSet, containsInAnyOrder(1L, 2L, 4L, 5L)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void iterateOnlyOverAddedElementsWhenSourceIsEmpty() public virtual void IterateOnlyOverAddedElementsWhenSourceIsEmpty() { LongIterator emptySource = ImmutableEmptyLongIterator.INSTANCE; LongSet added = LongHashSet.newSetWith(1L, 2L); LongSet removed = LongHashSet.newSetWith(3L); LongIterator iterator = DiffApplyingPrimitiveLongIterator.Augment(emptySource, added, removed); ISet <long> resultSet = toSet(iterator); assertThat(resultSet, containsInAnyOrder(1L, 2L)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void marshalIndexIds(org.neo4j.storageengine.api.WritableChannel buffer, org.eclipse.collections.api.set.primitive.LongSet indexIds) throws java.io.IOException internal virtual void MarshalIndexIds(WritableChannel buffer, LongSet indexIds) { buffer.PutInt(indexIds.size()); LongIterator itr = indexIds.longIterator(); while (itr.hasNext()) { long indexId = itr.next(); buffer.PutLong(indexId); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: protected PrepareStoreCopyResponse unmarshal0(org.neo4j.storageengine.api.ReadableChannel channel) throws java.io.IOException protected internal override PrepareStoreCopyResponse Unmarshal0(ReadableChannel channel) { int ordinal = channel.Int; Status status = Enum.GetValues(typeof(Status))[ordinal]; long? transactionId = channel.Long; File[] files = UnmarshalFiles(channel); LongSet indexIds = UnmarshalIndexIds(channel); return(new PrepareStoreCopyResponse(files, indexIds, transactionId, status)); }
public DocToIdIterator(IndexHits <Document> source, ICollection <EntityId> exclude, IndexReference searcherOrNull, LongSet idsModifiedInTransactionState) { this._source = source; this._removedInTransactionState = exclude; this._searcherOrNull = searcherOrNull; this._idsModifiedInTransactionState = idsModifiedInTransactionState; if (source.Size() == 0) { Close(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void doNotIterateOverDeletedElement() public virtual void DoNotIterateOverDeletedElement() { LongIterator source = iterator(3L, 5L); LongSet added = LongHashSet.newSetWith(1L); LongSet removed = LongHashSet.newSetWith(3L); LongIterator iterator = DiffApplyingPrimitiveLongIterator.Augment(source, added, removed); ISet <long> resultSet = toSet(iterator); assertThat(resultSet, containsInAnyOrder(1L, 5L)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void convertJavaCollectionToSetOfPrimitives() internal virtual void ConvertJavaCollectionToSetOfPrimitives() { IList <long> longs = new IList <long> { 1L, 4L, 7L }; LongSet longSet = PrimitiveLongCollections.AsSet(longs); assertTrue(longSet.contains(1L)); assertTrue(longSet.contains(4L)); assertTrue(longSet.contains(7L)); assertEquals(3, longSet.size()); }
internal override void CheckInvariant(ILPhase phase) { base.CheckInvariant(phase); LongSet sets = LongSet.Empty; foreach (var section in Sections) { Debug.Assert(!section.Labels.IsEmpty); Debug.Assert(!section.Labels.Overlaps(sets)); sets = sets.UnionWith(section.Labels); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void doNotIterateTwiceOverSameElementsWhenItsPartOfSourceAndAdded() public virtual void DoNotIterateTwiceOverSameElementsWhenItsPartOfSourceAndAdded() { LongIterator source = iterator(4L, 5L); LongSet added = LongHashSet.newSetWith(1L, 4L); LongSet removed = LongHashSet.newSetWith(3L); LongIterator iterator = DiffApplyingPrimitiveLongIterator.Augment(source, added, removed); long?[] values = ArrayUtils.toObject(asArray(iterator)); assertThat(values, arrayContainingInAnyOrder(1L, 4L, 5L)); assertThat(values, arrayWithSize(3)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void rangeSeekByPrefixOverPartitions() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void RangeSeekByPrefixOverPartitions() { PartitionedIndexReader indexReader = CreatePartitionedReaderFromReaders(); IndexQuery.StringPrefixPredicate query = IndexQuery.stringPrefix(1, stringValue("prefix")); when(_indexReader1.query(query)).thenReturn(PrimitiveLongResourceCollections.iterator(null, 1)); when(_indexReader2.query(query)).thenReturn(PrimitiveLongResourceCollections.iterator(null, 2)); when(_indexReader3.query(query)).thenReturn(PrimitiveLongResourceCollections.iterator(null, 3)); LongSet results = PrimitiveLongCollections.asSet(indexReader.Query(query)); VerifyResult(results); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void scanOverPartitions() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ScanOverPartitions() { PartitionedIndexReader indexReader = CreatePartitionedReaderFromReaders(); IndexQuery.ExistsPredicate query = IndexQuery.exists(1); when(_indexReader1.query(query)).thenReturn(PrimitiveLongResourceCollections.iterator(null, 1)); when(_indexReader2.query(query)).thenReturn(PrimitiveLongResourceCollections.iterator(null, 2)); when(_indexReader3.query(query)).thenReturn(PrimitiveLongResourceCollections.iterator(null, 3)); LongSet results = PrimitiveLongCollections.asSet(indexReader.Query(query)); VerifyResult(results); }
/// <summary> /// Analyzes the tail end (last two instructions) of a block. /// </summary> /// <remarks> /// Sets <c>switchVar</c> and <c>defaultInstruction</c> if they are null, /// and adds found sections to <c>sectionLabels</c> and <c>sectionInstructions</c>. /// /// If the function returns false, <c>sectionLabels</c> and <c>sectionInstructions</c> are unmodified. /// </remarks> /// <param name="block">The block to analyze.</param> /// <param name="inputValues">The possible values of the "interesting" variable /// when control flow reaches this block.</param> /// <param name="tailOnly">If true, analyze only the tail (last two instructions). /// If false, analyze the whole block.</param> bool AnalyzeBlock(Block block, LongSet inputValues, bool tailOnly = false) { if (block.Instructions.Count == 0) { // might happen if the block was already marked for deletion in SwitchDetection return(false); } if (tailOnly) { Debug.Assert(block == RootBlock); } else { Debug.Assert(switchVar != null); // switchVar should always be determined by the top-level call if (block.IncomingEdgeCount != 1 || block == RootBlock) { return(false); // for now, let's only consider if-structures that form a tree } if (block.Parent != RootBlock.Parent) { return(false); // all blocks should belong to the same container } } LongSet trueValues; if (block.Instructions.Count >= 2 && block.Instructions[block.Instructions.Count - 2].MatchIfInstruction(out var condition, out var trueInst) && AnalyzeCondition(condition, out trueValues) ) { if (!(tailOnly || block.Instructions.Count == 2)) { return(false); } trueValues = trueValues.IntersectWith(inputValues); if (trueValues.SetEquals(inputValues) || trueValues.IsEmpty) { return(false); } Block trueBlock; if (trueInst.MatchBranch(out trueBlock) && AnalyzeBlock(trueBlock, trueValues)) { // OK, true block was further analyzed. InnerBlocks.Add(trueBlock); } else { // Create switch section for trueInst. AddSection(trueValues, trueInst); } }
public void UpperBound() { var longSet = new LongSet(new[] { new LongInterval(1, 5), new LongInterval(6, 7) }.ToImmutableArray()); Assert.AreEqual(0, longSet.upper_bound(0)); for (int i = 1; i <= 5; i++) { Assert.AreEqual(1, longSet.upper_bound(i)); } for (int i = 6; i <= 10; i++) { Assert.AreEqual(2, longSet.upper_bound(i)); } }
protected internal override void channelRead0(ChannelHandlerContext channelHandlerContext, PrepareStoreCopyRequest prepareStoreCopyRequest) { channelHandlerContext.writeAndFlush(ResponseMessageType.PREPARE_STORE_COPY_RESPONSE); //JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter: IList <File> list = _outerInstance.filesystem.Select(FakeFile::getFile).ToList(); File[] files = new File[list.Count]; files = list.toArray(files); long transactionId = 123L; LongSet indexIds = LongSets.immutable.of(13); channelHandlerContext.writeAndFlush(PrepareStoreCopyResponse.Success(files, indexIds, transactionId)); _catchupServerProtocol.expect(CatchupServerProtocol.State.MESSAGE_TYPE); }
private bool AnalyzeSwitch(SwitchInstruction inst, LongSet inputValues, out LongSet anyMatchValues) { Debug.Assert(inst.DefaultBody is Nop); anyMatchValues = LongSet.Empty; long offset; if (MatchSwitchVar(inst.Value)) { offset = 0; } else if (inst.Value is BinaryNumericInstruction bop) { if (bop.CheckForOverflow) { return(false); } if (MatchSwitchVar(bop.Left) && bop.Right.MatchLdcI(out long val)) { switch (bop.Operator) { case BinaryNumericOperator.Add: offset = unchecked (-val); break; case BinaryNumericOperator.Sub: offset = val; break; default: // unknown bop.Operator return(false); } } else // unknown bop.Left { return(false); } } else // unknown inst.Value { return(false); } foreach (var section in inst.Sections) { var matchValues = section.Labels.AddOffset(offset).IntersectWith(inputValues); AddSection(matchValues, section.Body); anyMatchValues = anyMatchValues.UnionWith(matchValues); } return(true); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void rangeSeekByStringOverPartitions() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void RangeSeekByStringOverPartitions() { PartitionedIndexReader indexReader = CreatePartitionedReaderFromReaders(); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: org.neo4j.internal.kernel.api.IndexQuery.RangePredicate<?> query = org.neo4j.internal.kernel.api.IndexQuery.range(1, "a", false, "b", true); IndexQuery.RangePredicate <object> query = IndexQuery.range(1, "a", false, "b", true); when(_indexReader1.query(query)).thenReturn(PrimitiveLongResourceCollections.iterator(null, 1)); when(_indexReader2.query(query)).thenReturn(PrimitiveLongResourceCollections.iterator(null, 2)); when(_indexReader3.query(query)).thenReturn(PrimitiveLongResourceCollections.iterator(null, 3)); LongSet results = PrimitiveLongCollections.asSet(indexReader.Query(query)); VerifyResult(results); }