It seems like we should be able to do better if we modeled the data as a tree. IIUC the current approach is super-linear in runtime complexity.
tree = {}
for segment in sub_segments:
sub_tree = tree
for nibble in segment:
sub_tree.setdefault(nibble, {})
if not isinstance(sub_tree[nibble], collections.Mapping):
... # we've detected a that `segment` is a superset of `sub_tree[nibble]`
sub_tree = sub_tree[nibble]
# once the segment terminates, we store the full segment at that position
# so that we can later detect segments that are prefixes of other segments.
sub_tree[segment[-1]] = segment
I think the untested psuedocode above has O(n) complexity.
Originally posted by @pipermerriam in #95
Originally posted by @pipermerriam in #95