snapshot.branches is now an ImmutableDict, which is backed by
a tuple of tuples; so random accesses now take a linear time
instead of a constant time.
This commit replaces random accesses with a single scan of all
the items, and does existence checks in a set instead.