Skip to content

Make nodes hashable#715

Open
FredrikAppelros wants to merge 1 commit intojbeder:masterfrom
FredrikAppelros:hashable-nodes
Open

Make nodes hashable#715
FredrikAppelros wants to merge 1 commit intojbeder:masterfrom
FredrikAppelros:hashable-nodes

Conversation

@FredrikAppelros
Copy link

Implement a specialization of std::hash<YAML::Node> so that nodes can be used in unordered associative containers.

This would resolve parts of what is mentioned in #265.

Implement a specialization of `std::hash<YAML::Node>` so that nodes can
be used in unordered associative containers.
Copy link
Owner

@jbeder jbeder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the semantics of this hash?

@FredrikAppelros
Copy link
Author

As you can see from the implementation it basically boils down to looking at the location of the node in memory. If two nodes point to the same memory location then they produce the same hash digest.

The idea here is that, as mentioned in #265, there are situations in which you may want to be able to use the nodes themselves as indices into a data structure when processing the graph that the YAML represents.

@jbeder
Copy link
Owner

jbeder commented Aug 5, 2019 via email

@FredrikAppelros
Copy link
Author

I guess that depends on what your definition of "same" is. If I have understood it correctly this is based on the same principle as the existing equality operator that is used for nodes as can be seen here.

@FredrikAppelros
Copy link
Author

Just a friendly ping to see if we could resume this discussion. :)

@FredrikAppelros
Copy link
Author

Is there anything else that I can do to move this along?

@TedLyngmo
Copy link
Contributor

TedLyngmo commented Feb 26, 2020

If I create two nodes, separately, with the same content, would they get the same hash?

The is() member function does not test for equality so it's not a great fit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants