Efficient way to get size of a graph? #116
-
Is counting the iterator |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
If you are writing generic code, where the only thing you know about
The rationale is that the If, on the other hand, you know the precise type of
|
Beta Was this translation helpful? Give feedback.
If you are writing generic code, where the only thing you know about
graph
is that it implements theGraph
trait, then:graph.triples().count()
is the way to go.graph.triples().size_hint()
will be cheaper.The rationale is that the
Graph
trait might be implemented by types that can not cheaply determine the exact number of triples.If, on the other hand, you know the precise type of
graph
, then you might have other options:sophia::inmem
(FastGraph
,LightGraph
), the result ofgraph.triples().size_hint()
will always be strictly accurate (min=max).Vec<T>
andHashSet<T>
implementGraph
ifT
impleme…