ego-tree icon indicating copy to clipboard operation
ego-tree copied to clipboard

partialord + ord for nodeid

Open samdenty opened this issue 5 years ago • 3 comments

As node-ids are simply integers, it's useful to be able to compare two ids to see which one appears first in the tree

samdenty avatar Jan 30 '21 18:01 samdenty

As node-ids are simply integers, it's useful to be able to compare two ids to see which one appears first in the tree

Is it? By which definition of "first"?

causal-agent avatar Jan 30 '21 18:01 causal-agent

specifically I need ord to compare two html elements in scraper, to see if an element is before / after another. In scrapers case it appears the ids are correlated to the order at which they appear in the dom.

let b_appers_after_a = a_ref.id() < b_ref.id()

samdenty avatar Jan 30 '21 18:01 samdenty

There is no guarantee in either this library or scraper that the value of a NodeId would tell you that. NodeId's can be created in arbitrary order regardless of where they end up in the tree, and in particular the TreeSink trait which html5ever uses to build the tree decouples node creation from attaching to the tree in various ways.

causal-agent avatar Jan 30 '21 18:01 causal-agent