如果晚一点再开分支呢
假设 feature 不是从 7b4e2d0 分出来,而是等主线做完 a1c5f83 之后才分。运行下面这段程序看新的分叉距离:
def ancestors(g, c):
seen = set()
st = [c]
while st:
x = st.pop()
if x in seen:
continue
seen.add(x)
st.extend(g[x])
return seen
def only_on(g, a, b):
return ancestors(g, a) - ancestors(g, b)
g2 = {'3f2a91c': [], '7b4e2d0': ['3f2a91c'],
'a1c5f83': ['7b4e2d0'],
'e90d417': ['a1c5f83'], '5c8b206': ['e90d417']}
d = len(only_on(g2, 'a1c5f83', '5c8b206')) + \
len(only_on(g2, '5c8b206', 'a1c5f83'))
print(d)
全部评论