_topo_path_sort()
authoryu.dongliang <18588496441@163.com>
Tue, 26 Sep 2023 07:17:02 +0000 (15:17 +0800)
committeryu.dongliang <18588496441@163.com>
Tue, 26 Sep 2023 07:17:02 +0000 (15:17 +0800)
ses_step_jr.c
ses_step_topo.c

index b8587d1c36ea7d8130ed0f26cd8ff094aeacfe00..e1b52a3ec3745a71de59aba035fc3d3d237383b5 100644 (file)
@@ -1,7 +1,5 @@
 #include"ses_core.h"
 
-int _ses_path_cmp(const void* v0, const void* v1);
-
 static int __ses_path_jr(ScfEfunction* f, ses_path_t* path)
 {
        if (!path)
@@ -54,8 +52,6 @@ static int __ses_path_jr(ScfEfunction* f, ses_path_t* path)
 
        if (path->childs) {
 
-               scf_vector_qsort(path->childs, _ses_path_cmp);
-
                for (i    = path->childs->size - 1; i >= 0; i--) {
                        child = path->childs->data[i];
 
index 8366c6ad80083f047d75373c1b5198979e90923b..60886fc0472c1c546cc46a24277fdd4bd9550544 100644 (file)
@@ -1,6 +1,6 @@
 #include"ses_core.h"
 
-int _ses_path_cmp(const void* v0, const void* v1)
+static int _ses_path_cmp(const void* v0, const void* v1)
 {
        const ses_path_t* p0 = *(const ses_path_t**)v0;
        const ses_path_t* p1 = *(const ses_path_t**)v1;
@@ -162,6 +162,36 @@ int __dfs_path(ScfEfunction* f, ScfEcomponent* rc, ScfEpin* rp, scf_vector_t* __
        return ret;
 }
 
+static int _ses_child_cmp(const void* v0, const void* v1)
+{
+       const ses_path_t* p0 = *(const ses_path_t**)v0;
+       const ses_path_t* p1 = *(const ses_path_t**)v1;
+
+       if (p0->parent_p0 <= p1->parent_p0 && p0->parent_p1 >= p1->parent_p1)
+               return -1;
+
+       if (p0->parent_p0 >= p1->parent_p0 && p0->parent_p1 <= p1->parent_p1)
+               return 1;
+       return 0;
+}
+
+static void _topo_path_sort(ses_path_t* path)
+{
+       if (!path || !path->childs || path->childs->size <= 0)
+               return;
+
+       ses_path_t* child;
+       int i;
+
+       for (i = 0; i < path->childs->size; i++) {
+               child     = path->childs->data[i];
+
+               _topo_path_sort(child);
+       }
+
+       scf_vector_qsort(path->childs, _ses_child_cmp);
+}
+
 static int _topo_layers(scf_vector_t* paths)
 {
        ses_path_t*      child;
@@ -218,6 +248,12 @@ branch:
                }
        }
 
+       for (i = 0; i < paths->size; i++) {
+               child     = paths->data[i];
+
+               _topo_path_sort(child);
+       }
+
        return 0;
 }