-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add get_properties_ns to Node and RoNode #128
Conversation
This required implementing the traits Hash, PartialEq and Eq for Namespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contribution, and the new tests!
Everything looks great, but I am wondering if the equality implementation would cause confusion down the road. Not opposed to merging, but wondering if you have additional motivation to share.
fn eq(&self, other: &Self) -> bool { | ||
self.get_prefix() == other.get_prefix() && self.get_href() == other.get_href() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a little tricky, since it can be surprising depending on what expectation someone approaches the Namespace
struct.
Internally, Namespace stores a libxml2 xmlNsPtr
. So one could have expected pointer equality. Alternatively, one could have expected the equality to be in the XML sense - if the URL is identical, then the namespaces are equal, even if the prefixes are different.
So introducing the "deepest" kind of equality here (same prefix and same namespace) isn't immediately expected behavior. Additionally, it is the slowest variant performance-wise, and uses dedicated allocations.
Hm... I am not opposed to merging it as introduced here, but I wonder if we'll get requests to modify it down the road. For now a clarifying comment on the Namespace struct could help.
self.get_prefix().hash(state); | ||
self.get_href().hash(state); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly to above, using the pointer directly could be another reasonable approach to hashing.
Thank you for your review and comments! I actually had conflicting thoughts about the three options. As you say, it depends on what one expects from the I would've liked it to be true to the specification, but I rolled out the URI comparison because I don't see it as an implementation of the XML namespace. I think of it as a Using the pointer felt unnecessarily too strict, given the usage of namespaces, but I don't have a strong argument against it. If you wish, we can change it to the strictest equality (using the |
The method
get_properties_ns
was added toNode
andRoNode
in line with this issue.It returns a
HashMap
of attribute values, which is indexed by tuples of the attributes and their namespaces.The code is similar to that of
get_properties
. However,get_properties
used unnecessary vector allocationattr_names
, which is removed in the PR.The indexing mentioned above required implementing the traits
Hash
,PartialEq
andEq
forNamespace
. These were implemented using the methodsget_prefix
andget_href
instead ofns_ptr
. This choice does not affect the methodget_properties_ns
as a prefix is bound to a single namespace name in a given scope. However, this has the effect that the two namespaces declared below are considered identical.