From c837a21f9790102767490ef43ac54d5a5b75fa9e Mon Sep 17 00:00:00 2001 From: Christoph Mallon Date: Mon, 6 Oct 2008 07:20:35 +0000 Subject: [PATCH] Make reorder_node() more clear (at least to me). [r22512] --- heuristical.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/heuristical.c b/heuristical.c index 7605ffb58..973dc0360 100644 --- a/heuristical.c +++ b/heuristical.c @@ -158,9 +158,12 @@ static void normalize_towards_target(pbqp *pbqp, pbqp_edge *edge) static void reorder_node(pbqp_node *node) { - unsigned arity; - unsigned old_arity; - unsigned old_bucket_len; + unsigned arity; + unsigned old_arity; + unsigned old_bucket_len; + unsigned old_bucket_index; + pbqp_node **old_bucket; + pbqp_node *other; if (!buckets_filled) return; @@ -168,31 +171,34 @@ static void reorder_node(pbqp_node *node) arity = ARR_LEN(node->edges); - /* Equal bucket as before */ + /* Same bucket as before */ if (arity > 2) return; /* Assume node lost one incident edge. */ - old_arity = arity + 1; + old_arity = arity + 1; + old_bucket = node_buckets[old_arity]; + old_bucket_len = ARR_LEN(old_bucket); + old_bucket_index = node->bucket_index; - if (ARR_LEN(node_buckets[old_arity]) <= (int)node->bucket_index - || node_buckets[old_arity][node->bucket_index] != node) { + if (old_bucket_len <= old_bucket_index || + old_bucket[old_bucket_index] != node) { /* Old arity is new arity, so we have nothing to do. */ + assert(old_bucket_index < ARR_LEN(node_buckets[arity]) && + node_buckets[arity][old_bucket_index] == node); return; } - old_bucket_len = ARR_LEN(node_buckets[old_arity]); - assert (node_buckets[old_arity][node->bucket_index] == node); + assert(old_bucket[old_bucket_index] == node); /* Delete node from old bucket... */ - node_buckets[old_arity][old_bucket_len - 1]->bucket_index - = node->bucket_index; - node_buckets[old_arity][node->bucket_index] - = node_buckets[old_arity][old_bucket_len - 1]; - ARR_SHRINKLEN(node_buckets[old_arity], (int)old_bucket_len - 1); + other = old_bucket[old_bucket_len - 1]; + other->bucket_index = old_bucket_index; + old_bucket[old_bucket_index] = other; + ARR_SHRINKLEN(node_buckets[old_arity], old_bucket_len - 1); /* ..and add to new one. */ node->bucket_index = ARR_LEN(node_buckets[arity]); - ARR_APP1(pbqp_node *, node_buckets[arity], node); + ARR_APP1(pbqp_node*, node_buckets[arity], node); } static void simplify_edge(pbqp *pbqp, pbqp_edge *edge) -- 2.20.1