return 0;
}
+int line_pair_cmp(const void* v0, const void* v1)
+{
+ const ses_line_pair_t* lp0 = v0;
+ const ses_line_pair_t* lp1 = v1;
+
+ if (lp0->n_components < lp1->n_components)
+ return 1;
+
+ if (lp0->n_components > lp1->n_components)
+ return -1;
+
+ if (lp0 < lp1)
+ return -1;
+
+ if (lp0 > lp1)
+ return 1;
+
+ return 0;
+}
+
int ses_pins_same_line(ScfEfunction* f, scf_vector_t* lines)
{
ScfEcomponent* c;
- ScfEline* l;
ScfEpin* p;
ScfEpin* p2;
- scf_vector_t* vec;
+ scf_vector_t* lv;
size_t i;
size_t j;
qsort(p->tos, p->n_tos / 2, sizeof(uint64_t) * 2, epin_cmp);
for (k = 0; k < lines->size; k++) {
- vec = lines->data[k];
+ lv = lines->data[k];
- for (m = 0; m < vec->size; m++) {
- p2 = vec->data[m];
+ for (m = 0; m < lv->size; m++) {
+ p2 = lv->data[m];
if (p2->cid == p->cid && p2->id == p->id) {
assert(p2 == p);
m = 0;
n = 0;
- while (m < vec->size && n + 1 < p->n_tos) {
- p2 = vec->data[m];
+ while (m < lv->size && n + 1 < p->n_tos) {
+ p2 = lv->data[m];
if (p2->cid < p->tos[n])
m++;
n += 2;
else {
- if (scf_vector_add(vec, p) < 0)
+ if (scf_vector_add(lv, p) < 0)
return -ENOMEM;
goto next;
}
}
- vec = scf_vector_alloc();
- if (!vec)
+ lv = scf_vector_alloc();
+ if (!lv)
return -ENOMEM;
- if (scf_vector_add(lines, vec) < 0) {
- scf_vector_free(vec);
+ if (scf_vector_add(lines, lv) < 0) {
+ scf_vector_free(lv);
return -ENOMEM;
}
- if (scf_vector_add(vec, p) < 0)
+ if (scf_vector_add(lv, p) < 0)
return -ENOMEM;
next:
p = NULL;
#if 1
for (i = 0; i < lines->size; i++) {
- vec = lines->data[i];
+ lv = lines->data[i];
- scf_logw("line i: %ld\n", i);
+ scf_logw("line i: %ld, %p\n", i, lv);
- for (j = 0; j < vec->size; j++) {
- p = vec->data[j];
+ for (j = 0; j < lv->size; j++) {
+ p = lv->data[j];
scf_logi("pin j: %ld, cid: %ld, pid: %ld\n", j, p->cid, p->id);
}
return 0;
}
+int ses_lines_same_components(scf_vector_t* lines, scf_vector_t* pairs)
+{
+ ses_line_pair_t* lp;
+ scf_vector_t* lv0;
+ scf_vector_t* lv1;
+
+ ScfEpin* p0;
+ ScfEpin* p1;
+
+ size_t i;
+ size_t j;
+ size_t k0;
+ size_t k1;
+ size_t n;
+
+ for (i = 0; i < lines->size - 1; i++) {
+ lv0 = lines->data[i];
+
+ for (j = i + 1; j < lines->size; j++) {
+ lv1 = lines->data[j];
+
+ n = 0;
+ k0 = 0;
+ k1 = 0;
+
+ while (k0 < lv0->size && k1 < lv1->size) {
+ p0 = lv0->data[k0];
+ p1 = lv1->data[k1];
+
+ if (p0->cid < p1->cid)
+ k0++;
+ else if (p0->cid > p1->cid)
+ k1++;
+ else {
+ k0++;
+ k1++;
+ n++;
+ }
+ }
+
+ if (0 == n)
+ continue;
+
+ lp = malloc(sizeof(ses_line_pair_t));
+ if (!lp)
+ return -ENOMEM;
+
+ if (scf_vector_add(pairs, lp) < 0) {
+ free(lp);
+ return -ENOMEM;
+ }
+
+ lp->lines[0] = lv0;
+ lp->lines[1] = lv1;
+ lp->n_components = n;
+ }
+ }
+
+ scf_vector_qsort(pairs, line_pair_cmp);
+
+#if 1
+ for (i = 0; i < pairs->size; i++) {
+ lp = pairs->data[i];
+
+ scf_logi("i: %ld, lv0: %p, lv1: %p, n_components: %ld\n",
+ i, lp->lines[0], lp->lines[1], lp->n_components);
+ }
+#endif
+}
+
int ses_layout_board(ScfEboard* b, int x, int y, int w, int h)
{
ScfEcomponent* c;
ScfEpin* p;
scf_vector_t* lines;
+ scf_vector_t* pairs;
size_t i;
size_t j;
if (!lines)
return -ENOMEM;
+ pairs = scf_vector_alloc();
+ if (!pairs) {
+ scf_vector_free(lines);
+ return -ENOMEM;
+ }
+
ses_pins_same_line(f, lines);
+
+ ses_lines_same_components(lines, pairs);
}
return 0;