Skip to content

Commit ee2b6c0

Browse files
Make the lineage the main pointer for hull handling
1 parent 7058dd4 commit ee2b6c0

2 files changed

Lines changed: 26 additions & 26 deletions

File tree

lib/msprime.c

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,7 @@ msp_set_segment_mass(msp_t *self, segment_t *seg)
446446
}
447447
}
448448

449-
static void msp_remove_hull(msp_t *self, hull_t *hull);
450-
static void msp_free_hull(msp_t *self, hull_t *hull, label_id_t label);
449+
static void msp_remove_hull(msp_t *self, lineage_t *lin);
451450
static int msp_insert_individual_hull(msp_t *self, lineage_t *lin);
452451

453452
static int
@@ -466,8 +465,7 @@ msp_unindex_segments(msp_t *self)
466465
for (node = population_ancestors->head; node != NULL; node = node->next) {
467466
lin = (lineage_t *) node->item;
468467
if (lin->hull != NULL) {
469-
msp_remove_hull(self, lin->hull);
470-
lin->hull = NULL;
468+
msp_remove_hull(self, lin);
471469
}
472470
}
473471
}
@@ -975,12 +973,12 @@ msp_alloc_hull(msp_t *self, double left, double right, lineage_t *lineage)
975973
hull->left = left;
976974
tsk_bug_assert(right <= self->sequence_length);
977975
hull->right = right;
978-
hull->lineage = lineage;
979976
hull->count = 0;
980977
hull->insertion_order = UINT64_MAX;
981978
tsk_bug_assert(lineage->head->prev == NULL);
982979
tsk_bug_assert(lineage->hull == NULL);
983980
lineage->hull = hull;
981+
hull->lineage = lineage;
984982
out:
985983
return hull;
986984
}
@@ -1353,12 +1351,13 @@ msp_get_lineage_population(msp_t *self, lineage_t *lineage)
13531351
}
13541352

13551353
static int MSP_WARN_UNUSED
1356-
msp_insert_hull(msp_t *self, hull_t *hull)
1354+
msp_insert_hull(msp_t *self, lineage_t *lineage)
13571355
{
13581356
int c, ret = 0;
13591357
avl_node_t *node, *query_node;
13601358
avl_tree_t *hulls_left, *hulls_right;
13611359
population_id_t pop;
1360+
hull_t *hull = lineage->hull;
13621361
hull_t *curr_hull;
13631362
hullend_t query;
13641363
hullend_t *hullend;
@@ -1369,8 +1368,8 @@ msp_insert_hull(msp_t *self, hull_t *hull)
13691368
/* setting hull->count requires two steps
13701369
step 1: num_starting before hull->left */
13711370
tsk_bug_assert(hull != NULL);
1372-
pop = hull->lineage->population;
1373-
label = hull->lineage->label;
1371+
pop = lineage->population;
1372+
label = lineage->label;
13741373
hulls_left = &self->populations[pop].hulls_left[label];
13751374
coal_mass_index = &self->populations[pop].coal_mass_index[label];
13761375
/* insert hull into state */
@@ -1435,21 +1434,24 @@ msp_insert_hull(msp_t *self, hull_t *hull)
14351434
}
14361435

14371436
static void
1438-
msp_remove_hull(msp_t *self, hull_t *hull)
1437+
msp_remove_hull(msp_t *self, lineage_t *lin)
14391438
{
14401439
int c;
14411440
avl_node_t *node, *curr_node, *query_node;
14421441
hullend_t query, *query_ptr;
1443-
hull_t *curr_hull;
1442+
hull_t *curr_hull, *hull;
14441443
avl_tree_t *hulls_left, *hulls_right;
14451444
fenwick_t *coal_mass_index;
14461445
segment_t *u;
14471446
label_id_t label;
14481447
population_id_t pop;
14491448

1450-
u = hull->lineage->head;
1451-
label = hull->lineage->label;
1452-
pop = hull->lineage->population;
1449+
tsk_bug_assert(lin != NULL);
1450+
1451+
hull = lin->hull;
1452+
u = lin->head;
1453+
label = lin->label;
1454+
pop = lin->population;
14531455
tsk_bug_assert(u != NULL);
14541456
hulls_left = &self->populations[pop].hulls_left[label];
14551457
coal_mass_index = &self->populations[pop].coal_mass_index[label];
@@ -1496,6 +1498,7 @@ msp_remove_hull(msp_t *self, hull_t *hull)
14961498
msp_free_avl_node(self, node);
14971499
msp_free_hullend(self, query_ptr, label);
14981500
msp_free_hull(self, hull, label);
1501+
lin->hull = NULL;
14991502
}
15001503

