if i:
prev = entity[i - 1:i + 1]
stats[prev] += freq
if stats[prev] > partial_stats_min:
update_partial_stats = True
indices[prev][j] += 1
// Increase frequency of (new pair) "BC D" in "A BC D", but do not touch if "A BC BC" as stats for "BC BC" will be adjusted win next occurence of "BC" pair
if i < len(entity) - 1 and entity[i + 1] != new_pair:
After Change
// Update partial stats or frequency of most frequent pair is less than saved minimum for partial stats
if update_partial_stats or freq < partial_stats_min:
partial_stats_min = stats.most_common(500)[-1][1]
partial_stats = Counter()
for k, v in stats.most_common():
if v < partial_stats_min:
break