Here's a possible adjustment to the School-II approach that i think avoids the issues i've been raising, while giving the desired O(n)-to-O(1) speedup in common situations. It's basically School-II dispatch, plus a check: On compilation, freeze any cases that meet the School-II conditions and have a trustworthy __hash__ method into a dictionary. At runtime, when the dictionary yields a hit, check if the case expression yields a different value. If the value has changed, use if/elif processing. In most cases the case-equality check will be cheap (e.g. an attribute lookup), but it would allow us to establish for sure that the switch value really matches the case value when we branch to a particular case, so we'd not be so vulnerable to __hash__ misbehaving, which seems to be your main source of discomfort with if/elif semantics. -- ?!ng
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4