While using libgraph I found myself building hash maps of some_other_id => vertex to get map lookup performance in contexts where the id was a hash of a value in a struct/vertex rather than the whole vertex contents as Graph.Utils.vertex_id/1 implements. In my case this was to maintain uniqueness of conditionals in a rule engine / match algorithm context where additional meta data in a vertex may vary but uniqueness of the actual conditional expression within was necessary.
Rather than maintain the extra memory space of my own hash maps this PR lets these hash lookups be maintained as a single source of truth within Libgraph.
This PR does the following to address this use case
Supports a :vertex_identifier option in Graph.new/1 allowing injection of one's own unique identifier function of a vertex.
While using libgraph I found myself building hash maps of
some_other_id => vertex
to get map lookup performance in contexts where the id was a hash of a value in a struct/vertex rather than the whole vertex contents asGraph.Utils.vertex_id/1
implements. In my case this was to maintain uniqueness of conditionals in a rule engine / match algorithm context where additional meta data in a vertex may vary but uniqueness of the actual conditional expression within was necessary.Rather than maintain the extra memory space of my own hash maps this PR lets these hash lookups be maintained as a single source of truth within Libgraph.
This PR does the following to address this use case
:vertex_identifier
option inGraph.new/1
allowing injection of one's own unique identifier function of a vertex.Graph.Utils.vertex_id/1
Please tell me if you have any questions or concerns - I'm not yet 100% sure this is a sane approach so feedback of any kind would be appreciated.