Skip to content

Efficient way to get size of a graph? #116

Answered by pchampin
KonradHoeffner asked this question in Q&A
Discussion options

You must be logged in to vote

If you are writing generic code, where the only thing you know about graph is that it implements the Graph trait, then:

  • If you need an exact count, yes, graph.triples().count() is the way to go.
  • If you can make do with an estimation, 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:

  • for all graphs in sophia::inmem (FastGraph, LightGraph), the result of graph.triples().size_hint() will always be strictly accurate (min=max).
  • Vec<T> and HashSet<T> implement Graph if T impleme…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by KonradHoeffner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #114 on August 17, 2022 07:49.