From: yu.dongliang <18588496441@163.com> Date: Tue, 26 Sep 2023 07:17:02 +0000 (+0800) Subject: _topo_path_sort() X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=51ae7be48de654f3d7957d420185d4f36d9a85df;p=ses.git _topo_path_sort() --- diff --git a/ses_step_jr.c b/ses_step_jr.c index b8587d1..e1b52a3 100644 --- a/ses_step_jr.c +++ b/ses_step_jr.c @@ -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]; diff --git a/ses_step_topo.c b/ses_step_topo.c index 8366c6a..60886fc 100644 --- a/ses_step_topo.c +++ b/ses_step_topo.c @@ -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; }