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)
CSRGraph
concurrentCopy()
boolean
contains(long originalNodeId)
Returns true iff the Neo4j id is mapped, otherwise false.boolean
containsRootNodeId(long rootNodeId)
Checks if the rootNodeId (mappedNodeId) is present in the IdMaps mapping information.int
degree(long nodeId)
Returns the number of relationships connected to that node.int
degreeWithoutParallelRelationships(long nodeId)
Much slower than just degree() because it may have to look up all relationships.boolean
exists(long sourceNodeId, long targetNodeId)
void
forEachNode(java.util.function.LongPredicate consumer)
Iterate over each nodeIdvoid
forEachNodeLabel(long mappedNodeId, IdMap.NodeLabelConsumer consumer)
void
forEachRelationship(long nodeId, double fallbackValue, RelationshipWithPropertyConsumer consumer)
Calls the given consumer function for every relationship of a given node.void
forEachRelationship(long nodeId, RelationshipConsumer consumer)
Calls the given consumer function for every relationship of a given node.boolean
hasLabel(long mappedNodeId, org.neo4j.gds.NodeLabel label)
long
highestOriginalId()
The highest id that is mapped in this id mapping.long
nodeCount()
Number of mapped nodeIds.long
nodeCount(org.neo4j.gds.NodeLabel nodeLabel)
Number of mapped nodeIds for a specific node label.java.util.PrimitiveIterator.OfLong
nodeIterator()
java.util.PrimitiveIterator.OfLong
nodeIterator(java.util.Set<org.neo4j.gds.NodeLabel> labels)
java.util.List<org.neo4j.gds.NodeLabel>
nodeLabels(long mappedNodeId)
NodePropertyValues
nodeProperties(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 possiblelong
nthTarget(long nodeId, int offset)
Get the n-th target node id for a givensourceNodeId
.long
relationshipCount()
double
relationshipProperty(long sourceNodeId, long targetNodeId)
Returns the property value for a relationship defined by its source and target nodes.double
relationshipProperty(long sourceNodeId, long targetNodeId, double fallbackValue)
get value of property on relationship between source and target node idvoid
release()
Release all resources which are not part of the result or IdMapjava.util.OptionalLong
rootNodeCount()
Number of mapped node ids in the root mapping.org.neo4j.gds.api.schema.GraphSchema
schema()
java.util.stream.Stream<RelationshipCursor>
streamRelationships(long nodeId, double fallbackValue)
long
toFilteredNodeId(long rootNodeId)
Maps a root mapped node id to a filtered mapped node id.long
toMappedNodeId(long originalNodeId)
Maps an original node id to a mapped node id.long
toOriginalNodeId(long mappedNodeId)
Returns the original node id for the given mapped node id.long
toRootNodeId(long mappedNodeId)
Maps a filtered mapped node id to its root mapped node id.java.util.Optional<FilteredIdMap>
withFilteredLabels(java.util.Collection<org.neo4j.gds.NodeLabel> nodeLabels, int concurrency)
-
Methods inherited from class org.neo4j.gds.api.CSRGraphAdapter
addNodeIdToLabel, addNodeLabel, relationshipTopologies
-
Methods inherited from class org.neo4j.gds.api.GraphAdapter
availableNodeProperties, canRelease, characteristics, degreeInverse, forEachInverseRelationship, forEachInverseRelationship, graph, hasRelationshipProperty, isMultiGraph, relationshipTypeFilteredGraph, releaseProperties, releaseTopology, rootIdMap, supportsInverseIteration
-
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.Degrees
degreeInverse
-
Methods inherited from interface org.neo4j.gds.api.Graph
canRelease, characteristics, hasRelationshipProperty, isEmpty, isMultiGraph, relationshipTypeFilteredGraph, releaseProperties, releaseTopology
-
Methods inherited from interface org.neo4j.gds.api.IdMap
addNodeIdToLabel, addNodeLabel, rootIdMap, safeToMappedNodeId
-
Methods inherited from interface org.neo4j.gds.api.properties.nodes.NodePropertyContainer
availableNodeProperties
-
Methods inherited from interface org.neo4j.gds.api.RelationshipIterator
forEachInverseRelationship, forEachInverseRelationship, supportsInverseIteration
-
-
-
-
Constructor Detail
-
NodeFilteredGraph
public NodeFilteredGraph(CSRGraph originalGraph, FilteredIdMap filteredIdMap)
-
-
Method Detail
-
schema
public org.neo4j.gds.api.schema.GraphSchema schema()
- Specified by:
schema
in interfaceGraph
- Overrides:
schema
in classGraphAdapter
-
nodeIterator
public java.util.PrimitiveIterator.OfLong nodeIterator()
- Specified by:
nodeIterator
in interfaceNodeIterator
- Overrides:
nodeIterator
in classGraphAdapter
-
nodeIterator
public java.util.PrimitiveIterator.OfLong nodeIterator(java.util.Set<org.neo4j.gds.NodeLabel> labels)
- Specified by:
nodeIterator
in interfaceNodeIterator
- Overrides:
nodeIterator
in classGraphAdapter
-
batchIterables
public java.util.Collection<PrimitiveLongIterable> batchIterables(long batchSize)
- Specified by:
batchIterables
in interfaceBatchNodeIterable
- Overrides:
batchIterables
in 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:NodeIterator
Iterate over each nodeId- Specified by:
forEachNode
in interfaceNodeIterator
- Overrides:
forEachNode
in classGraphAdapter
-
degree
public int degree(long nodeId)
Description copied from interface:Degrees
Returns the number of relationships connected to that node. For undirected graphs, this includes outgoing and incoming relationships. For directed graphs, this is the number of outgoing edges.- Specified by:
degree
in interfaceDegrees
- Overrides:
degree
in classGraphAdapter
-
degreeWithoutParallelRelationships
public int degreeWithoutParallelRelationships(long nodeId)
Description copied from interface:Degrees
Much 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:
degreeWithoutParallelRelationships
in interfaceDegrees
- Overrides:
degreeWithoutParallelRelationships
in classGraphAdapter
- See Also:
Graph.isMultiGraph()
-
nodeCount
public long nodeCount()
Description copied from interface:IdMap
Number of mapped nodeIds.- Specified by:
nodeCount
in interfaceIdMap
- Overrides:
nodeCount
in classGraphAdapter
-
nodeCount
public long nodeCount(org.neo4j.gds.NodeLabel nodeLabel)
Description copied from interface:IdMap
Number of mapped nodeIds for a specific node label.- Specified by:
nodeCount
in interfaceIdMap
- Overrides:
nodeCount
in classGraphAdapter
-
rootNodeCount
public java.util.OptionalLong rootNodeCount()
Description copied from interface:PartialIdMap
Number of mapped node ids in the root mapping. This is necessary for nested (filtered) id mappings.- Specified by:
rootNodeCount
in interfacePartialIdMap
- Overrides:
rootNodeCount
in classGraphAdapter
-
relationshipCount
public long relationshipCount()
- Specified by:
relationshipCount
in interfaceGraph
- Overrides:
relationshipCount
in classGraphAdapter
- Returns:
- returns the total number of relationships in the graph.
-
highestOriginalId
public long highestOriginalId()
Description copied from interface:IdMap
The highest id that is mapped in this id mapping.The value is the upper bound of the original node id space.
- Specified by:
highestOriginalId
in interfaceIdMap
- Overrides:
highestOriginalId
in classGraphAdapter
-
toMappedNodeId
public long toMappedNodeId(long originalNodeId)
Description copied from interface:PartialIdMap
Maps 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:
toMappedNodeId
in interfacePartialIdMap
- Overrides:
toMappedNodeId
in classGraphAdapter
- Parameters:
originalNodeId
- must be smaller or equal to the id returned byIdMap.highestOriginalId()
-
toRootNodeId
public long toRootNodeId(long mappedNodeId)
Description copied from interface:IdMap
Maps 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:
toRootNodeId
in interfaceIdMap
- Overrides:
toRootNodeId
in classGraphAdapter
-
toOriginalNodeId
public long toOriginalNodeId(long mappedNodeId)
Description copied from interface:IdMap
Returns the original node id for the given mapped node id. The original node id is typically the Neo4j node id. This method is guaranteed to always return the Neo4j id, regardless of the given mapped node id refers to a filtered node id space or a regular / unfiltered node id space.- Specified by:
toOriginalNodeId
in interfaceIdMap
- Overrides:
toOriginalNodeId
in classGraphAdapter
-
toFilteredNodeId
public long toFilteredNodeId(long rootNodeId)
Description copied from interface:FilteredIdMap
Maps 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:
toFilteredNodeId
in interfaceFilteredIdMap
-
contains
public boolean contains(long originalNodeId)
Description copied from interface:IdMap
Returns true iff the Neo4j id is mapped, otherwise false.- Specified by:
contains
in interfaceIdMap
- Overrides:
contains
in classGraphAdapter
-
containsRootNodeId
public boolean containsRootNodeId(long rootNodeId)
Description copied from interface:FilteredIdMap
Checks if the rootNodeId (mappedNodeId) is present in the IdMaps mapping information.- Specified by:
containsRootNodeId
in interfaceFilteredIdMap
-
forEachRelationship
public void forEachRelationship(long nodeId, RelationshipConsumer consumer)
Description copied from interface:RelationshipIterator
Calls the given consumer function for every relationship of a given node.- Specified by:
forEachRelationship
in interfaceRelationshipIterator
- Overrides:
forEachRelationship
in 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:RelationshipIterator
Calls 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:
forEachRelationship
in interfaceRelationshipIterator
- Overrides:
forEachRelationship
in 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:
streamRelationships
in interfaceRelationshipIterator
- Overrides:
streamRelationships
in classGraphAdapter
-
asNodeFilteredGraph
public java.util.Optional<NodeFilteredGraph> asNodeFilteredGraph()
Description copied from interface:Graph
If 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:
asNodeFilteredGraph
in interfaceGraph
- Overrides:
asNodeFilteredGraph
in classGraphAdapter
-
exists
public boolean exists(long sourceNodeId, long targetNodeId)
- Specified by:
exists
in interfaceRelationshipPredicate
- Overrides:
exists
in classGraphAdapter
-
nthTarget
public long nthTarget(long nodeId, int offset)
Description copied from interface:Graph
Get 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. ThesourceNodeId
must be a node id existing in the graph. Theoffset
parameter is 0-indexed and must be positive. Ifoffset
is greater than the number of targets forsourceNodeId
,-1
is returned. It is undefined behavior if thesourceNodeId
does not exist in the graph or theoffset
is negative.- Specified by:
nthTarget
in interfaceGraph
- Overrides:
nthTarget
in classGraphAdapter
offset
- then
-th target to return. Must be positive.- Returns:
- the target at the
offset
or-1
if there is no such target.
-
relationshipProperty
public double relationshipProperty(long sourceNodeId, long targetNodeId, double fallbackValue)
Description copied from interface:RelationshipProperties
get value of property on relationship between source and target node id- Specified by:
relationshipProperty
in interfaceRelationshipProperties
- Overrides:
relationshipProperty
in 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:RelationshipProperties
Returns the property value for a relationship defined by its source and target nodes.- Specified by:
relationshipProperty
in interfaceRelationshipProperties
- Overrides:
relationshipProperty
in classGraphAdapter
-
concurrentCopy
public CSRGraph concurrentCopy()
- Specified by:
concurrentCopy
in interfaceCSRGraph
- Specified by:
concurrentCopy
in interfaceGraph
- Specified by:
concurrentCopy
in interfaceRelationshipIterator
- Overrides:
concurrentCopy
in classCSRGraphAdapter
- Returns:
- a copy of this iterator that reuses new cursors internally, so that iterations happen independent of other iterations.
-
availableNodeLabels
public java.util.Set<org.neo4j.gds.NodeLabel> availableNodeLabels()
- Specified by:
availableNodeLabels
in interfaceIdMap
- Overrides:
availableNodeLabels
in classGraphAdapter
-
nodeLabels
public java.util.List<org.neo4j.gds.NodeLabel> nodeLabels(long mappedNodeId)
- Specified by:
nodeLabels
in interfaceIdMap
- Overrides:
nodeLabels
in classGraphAdapter
-
hasLabel
public boolean hasLabel(long mappedNodeId, org.neo4j.gds.NodeLabel label)
- Specified by:
hasLabel
in interfaceIdMap
- Overrides:
hasLabel
in classGraphAdapter
-
forEachNodeLabel
public void forEachNodeLabel(long mappedNodeId, IdMap.NodeLabelConsumer consumer)
- Specified by:
forEachNodeLabel
in interfaceIdMap
- Overrides:
forEachNodeLabel
in classGraphAdapter
-
withFilteredLabels
public java.util.Optional<FilteredIdMap> withFilteredLabels(java.util.Collection<org.neo4j.gds.NodeLabel> nodeLabels, int concurrency)
- Specified by:
withFilteredLabels
in interfaceIdMap
- Overrides:
withFilteredLabels
in classGraphAdapter
-
nodeProperties
public NodePropertyValues nodeProperties(java.lang.String propertyKey)
Description copied from interface:NodePropertyContainer
Return the property values for a property key NOTE: Avoid using this on the hot path, favor caching the NodeProperties object when possible- Specified by:
nodeProperties
in interfaceNodePropertyContainer
- Overrides:
nodeProperties
in classGraphAdapter
- Parameters:
propertyKey
- the node property key- Returns:
- the values associated with that key
-
release
public void release()
Description copied from interface:Graph
Release all resources which are not part of the result or IdMap- Specified by:
release
in interfaceGraph
- Overrides:
release
in classGraphAdapter
-
-