Is it possible in jdom to get the children of a node that share a certain attribute without having to look at all children in bruteforce? Is search in l开发者_运维技巧ogarithmic time possible?
Is search in logarithmic time possible?
No, because that would require some sort of index keyed on that particular attribute, and why would JDOM keep such an index?
You could have an XPath implementation that builds such an index internally to speed up repeated searches, but it would still have to build it first.
If you wanted to create an index on the specific attribute, you could use SAX and create an index as you parse the document. This could give you O(1) to find the attribute, after you constructed the index.
In JDOM, a logrithmic search would be impossible because, in divide and conquer searches an ordering of the nodes is assumed (like in a binary search tree). Since the Element
s of a JDOM Document
have no ordering, there is no way to shrink the search space.
精彩评论