Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graph.toString and Graph.nodeCountByLabel (like in odb) #176

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions core/src/main/scala/flatgraph/Graph.scala
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,15 @@ class Graph(val schema: Schema, val storagePathMaybe: Option[Path] = None) exten
}
}

override def toString(): String =
s"Graph[${nodeCount()} nodes]"

def nodeCountByLabel: Map[String, Int] = {
schema.nodeKinds
.map(schema.getNodeLabel)
.map(label => label -> nodeCount(label))
.filter { case (label, count) => count > 0 }
.toMap
}

}
3 changes: 3 additions & 0 deletions core/src/test/scala/flatgraph/GraphTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ class GraphTests extends AnyWordSpec with Matchers {
Accessors.getNeighborsIn(V0_0_GNode).size shouldBe 2
V0_0_GNode.out.size shouldBe 1
V0_0_GNode.in.size shouldBe 2

g.toString shouldBe "Graph[4 nodes]"
g.nodeCountByLabel shouldBe Map("V0" -> 2, "V1" -> 2)
}

val schema = TestSchema.make(1, 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,9 @@ class DomainClassesGenerator(schema: Schema) {
|
| override def close(): Unit =
| _graph.close()
|
| override def toString(): String =
| String.format("$domainShortName[%s]", graph)
|}
|
|@flatgraph.help.TraversalSource
Expand Down
Loading