From: yu.dongliang <18588496441@163.com> Date: Thu, 9 Nov 2023 19:03:57 +0000 (+0800) Subject: ses_graph.c X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=686b7baf0d014c8de347d6f95064ce5e5a0c9b23;p=ses.git ses_graph.c --- diff --git a/ses_graph.c b/ses_graph.c index e45d6d3..f13b074 100644 --- a/ses_graph.c +++ b/ses_graph.c @@ -385,5 +385,36 @@ int ses_graph_kcolor(ses_graph_t* graph, int k, scf_vector_t* colors) if (!graph || !colors || 0 == colors->size) return -EINVAL; - return __graph_kcolor(graph, k, colors); + int ret = __graph_kcolor(graph, k, colors); + if (ret < 0) + return ret; + + scf_vector_t* __colors = scf_vector_clone(colors); + if (!__colors) + return -ENOMEM; + + ses_vertex_t* v = NULL; + int i; + int j; + + for (i = 0; i < graph->size; i++) { + v = graph->data[i]; + + scf_vector_del(__colors, (void*)v->color); + } + + for (j = 0; j < __colors->size; j++) { + + for (i = 0; i < graph->size; i++) { + v = graph->data[i]; + + if (v->color < 0) { + v->color = (intptr_t)__colors->data[j]; + break; + } + } + } + + scf_vector_free(__colors); + return 0; } diff --git a/ses_layout.c b/ses_layout.c index c10ad17..0833fc9 100644 --- a/ses_layout.c +++ b/ses_layout.c @@ -1169,25 +1169,26 @@ static int __ses_de_cross(ScfEfunction* f, int d) scf_loge("**********\n"); } - int n = 0; - for (i = 0; i < graph->size; i++) { v = graph->data[i]; - c = v->data; - if (v->color < 0) { - c->color = j; - n++; scf_loge("j: %ld, i: %ld, c%ld->color: %ld\n", j, i, c->id, v->color); - } else - c->color = v->color; - v->color = 0; + break; + } } - if (n > 0) + if (i < graph->size) break; + for (i = 0; i < graph->size; i++) { + v = graph->data[i]; + + c = v->data; + c->color = v->color; + v->color = 0; + } + scf_vector_clear(colors, NULL); } @@ -1199,7 +1200,7 @@ static int __ses_de_cross(ScfEfunction* f, int d) int x1 = 0; - N = j; + N = j + 1; for (j = 1; j <= N; j++) {