rushter / selectolax

Python binding to Modest and Lexbor engines (fast HTML5 parser with CSS selectors).
MIT License
1.16k stars 70 forks source link

add hash and mem_id to make nodes hashable #96

Closed MohammadRaziei closed 1 year ago

MohammadRaziei commented 1 year ago

hi. I'm using selectolax. but in many algorithms, we need to store nodes in a dict. but the parser.Node or lexbor.Node is not hashable so I cannot to use it. and in many algorithms we need to assign a unique id to any node of tree. also there is a another problem for example :

node = parent.child[0] # thats pseudo-code
node.parent is parent # return False
# but
node.parent == parent # return True

so there is no way to use id(.) if node as a unique feature of node to store it in a dict, I cast the pointer of node to mem_id as mem_id and use mem_id as hash function. so the problem is almost solved

rushter commented 1 year ago

Thanks. That's a useful feature.