15011504
static inline int MSP_WARN_UNUSED
@@ -1513,7 +1516,7 @@ msp_insert_individual_hull(msp_t *self, lineage_t *lin)
15131516
goto out;
15141517
}
15151518
lin->hull = hull;
1516-
ret = msp_insert_hull(self, hull);
1519+
ret = msp_insert_hull(self, lin);
15171520
if (ret != 0) {
15181521
goto out;
15191522
}
@@ -2679,8 +2682,7 @@ msp_move_individual(msp_t *self, avl_node_t *node, avl_tree_t *source,
26792682
avl_unlink_node(source, node);
26802683
msp_free_avl_node(self, node);
26812684
if (self->model.type == MSP_MODEL_SMC_K) {
2682-
msp_remove_hull(self, ind->hull);
2683-
ind->hull = NULL;
2685+
msp_remove_hull(self, ind);
26842686
}
26852687

26862688
if (self->additional_nodes & MSP_NODE_IS_MIG_EVENT) {
@@ -4274,8 +4276,7 @@ msp_reset_memory_state(msp_t *self)
42744276
avl_unlink_node(&pop->ancestors[label], node);
42754277
msp_free_avl_node(self, node);
42764278
if (lin->hull != NULL) {
4277-
msp_remove_hull(self, lin->hull);
4278-
lin->hull = NULL;
4279+
msp_remove_hull(self, lin);
42794280
}
42804281
msp_free_lineage(self, lin);
42814282
}
@@ -7720,19 +7721,17 @@ msp_smc_k_common_ancestor_event(
77207721
remaining_mass--;
77217722
}
77227723
}
7723-
msp_remove_hull(self, x_hull);
7724-
msp_remove_hull(self, y_hull);
7724+
x_lin = x_hull->lineage;
7725+
y_lin = y_hull->lineage;
7726+
msp_remove_hull(self, x_lin);
7727+
msp_remove_hull(self, y_lin);
77257728

77267729
/* retrieve ancestors linked to both hulls */
77277730
avl = &self->populations[population_id].ancestors[label];
7728-
x_lin = x_hull->lineage;
7729-
x_lin->hull = NULL;
77307731
x = x_lin->head;
77317732
x_node = avl_search(avl, x_lin);
77327733
tsk_bug_assert(x_node != NULL);
77337734
avl_unlink_node(avl, x_node);
7734-
y_lin = y_hull->lineage;
7735-
y_lin->hull = NULL;
77367735
y = y_lin->head;
77377736
y_node = avl_search(avl, y_lin);
77387737
tsk_bug_assert(y_node != NULL);
@@ -8226,7 +8225,6 @@ msp_set_simulation_model(msp_t *self, int model)
82268225
if (self->model.free != NULL) {
82278226
self->model.free(&self->model);
82288227
}
8229-
/* printf("set_simulation_model %d -> %d\n", self->model.type, model); */
82308228

82318229
self->model.type = model;
82328230
self->get_common_ancestor_waiting_time = msp_std_get_common_ancestor_waiting_time;

lib/msprime.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ typedef struct {
102102
typedef struct hull_t_t {
103103
double left;
104104
double right;
105-
lineage_t *lineage; // TODO remove as part of refactoring */
105+
/* We need a reference back to the lineage because we index the hulls in
106+
* the smc_k. */
107+
lineage_t *lineage;
106108
size_t id;
107109
uint64_t count;
108110
uint64_t insertion_order;

0 commit comments

Comments
 (0)