Skip to content

Commit

Permalink
Graph.toString and Graph.nodeCountByLabel (like in odb) (#176)
Browse files Browse the repository at this point in the history
* Graph.toString and Graph.nodeCountByLabel (like in odb)

* also generate Domain.toString like before
  • Loading branch information
mpollmeier authored Apr 18, 2024
1 parent e4756e6 commit d56ed8b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
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

0 comments on commit d56ed8b

Please sign in to comment.