Skip to content

Commit

Permalink
Move "hull" pointer to lineage
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromekelleher committed Jul 25, 2024
1 parent 8ee8cb1 commit a75d933
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
24 changes: 10 additions & 14 deletions algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,9 @@ def __init__(self, index):
self.node = None
self.prev = None
self.next = None
self.index = index
self.population = None
self.label = 0
self.index = index
self.hull = None
self.lineage = None

def __repr__(self):
Expand All @@ -154,7 +153,7 @@ def get_hull(self):
assert seg is not None
while seg.prev is not None:
seg = seg.prev
hull = seg.hull
hull = seg.lineage.hull
return hull

def get_left_index(self):
Expand All @@ -166,11 +165,6 @@ def get_left_index(self):
return index


@dataclasses.dataclass
class Lineage:
head: Segment


class Population:
"""
Class representing a population in the simulation.
Expand Down Expand Up @@ -729,6 +723,12 @@ def __repr__(self):
return f"x:{self.x}, io:{self.insertion_order}"


@dataclasses.dataclass
class Lineage:
head: Segment
hull: Hull = None


class OrderStatisticsTree:
"""
Bintrees AVL tree with added functionality to keep track of the rank
Expand Down Expand Up @@ -1054,15 +1054,11 @@ def change_migration_matrix_element(self, pop_i, pop_j, rate):
self.migration_matrix[pop_i][pop_j] = rate

def alloc_hull(self, left, right, lineage):
alpha = lineage.head
hull = self.hull_stack.pop()
hull.left = left
hull.right = right
while alpha.prev is not None:
alpha = alpha.prev
assert alpha is not None
hull.lineage = lineage
alpha.hull = hull
lineage.hull = hull
return hull

def alloc_segment(
Expand Down Expand Up @@ -1688,7 +1684,7 @@ def migration_event(self, j, k):
index = random.randint(0, source.get_num_ancestors(label) - 1)
lineage = source.remove(index, label)
x = lineage.head
hull = x.get_hull()
hull = lineage.hull
assert (self.model == "smc_k") == (hull is not None)
dest.add(lineage, label)
if self.model == "smc_k":
Expand Down
11 changes: 5 additions & 6 deletions lib/msprime.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ segment_get_hull(segment_t *seg)
seg = seg->prev;
}
tsk_bug_assert(seg->lineage != NULL);
hull = seg->hull;
hull = seg->lineage->hull;
tsk_bug_assert(hull->lineage == seg->lineage);

return hull;
Expand Down Expand Up @@ -839,7 +839,7 @@ msp_set_hull_block_size(msp_t *self, size_t block_size)
static segment_t *MSP_WARN_UNUSED
msp_alloc_segment(msp_t *self, double left, double right, tsk_id_t value,
population_id_t population, label_id_t label, segment_t *prev, segment_t *next,
hull_t *hull)
hull_t *MSP_UNUSED(hull))
{
segment_t *seg = NULL;

Expand Down Expand Up @@ -878,7 +878,6 @@ msp_alloc_segment(msp_t *self, double left, double right, tsk_id_t value,
seg->value = value;
seg->population = population;
seg->label = label;
seg->hull = hull;
out:
return seg;
}
Expand Down Expand Up @@ -907,7 +906,7 @@ static segment_t *MSP_WARN_UNUSED
msp_copy_segment(msp_t *self, const segment_t *seg)
{
return msp_alloc_segment(self, seg->left, seg->right, seg->value, seg->population,
seg->label, seg->prev, seg->next, seg->hull);
seg->label, seg->prev, seg->next, NULL);
}

static hull_t *MSP_WARN_UNUSED
Expand Down Expand Up @@ -950,7 +949,7 @@ msp_alloc_hull(msp_t *self, double left, double right, lineage_t *lineage)
hull->count = 0;
hull->insertion_order = UINT64_MAX;
tsk_bug_assert(lineage->head->prev == NULL);
lineage->head->hull = hull;
lineage->hull = hull;
out:
return hull;
}
Expand Down Expand Up @@ -1949,7 +1948,7 @@ msp_verify_hulls(msp_t *self)
for (a = avl->head; a->next != NULL; a = a->next) {
lin = (lineage_t *) a->item;
x = lin->head;
hull_right = x->hull->right;
hull_right = lin->hull->right;
hull_a.left = x->left;
while (x->next != NULL) {
x = x->next;
Expand Down
2 changes: 1 addition & 1 deletion lib/msprime.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ typedef struct segment_t_t {
size_t id;
struct segment_t_t *prev;
struct segment_t_t *next;
struct hull_t_t *hull;
struct lineage_t_t *lineage;
} segment_t;

typedef struct lineage_t_t {
segment_t *head;
struct hull_t_t *hull;
} lineage_t;

typedef struct {
Expand Down

0 comments on commit a75d933

Please sign in to comment.