Using DONE_SET method to make algorithm faster

What we do is like to maintain a dict {DONE_SET: memory peak}, then Each time when we execute Node X, we make a check if the peak in dict and the current peak bigger than that peak. If yes(or equal), break and start a new branch. if no, update the peak in dict and continue.
This duplicate much code. I think you can rearrage the if/else to remote the duplicate code like this:

if done_dict.get(frozen_set, max_mem_count + 1) <= max_mem_count:
   done_dict[...] = max
   move line 943 to 955 here.
# no else clause.

The clean up code. from line 957 and following.