rust-scraper / ego-tree

Vec-backed ID-tree
https://docs.rs/ego-tree
ISC License
45 stars 16 forks source link

partialord + ord for nodeid #22

Closed samdenty closed 1 month ago

samdenty commented 3 years ago

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

causal-agent commented 3 years ago

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"?

samdenty commented 3 years ago

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()
causal-agent commented 3 years ago

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.