ses_graph.c
authoryu.dongliang <18588496441@163.com>
Thu, 9 Nov 2023 19:03:57 +0000 (03:03 +0800)
committeryu.dongliang <18588496441@163.com>
Thu, 9 Nov 2023 19:03:57 +0000 (03:03 +0800)
ses_graph.c
ses_layout.c

index e45d6d322d6ed2585cd25048242e72b2f5498d97..f13b07477e8dc1265e14be497fd2b14299ec8199 100644 (file)
@@ -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;
 }
index c10ad17304da0102acb60bf57d0154329f563fa6..0833fc9896bcdcca670a83a7dc7e124da5180e73 100644 (file)
@@ -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++) {