Package org.neo4j.gds.core.huge
Class NodeFilteredGraph
- java.lang.Object
-
- org.neo4j.gds.api.GraphAdapter
-
- org.neo4j.gds.api.CSRGraphAdapter
-
- org.neo4j.gds.core.huge.NodeFilteredGraph
-
- All Implemented Interfaces:
BatchNodeIterable,CSRGraph,Degrees,FilteredIdMap,Graph,IdMap,NodeIterator,PartialIdMap,NodePropertyContainer,RelationshipIterator,RelationshipPredicate,RelationshipProperties
public class NodeFilteredGraph extends CSRGraphAdapter implements FilteredIdMap
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.neo4j.gds.api.BatchNodeIterable
BatchNodeIterable.BitSetIdIterator, BatchNodeIterable.IdIterable, BatchNodeIterable.IdIterator
-
Nested classes/interfaces inherited from interface org.neo4j.gds.api.IdMap
IdMap.NodeLabelConsumer
-
-
Field Summary
-
Fields inherited from class org.neo4j.gds.api.CSRGraphAdapter
csrGraph
-
Fields inherited from class org.neo4j.gds.api.GraphAdapter
graph
-
Fields inherited from interface org.neo4j.gds.api.IdMap
NOT_FOUND, START_NODE_ID
-
-
Constructor Summary
Constructors Constructor Description NodeFilteredGraph(CSRGraph originalGraph, FilteredIdMap filteredIdMap)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Optional<NodeFilteredGraph>asNodeFilteredGraph()If this graph is created using a node label filter, this will return a NodeFilteredGraph that represents the node set used in this graph.java.util.Set<org.neo4j.gds.NodeLabel>availableNodeLabels()java.util.Collection<PrimitiveLongIterable>batchIterables(long batchSize)CSRGraphconcurrentCopy()booleancontains(long originalNodeId)Returns true iff the neo4jNodeId is mapped, otherwise false.booleancontainsRootNodeId(long rootNodeId)Checks if the rootNodeId (mappedNodeId) is present in the IdMaps mapping information.intdegree(long nodeId)intdegreeWithoutParallelRelationships(long nodeId)Much slower than just degree() because it may have to look up all relationships.booleanexists(long sourceNodeId, long targetNodeId)voidforEachNode(java.util.function.LongPredicate consumer)Iterate over each nodeIdvoidforEachNodeLabel(long mappedNodeId, IdMap.NodeLabelConsumer consumer)voidforEachRelationship(long nodeId, double fallbackValue, RelationshipWithPropertyConsumer consumer)Calls the given consumer function for every relationship of a given node.voidforEachRelationship(long nodeId, RelationshipConsumer consumer)Calls the given consumer function for every relationship of a given node.longgetFilteredMappedNodeId(long nodeId)booleanhasLabel(long mappedNodeId, org.neo4j.gds.NodeLabel label)longhighestNeoId()longnodeCount()Number of mapped nodeIds.java.util.PrimitiveIterator.OfLongnodeIterator()java.util.PrimitiveIterator.OfLongnodeIterator(java.util.Set<org.neo4j.gds.NodeLabel> labels)java.util.List<org.neo4j.gds.NodeLabel>nodeLabels(long mappedNodeId)NodePropertyValuesnodeProperties(java.lang.String propertyKey)Return the property values for a property key NOTE: Avoid using this on the hot path, favor caching the NodeProperties object when possiblelongnthTarget(long nodeId, int offset)Get the n-th target node id for a givensourceNodeId.longrelationshipCount()doublerelationshipProperty(long sourceNodeId, long targetNodeId)Returns the property value for a relationship defined by its source and target nodes.doublerelationshipProperty(long sourceNodeId, long targetNodeId, double fallbackValue)get value of property on relationship between source and target node idvoidrelease()Release all resources which are not part of the result or IdMapjava.util.OptionalLongrootNodeCount()Number of mapped node ids in the root mapping.longrootToMappedNodeId(long rootNodeId)Maps a root mapped node id to a filtered mapped node id.org.neo4j.gds.api.schema.GraphSchemaschema()java.util.stream.Stream<RelationshipCursor>streamRelationships(long nodeId, double fallbackValue)longtoMappedNodeId(long originalNodeId)Maps an original node id to a mapped node id.longtoOriginalNodeId(long mappedNodeId)Map mapped nodeId back to neo4j nodeIdlongtoRootNodeId(long mappedNodeId)Maps a filtered mapped node id to its root mapped node id.java.util.Optional<? extends FilteredIdMap>withFilteredLabels(java.util.Collection<org.neo4j.gds.NodeLabel> nodeLabels, int concurrency)-
Methods inherited from class org.neo4j.gds.api.CSRGraphAdapter
relationshipTopologies
-
Methods inherited from class org.neo4j.gds.api.GraphAdapter
availableNodeProperties, canRelease, graph, hasRelationshipProperty, isMultiGraph, relationshipTypeFilteredGraph, releaseProperties, releaseTopology, rootIdMap
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.neo4j.gds.api.Graph
canRelease, hasRelationshipProperty, isEmpty, isMultiGraph, relationshipTypeFilteredGraph, releaseProperties, releaseTopology
-
Methods inherited from interface org.neo4j.gds.api.IdMap
rootIdMap, safeToMappedNodeId
-
Methods inherited from interface org.neo4j.gds.api.properties.nodes.NodePropertyContainer
availableNodeProperties
-
-
-
-
Constructor Detail
-
NodeFilteredGraph
public NodeFilteredGraph(CSRGraph originalGraph, FilteredIdMap filteredIdMap)
-
-
Method Detail
-
schema
public org.neo4j.gds.api.schema.GraphSchema schema()
- Specified by:
schemain interfaceGraph- Overrides:
schemain classGraphAdapter
-
nodeIterator
public java.util.PrimitiveIterator.OfLong nodeIterator()
- Specified by:
nodeIteratorin interfaceNodeIterator- Overrides:
nodeIteratorin classGraphAdapter
-
nodeIterator
public java.util.PrimitiveIterator.OfLong nodeIterator(java.util.Set<org.neo4j.gds.NodeLabel> labels)
- Specified by:
nodeIteratorin interfaceNodeIterator- Overrides:
nodeIteratorin classGraphAdapter
-
batchIterables
public java.util.Collection<PrimitiveLongIterable> batchIterables(long batchSize)
- Specified by:
batchIterablesin interfaceBatchNodeIterable- Overrides:
batchIterablesin classGraphAdapter- Returns:
- a collection of iterables over every node, partitioned by the given batch size.
-
forEachNode
public void forEachNode(java.util.function.LongPredicate consumer)
Description copied from interface:NodeIteratorIterate over each nodeId- Specified by:
forEachNodein interfaceNodeIterator- Overrides:
forEachNodein classGraphAdapter
-
degree
public int degree(long nodeId)
- Specified by:
degreein interfaceDegrees- Overrides:
degreein classGraphAdapter
-
degreeWithoutParallelRelationships
public int degreeWithoutParallelRelationships(long nodeId)
Description copied from interface:DegreesMuch slower than just degree() because it may have to look up all relationships. This is not thread-safe, so if this is called concurrently please useRelationshipIterator.concurrentCopy().- Specified by:
degreeWithoutParallelRelationshipsin interfaceDegrees- Overrides:
degreeWithoutParallelRelationshipsin classGraphAdapter- See Also:
Graph.isMultiGraph()
-
nodeCount
public long nodeCount()
Description copied from interface:IdMapNumber of mapped nodeIds.- Specified by:
nodeCountin interfaceIdMap- Overrides:
nodeCountin classGraphAdapter
-
rootNodeCount
public java.util.OptionalLong rootNodeCount()
Description copied from interface:PartialIdMapNumber of mapped node ids in the root mapping. This is necessary for nested (filtered) id mappings.- Specified by:
rootNodeCountin interfacePartialIdMap- Overrides:
rootNodeCountin classGraphAdapter
-
containsRootNodeId
public boolean containsRootNodeId(long rootNodeId)
Description copied from interface:FilteredIdMapChecks if the rootNodeId (mappedNodeId) is present in the IdMaps mapping information.- Specified by:
containsRootNodeIdin interfaceFilteredIdMap
-
relationshipCount
public long relationshipCount()
- Specified by:
relationshipCountin interfaceGraph- Overrides:
relationshipCountin classGraphAdapter- Returns:
- returns the total number of relationships in the graph.
-
highestNeoId
public long highestNeoId()
- Specified by:
highestNeoIdin interfaceIdMap- Overrides:
highestNeoIdin classGraphAdapter
-
toMappedNodeId
public long toMappedNodeId(long originalNodeId)
Description copied from interface:PartialIdMapMaps an original node id to a mapped node id. In case of nested id maps, the mapped node id is always in the space of the innermost mapping.- Specified by:
toMappedNodeIdin interfacePartialIdMap- Overrides:
toMappedNodeIdin classGraphAdapter- Parameters:
originalNodeId- must be smaller or equal to the id returned byIdMap.highestNeoId()
-
toRootNodeId
public long toRootNodeId(long mappedNodeId)
Description copied from interface:IdMapMaps a filtered mapped node id to its root mapped node id. This is necessary for nested (filtered) id mappings. If this mapping is a nested mapping, this method returns the root mapped node id of the parent mapping. For the root mapping this method returns the given node id.- Specified by:
toRootNodeIdin interfaceIdMap- Overrides:
toRootNodeIdin classGraphAdapter
-
rootToMappedNodeId
public long rootToMappedNodeId(long rootNodeId)
Description copied from interface:FilteredIdMapMaps a root mapped node id to a filtered mapped node id. This is necessary for nested (filtered) id mappings. If this mapping is a nested mapping, this method returns the mapped id corresponding to the mapped id of the parent mapping. For the root mapping this method returns the given node id.- Specified by:
rootToMappedNodeIdin interfaceFilteredIdMap
-
contains
public boolean contains(long originalNodeId)
Description copied from interface:IdMapReturns true iff the neo4jNodeId is mapped, otherwise false.- Specified by:
containsin interfaceIdMap- Overrides:
containsin classGraphAdapter
-
toOriginalNodeId
public long toOriginalNodeId(long mappedNodeId)
Description copied from interface:IdMapMap mapped nodeId back to neo4j nodeId- Specified by:
toOriginalNodeIdin interfaceIdMap- Overrides:
toOriginalNodeIdin classGraphAdapter
-
forEachRelationship
public void forEachRelationship(long nodeId, RelationshipConsumer consumer)Description copied from interface:RelationshipIteratorCalls the given consumer function for every relationship of a given node.- Specified by:
forEachRelationshipin interfaceRelationshipIterator- Overrides:
forEachRelationshipin classGraphAdapter- Parameters:
nodeId- id of the node for which to iterate relationshipsconsumer- relationship consumer function
-
forEachRelationship
public void forEachRelationship(long nodeId, double fallbackValue, RelationshipWithPropertyConsumer consumer)Description copied from interface:RelationshipIteratorCalls the given consumer function for every relationship of a given node. If the graph was loaded with a relationship property, the property value of the relationship will be passed into the consumer. Otherwise the given fallback value will be used.- Specified by:
forEachRelationshipin interfaceRelationshipIterator- Overrides:
forEachRelationshipin classGraphAdapter- Parameters:
nodeId- id of the node for which to iterate relationshipsfallbackValue- value used as relationship property if no properties were loadedconsumer- relationship consumer function
-
streamRelationships
public java.util.stream.Stream<RelationshipCursor> streamRelationships(long nodeId, double fallbackValue)
- Specified by:
streamRelationshipsin interfaceRelationshipIterator- Overrides:
streamRelationshipsin classGraphAdapter
-
getFilteredMappedNodeId
public long getFilteredMappedNodeId(long nodeId)
-
asNodeFilteredGraph
public java.util.Optional<NodeFilteredGraph> asNodeFilteredGraph()
Description copied from interface:GraphIf this graph is created using a node label filter, this will return a NodeFilteredGraph that represents the node set used in this graph. Be aware that it is not guaranteed to contain all relationships of the graph. Otherwise, it will return an empty Optional.- Specified by:
asNodeFilteredGraphin interfaceGraph- Overrides:
asNodeFilteredGraphin classGraphAdapter
-
exists
public boolean exists(long sourceNodeId, long targetNodeId)- Specified by:
existsin interfaceRelationshipPredicate- Overrides:
existsin classGraphAdapter
-
nthTarget
public long nthTarget(long nodeId, int offset)Description copied from interface:GraphGet the n-th target node id for a givensourceNodeId. The order of the targets is not defined and depends on the implementation of the graph, but it is consistent across separate calls to this method on the same graph. ThesourceNodeIdmust be a node id existing in the graph. Theoffsetparameter is 0-indexed and must be positive. Ifoffsetis greater than the number of targets forsourceNodeId,-1is returned. It is undefined behavior if thesourceNodeIddoes not exist in the graph or theoffsetis negative.- Specified by:
nthTargetin interfaceGraph- Overrides:
nthTargetin classGraphAdapteroffset- then-th target to return. Must be positive.- Returns:
- the target at the
offsetor-1if there is no such target.
-
relationshipProperty
public double relationshipProperty(long sourceNodeId, long targetNodeId, double fallbackValue)Description copied from interface:RelationshipPropertiesget value of property on relationship between source and target node id- Specified by:
relationshipPropertyin interfaceRelationshipProperties- Overrides:
relationshipPropertyin classGraphAdapter- Parameters:
sourceNodeId- source nodetargetNodeId- target nodefallbackValue- value to use if relationship has no property value- Returns:
- the property value
-
relationshipProperty
public double relationshipProperty(long sourceNodeId, long targetNodeId)Description copied from interface:RelationshipPropertiesReturns the property value for a relationship defined by its source and target nodes.- Specified by:
relationshipPropertyin interfaceRelationshipProperties- Overrides:
relationshipPropertyin classGraphAdapter
-
concurrentCopy
public CSRGraph concurrentCopy()
- Specified by:
concurrentCopyin interfaceCSRGraph- Specified by:
concurrentCopyin interfaceGraph- Specified by:
concurrentCopyin interfaceRelationshipIterator- Overrides:
concurrentCopyin classCSRGraphAdapter- Returns:
- a copy of this iterator that reuses new cursors internally, so that iterations happen independent from other iterations.
-
availableNodeLabels
public java.util.Set<org.neo4j.gds.NodeLabel> availableNodeLabels()
- Specified by:
availableNodeLabelsin interfaceIdMap- Overrides:
availableNodeLabelsin classGraphAdapter
-
nodeLabels
public java.util.List<org.neo4j.gds.NodeLabel> nodeLabels(long mappedNodeId)
- Specified by:
nodeLabelsin interfaceIdMap- Overrides:
nodeLabelsin classGraphAdapter
-
hasLabel
public boolean hasLabel(long mappedNodeId, org.neo4j.gds.NodeLabel label)- Specified by:
hasLabelin interfaceIdMap- Overrides:
hasLabelin classGraphAdapter
-
forEachNodeLabel
public void forEachNodeLabel(long mappedNodeId, IdMap.NodeLabelConsumer consumer)- Specified by:
forEachNodeLabelin interfaceIdMap- Overrides:
forEachNodeLabelin classGraphAdapter
-
withFilteredLabels
public java.util.Optional<? extends FilteredIdMap> withFilteredLabels(java.util.Collection<org.neo4j.gds.NodeLabel> nodeLabels, int concurrency)
- Specified by:
withFilteredLabelsin interfaceIdMap- Overrides:
withFilteredLabelsin classGraphAdapter
-
nodeProperties
public NodePropertyValues nodeProperties(java.lang.String propertyKey)
Description copied from interface:NodePropertyContainerReturn the property values for a property key NOTE: Avoid using this on the hot path, favor caching the NodeProperties object when possible- Specified by:
nodePropertiesin interfaceNodePropertyContainer- Overrides:
nodePropertiesin classGraphAdapter- Parameters:
propertyKey- the node property key- Returns:
- the values associated with that key
-
release
public void release()
Description copied from interface:GraphRelease all resources which are not part of the result or IdMap- Specified by:
releasein interfaceGraph- Overrides:
releasein classGraphAdapter
-
-