Skip to content

Commit

Permalink
C: simplify merge_x_ancestors
Browse files Browse the repository at this point in the history
Abstract out details of adding in merged lineage
  • Loading branch information
jeromekelleher committed Aug 1, 2024
1 parent eece1e0 commit d7b9eec
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 151 deletions.
17 changes: 11 additions & 6 deletions algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1116,11 +1116,11 @@ def alloc_segment(
def alloc_lineage(self, head, population, *, label=0, tail=None):
lineage = Lineage(head, population=population, label=label, tail=tail)
assert tail is None
if head is not None:
# If we're allocating a new lineage for a given head segment, then we
# have no choice but to iterate over the rest of the chain to update
# the lineage reference, and determine the tail.
lineage.reset_segments()
# If we're allocating a new lineage for a given head segment, then we
# have no choice but to iterate over the rest of the chain to update
# the lineage reference, and determine the tail. If head is None,
# this doesn't do anything.
lineage.reset_segments()
return lineage

def copy_segment(self, segment):
Expand Down Expand Up @@ -2564,9 +2564,14 @@ def insert_merged_lineage(

if new_lineage.head is not None:
# Use up any uncoalesced segments at the end of the chain
while (x := new_lineage.tail.next) is not None:
x = new_lineage.tail.next
while x is not None:
x.lineage = new_lineage
new_lineage.tail = x
x = x.next
# tail = new_lineage.tail
# new_lineage.reset_segments()
# assert tail == new_lineage.tail
self.add_lineage(new_lineage)

if self.model == "smc_k":
Expand Down
Loading

0 comments on commit d7b9eec

Please sign in to comment.