/dgc-0.98/cube/dcube.c

# · C · 5900 lines · 4299 code · 777 blank · 824 comment · 1768 complexity · 3ee80781952e9c843ac71d24272cd8a3 MD5 · raw file

Large files are truncated click here to view the full file

  1. /*
  2. dynamic cube
  3. Copyright (C) 2001 Oliver Kraus (olikraus@yahoo.com)
  4. This file is part of DGC.
  5. DGC is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. DGC is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with DGC; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. /*! \defgroup dclist Sum of Product Management */
  18. #include <stdarg.h>
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <assert.h>
  23. #include "b_io.h"
  24. #include "b_ff.h"
  25. #include "dcube.h"
  26. #include "mcov.h"
  27. #include "mwc.h"
  28. #include "matrix.h"
  29. /*-- dcInSetAll -------------------------------------------------------------*/
  30. void dcInSetAll(pinfo *pi, dcube *c, c_int v)
  31. {
  32. int i;
  33. for( i = 0; i < pi->in_words; i++ )
  34. c->in[i] = v;
  35. }
  36. /*-- dcCopy -----------------------------------------------------------------*/
  37. void dcCopy(pinfo *pi, dcube *dest, dcube *src)
  38. {
  39. int i;
  40. for( i = 0; i < pi->in_out_words_min; i++ )
  41. {
  42. dest->in[i] = src->in[i];
  43. dest->out[i] = src->out[i];
  44. }
  45. for( i = pi->in_out_words_min; i < pi->in_words; i++ )
  46. dest->in[i] = src->in[i];
  47. for( i = pi->in_out_words_min; i < pi->out_words; i++ )
  48. dest->out[i] = src->out[i];
  49. dest->n = src->n;
  50. }
  51. /*-- dcCopyOut --------------------------------------------------------------*/
  52. void dcCopyOut(pinfo *pi, dcube *dest, dcube *src)
  53. {
  54. int i;
  55. for( i = 0; i < pi->out_words; i++ )
  56. dest->out[i] = src->out[i];
  57. }
  58. /*-- dcCopyIn ---------------------------------------------------------------*/
  59. void dcCopyIn(pinfo *pi, dcube *dest, dcube *src)
  60. {
  61. int i;
  62. for( i = 0; i < pi->in_words; i++ )
  63. dest->in[i] = src->in[i];
  64. }
  65. /*-- dcCopyInToIn -----------------------------------------------------------*/
  66. void dcCopyInToIn(pinfo *pi_dest, dcube *dest, int dest_offset, pinfo *pi_src, dcube *src)
  67. {
  68. int i;
  69. int s;
  70. for( i = 0; i < pi_src->in_cnt; i++ )
  71. {
  72. s = dcGetIn(src, i);
  73. dcSetIn(dest, i+dest_offset, s);
  74. }
  75. }
  76. /*-- dcCopyInToInRange ------------------------------------------------------*/
  77. void dcCopyInToInRange(pinfo *pi_dest, dcube *dest, int dest_offset,
  78. pinfo *pi_src, dcube *src, int src_offset, int src_cnt)
  79. {
  80. int i;
  81. int s;
  82. assert(src_offset+src_cnt <= pi_src->in_cnt);
  83. for( i = src_offset; i < src_offset+src_cnt; i++ )
  84. {
  85. s = dcGetIn(src, i);
  86. dcSetIn(dest, i+dest_offset-src_offset, s);
  87. }
  88. }
  89. /*-- dcCopyOutToIn ----------------------------------------------------------*/
  90. void dcCopyOutToIn(pinfo *pi_dest, dcube *dest, int dest_offset, pinfo *pi_src, dcube *src)
  91. {
  92. int i;
  93. int s;
  94. for( i = 0; i < pi_src->out_cnt; i++ )
  95. {
  96. s = dcGetOut(src, i) + 1;
  97. dcSetIn(dest, i+dest_offset, s);
  98. }
  99. }
  100. /*-- dcCopyOutToInRange -----------------------------------------------------*/
  101. void dcCopyOutToInRange(pinfo *pi_dest, dcube *dest, int dest_offset,
  102. pinfo *pi_src, dcube *src, int src_offset, int src_cnt)
  103. {
  104. int i;
  105. int s;
  106. assert(src_offset+src_cnt <= pi_src->in_cnt);
  107. for( i = src_offset; i < src_offset+src_cnt; i++ )
  108. {
  109. s = dcGetOut(src, i) + 1;
  110. dcSetIn(dest, i+dest_offset-src_offset, s);
  111. }
  112. }
  113. /*-- dcCopyInToOut ----------------------------------------------------------*/
  114. void dcCopyInToOut(pinfo *pi_dest, dcube *dest, int dest_offset, pinfo *pi_src, dcube *src)
  115. {
  116. int i;
  117. int s;
  118. for( i = 0; i < pi_src->in_cnt; i++ )
  119. {
  120. s = dcGetIn(src, i) - 1;
  121. dcSetOut(dest, i+dest_offset, s);
  122. }
  123. }
  124. /*-- dcCopyInToOutRange -----------------------------------------------------*/
  125. void dcCopyInToOutRange(pinfo *pi_dest, dcube *dest, int dest_offset,
  126. pinfo *pi_src, dcube *src, int src_offset, int src_cnt)
  127. {
  128. int i;
  129. int s;
  130. assert(src_offset+src_cnt <= pi_src->in_cnt);
  131. for( i = src_offset; i < src_offset+src_cnt; i++ )
  132. {
  133. s = dcGetIn(src, i) - 1;
  134. dcSetOut(dest, i+dest_offset-src_offset, s);
  135. }
  136. }
  137. /*-- dcCopyOutToOut ---------------------------------------------------------*/
  138. void dcCopyOutToOut(pinfo *pi_dest, dcube *dest, int dest_offset,
  139. pinfo *pi_src, dcube *src)
  140. {
  141. int i, cnt;
  142. int s;
  143. cnt = pi_src->out_cnt;
  144. if ( cnt > pi_dest->out_cnt-dest_offset )
  145. cnt = pi_dest->out_cnt-dest_offset;
  146. for( i = 0; i < cnt; i++ )
  147. {
  148. s = dcGetOut(src, i);
  149. dcSetOut(dest, i+dest_offset, s);
  150. }
  151. }
  152. /*-- dcCopyOutToOutRange ----------------------------------------------------*/
  153. void dcCopyOutToOutRange(pinfo *pi_dest, dcube *dest, int dest_offset,
  154. pinfo *pi_src, dcube *src, int src_offset, int src_cnt)
  155. {
  156. int i;
  157. int s;
  158. assert(src_offset+src_cnt <= pi_src->out_cnt);
  159. assert(dest_offset+src_cnt < pi_dest->out_cnt);
  160. for( i = src_offset; i < src_offset+src_cnt; i++ )
  161. {
  162. s = dcGetOut(src, i);
  163. dcSetOut(dest, i+dest_offset-src_offset, s);
  164. }
  165. }
  166. /*-- dcOutSetAll ------------------------------------------------------------*/
  167. void dcOutSetAll(pinfo *pi, dcube *c, c_int v)
  168. {
  169. int i;
  170. for( i = 0; i < pi->out_words; i++ )
  171. c->out[i] = v;
  172. }
  173. /*-- dcAllClear -------------------------------------------------------------*/
  174. void dcAllClear(pinfo *pi, dcube *c)
  175. {
  176. dcInSetAll(pi, c, 0);
  177. dcOutSetAll(pi, c, 0);
  178. }
  179. /*-- dcSetTautology ---------------------------------------------------------*/
  180. void dcSetTautology(pinfo *pi, dcube *c)
  181. {
  182. dcInSetAll(pi, c, CUBE_IN_MASK_DC);
  183. dcOutSetAll(pi, c, CUBE_OUT_MASK);
  184. if ( pi->out_words > 0 )
  185. c->out[pi->out_words-1] = pi->out_last_mask;
  186. }
  187. /*-- dcSetOutTautology ------------------------------------------------------*/
  188. void dcSetOutTautology(pinfo *pi, dcube *c)
  189. {
  190. dcOutSetAll(pi, c, CUBE_OUT_MASK);
  191. if ( pi->out_words > 0 )
  192. c->out[pi->out_words-1] = pi->out_last_mask;
  193. }
  194. /*-- dcInitMem --------------------------------------------------------------*/
  195. int dcInitMem(pinfo *pi, dcube *c)
  196. {
  197. c->in = NULL;
  198. c->out = NULL;
  199. return dcAdjustByPinfo(pi, c);
  200. }
  201. /*-- dcInit -----------------------------------------------------------------*/
  202. int dcInit(pinfo *pi, dcube *c)
  203. {
  204. c->in = NULL;
  205. c->out = NULL;
  206. if ( dcAdjustByPinfo(pi, c) == 0 )
  207. return 0;
  208. dcInSetAll(pi, c, CUBE_IN_MASK_DC);
  209. dcOutSetAll(pi, c, 0);
  210. c->n = 0;
  211. return 1;
  212. }
  213. /*-- dcInitVA --------------------------------------------------------------*/
  214. int dcInitVA(pinfo *pi, int n, ...)
  215. {
  216. va_list va;
  217. int i;
  218. va_start(va, n);
  219. for( i = 0; i < n; i++ )
  220. if ( dcInit(pi, va_arg(va, dcube *)) == 0 )
  221. break;
  222. va_end(va);
  223. if ( i < n )
  224. {
  225. va_start(va, n);
  226. while( i-- >= 0 )
  227. dcDestroy(va_arg(va, dcube *));
  228. va_end(va);
  229. return 0;
  230. }
  231. return 1;
  232. }
  233. /*-- dcDestroy --------------------------------------------------------------*/
  234. void dcDestroy(dcube *c)
  235. {
  236. if ( c->in != NULL )
  237. free(c->in);
  238. if ( c->out != NULL )
  239. free(c->out);
  240. c->in = NULL;
  241. c->out = NULL;
  242. }
  243. /*-- dcDestroyVA ------------------------------------------------------------*/
  244. void dcDestroyVA(int n, ...)
  245. {
  246. va_list va;
  247. int i;
  248. va_start(va, n);
  249. for( i = 0; i < n; i++ )
  250. dcDestroy(va_arg(va, dcube *));
  251. va_end(va);
  252. }
  253. /*-- dcAdjust ---------------------------------------------------------------*/
  254. int dcAdjust(dcube *c, int in_words, int out_words)
  255. {
  256. void *ptr;
  257. if ( in_words == 0 )
  258. {
  259. if ( c->in != NULL )
  260. free(c->in);
  261. c->in = NULL;
  262. }
  263. else
  264. {
  265. if ( c->in == NULL )
  266. ptr = malloc(sizeof(c_int)*in_words);
  267. else
  268. ptr = realloc(c->in, sizeof(c_int)*in_words);
  269. if ( ptr == NULL )
  270. return 0;
  271. c->in = (c_int *)ptr;
  272. }
  273. if ( out_words == 0 )
  274. {
  275. if ( c->out != NULL )
  276. free(c->out);
  277. c->out = NULL;
  278. }
  279. else
  280. {
  281. if ( c->out == NULL )
  282. ptr = malloc(sizeof(c_int)*out_words);
  283. else
  284. ptr = realloc(c->out, sizeof(c_int)*out_words);
  285. if ( ptr == NULL )
  286. return 0;
  287. c->out = (c_int *)ptr;
  288. }
  289. return 1;
  290. }
  291. /*-- dcAdjustByPinfo --------------------------------------------------------*/
  292. int dcAdjustByPinfo(pinfo *pi, dcube *c)
  293. {
  294. return dcAdjust(c, pi->in_words, pi->out_words);
  295. }
  296. /*-- dcAdjustByPinfoVA ------------------------------------------------------*/
  297. int dcAdjustByPinfoVA(pinfo *pi, int n, ...)
  298. {
  299. va_list va;
  300. int i;
  301. va_start(va, n);
  302. for( i = 0; i < n; i++ )
  303. if ( dcAdjustByPinfo(pi, va_arg(va, dcube *)) == 0 )
  304. {
  305. va_end(va);
  306. return 0;
  307. }
  308. va_end(va);
  309. return 1;
  310. }
  311. /*-- dcSetIn ----------------------------------------------------------------*/
  312. void dcSetIn(dcube *c, int pos, int code)
  313. {
  314. c->in[pos/CUBE_SIGNALS_PER_IN_WORD] &= ~(3<<((pos&(CUBE_SIGNALS_PER_IN_WORD-1))*2));
  315. c->in[pos/CUBE_SIGNALS_PER_IN_WORD] |= code<<((pos&(CUBE_SIGNALS_PER_IN_WORD-1))*2);
  316. }
  317. /*-- dcGetIn ----------------------------------------------------------------*/
  318. int dcGetIn(dcube *c, int pos)
  319. {
  320. return (c->in[pos/CUBE_SIGNALS_PER_IN_WORD] >>
  321. ((pos&(CUBE_SIGNALS_PER_IN_WORD-1))*2)) & 3;
  322. }
  323. /*-- dcSetOut ---------------------------------------------------------------*/
  324. void dcSetOut(dcube *c, int pos, int code)
  325. {
  326. c->out[pos/CUBE_SIGNALS_PER_OUT_WORD] &= ~(1<<(pos&(CUBE_SIGNALS_PER_OUT_WORD-1)));
  327. c->out[pos/CUBE_SIGNALS_PER_OUT_WORD] |= (code<<(pos&(CUBE_SIGNALS_PER_OUT_WORD-1)));
  328. }
  329. /*-- dcGetOut ----------------------------------------------------------------*/
  330. int dcGetOut(dcube *c, int pos)
  331. {
  332. return (c->out[pos/CUBE_SIGNALS_PER_OUT_WORD] >>
  333. (pos&(CUBE_SIGNALS_PER_OUT_WORD-1))) & 1;
  334. }
  335. /*-- dcSetByStr -------------------------------------------------------------*/
  336. int dcSetByStr(pinfo *pi, dcube *c, char *str)
  337. {
  338. size_t i = 0;
  339. if ( dcAdjustByPinfo(pi, c) == 0 )
  340. return 0;
  341. dcInSetAll(pi, c, CUBE_IN_MASK_DC);
  342. dcOutSetAll(pi, c, 0);
  343. while( i < pi->in_cnt )
  344. switch(*str++)
  345. {
  346. case '0': dcSetIn(c, i++, 1); break;
  347. case '1': dcSetIn(c, i++, 2); break;
  348. case '-': dcSetIn(c, i++, 3); break;
  349. case '\0': return 0;
  350. }
  351. i = 0;
  352. while( i < pi->out_cnt )
  353. switch(*str++)
  354. {
  355. case '0': dcSetOut(c, i++, 0); break;
  356. case '1': dcSetOut(c, i++, 1); break;
  357. case '\0': return 0;
  358. }
  359. return 1;
  360. }
  361. /*-- dcSetInByStr -----------------------------------------------------------*/
  362. int dcSetInByStr(pinfo *pi, dcube *c, char *str)
  363. {
  364. size_t i = 0;
  365. if ( dcAdjustByPinfo(pi, c) == 0 )
  366. return 0;
  367. dcInSetAll(pi, c, CUBE_IN_MASK_DC);
  368. i = 0;
  369. while( i < pi->in_cnt )
  370. switch(*str++)
  371. {
  372. case '0': dcSetIn(c, i++, 1); break;
  373. case '1': dcSetIn(c, i++, 2); break;
  374. case '-': dcSetIn(c, i++, 3); break;
  375. case '\0': return 0;
  376. }
  377. return 1;
  378. }
  379. /*-- dcSetOutByStr ----------------------------------------------------------*/
  380. int dcSetOutByStr(pinfo *pi, dcube *c, char *str)
  381. {
  382. size_t i = 0;
  383. if ( dcAdjustByPinfo(pi, c) == 0 )
  384. return 0;
  385. dcInSetAll(pi, c, 0);
  386. i = 0;
  387. while( i < pi->out_cnt )
  388. switch(*str++)
  389. {
  390. case '0': dcSetOut(c, i++, 0); break;
  391. case '1': dcSetOut(c, i++, 1); break;
  392. case '\0': return 0;
  393. }
  394. return 1;
  395. }
  396. /*-- dcSetAllByStr ----------------------------------------------------------*/
  397. /* dcSetAllByStr ... dcSetAllByStrPtr */
  398. char *dcSetAllByStr(pinfo *pi, int in_cnt, int out_cnt, dcube *c_on, dcube *c_dc, char *str)
  399. {
  400. size_t i = 0;
  401. if ( dcAdjustByPinfo(pi, c_on) == 0 )
  402. return NULL;
  403. if ( dcAdjustByPinfo(pi, c_dc) == 0 )
  404. return NULL;
  405. dcInSetAll(pi, c_on, CUBE_IN_MASK_DC);
  406. dcOutSetAll(pi, c_on, 0);
  407. dcInSetAll(pi, c_dc, CUBE_IN_MASK_DC);
  408. dcOutSetAll(pi, c_dc, 0);
  409. while( i < in_cnt )
  410. {
  411. switch(*str++)
  412. {
  413. case '0': dcSetIn(c_on, i, 1); dcSetIn(c_dc, i, 1); i++; break;
  414. case '1': dcSetIn(c_on, i, 2); dcSetIn(c_dc, i, 2); i++; break;
  415. case '-': dcSetIn(c_on, i, 3); dcSetIn(c_dc, i, 3); i++; break;
  416. case '\0': return 0;
  417. }
  418. }
  419. i = 0;
  420. while( i < out_cnt )
  421. {
  422. switch(*str)
  423. {
  424. case '0': dcSetOut(c_on, i, 0); dcSetOut(c_dc, i, 0); i++; break;
  425. case '1': dcSetOut(c_on, i, 1); dcSetOut(c_dc, i, 0); i++; break;
  426. case '2': dcSetOut(c_on, i, 0); dcSetOut(c_dc, i, 1); i++; break;
  427. case '-': dcSetOut(c_on, i, 0); dcSetOut(c_dc, i, 1); i++; break;
  428. case '\0': return 0;
  429. default:
  430. if ( *str >= 'a' && *str <= 'z' )
  431. return 0;
  432. if ( *str >= 'A' && *str <= 'Z' )
  433. return 0;
  434. if ( *str == '_' )
  435. return 0;
  436. }
  437. str++;
  438. }
  439. return str;
  440. }
  441. /*-- dcToStr ----------------------------------------------------------------*/
  442. char *dcToStr(pinfo *pi, dcube *c, char *sep, char *post)
  443. {
  444. static char s[1024*8];
  445. int i, l;
  446. for( i = 0; i < pi->in_cnt; i++ )
  447. s[i] = "x01-"[dcGetIn(c, i)];
  448. strcpy(s+pi->in_cnt, sep);
  449. l = pi->in_cnt+strlen(sep);
  450. for( i = 0; i < pi->out_cnt; i++ )
  451. s[i+l] = "01"[dcGetOut(c, i)];
  452. strcpy(s+l+pi->out_cnt, post);
  453. return s;
  454. }
  455. char *dcToStr2(pinfo *pi, dcube *c, char *sep, char *post)
  456. {
  457. static char s[1024*8];
  458. int i, l;
  459. for( i = 0; i < pi->in_cnt; i++ )
  460. s[i] = "x01-"[dcGetIn(c, i)];
  461. strcpy(s+pi->in_cnt, sep);
  462. l = pi->in_cnt+strlen(sep);
  463. for( i = 0; i < pi->out_cnt; i++ )
  464. s[i+l] = "01"[dcGetOut(c, i)];
  465. strcpy(s+l+pi->out_cnt, post);
  466. return s;
  467. }
  468. char *dcToStr3(pinfo *pi, dcube *c, char *sep, char *post)
  469. {
  470. static char s[1024*8];
  471. int i, l;
  472. for( i = 0; i < pi->in_cnt; i++ )
  473. s[i] = "x01-"[dcGetIn(c, i)];
  474. strcpy(s+pi->in_cnt, sep);
  475. l = pi->in_cnt+strlen(sep);
  476. for( i = 0; i < pi->out_cnt; i++ )
  477. s[i+l] = "01"[dcGetOut(c, i)];
  478. strcpy(s+l+pi->out_cnt, post);
  479. return s;
  480. }
  481. /*-- dcOutToStr -------------------------------------------------------------*/
  482. char *dcOutToStr(pinfo *pi, dcube *c, char *post)
  483. {
  484. static char s[1024*16];
  485. int i;
  486. for( i = 0; i < pi->out_cnt; i++ )
  487. s[i] = "01"[dcGetOut(c, i)];
  488. strcpy(s+pi->out_cnt, post);
  489. return s;
  490. }
  491. /*-- dcInToStr --------------------------------------------------------------*/
  492. char *dcInToStr(pinfo *pi, dcube *c, char *post)
  493. {
  494. static char s[1024*16];
  495. int i, l;
  496. for( i = 0; i < pi->in_cnt; i++ )
  497. s[i] = "x01-"[dcGetIn(c, i)];
  498. strcpy(s+pi->in_cnt, post);
  499. return s;
  500. }
  501. /*-- dcInc ------------------------------------------------------------------*/
  502. /* assume that there are no don't cares */
  503. /* interpret the cube as a binary number and add 1 */
  504. /* returns 0 if there was a overflow */
  505. int dcInc(pinfo *pi, dcube *c)
  506. {
  507. int i = 0;
  508. for(;;)
  509. {
  510. if ( dcGetIn(c, i) == 1 )
  511. {
  512. dcSetIn(c, i, 2);
  513. break;
  514. }
  515. else
  516. {
  517. dcSetIn(c, i, 1);
  518. i++;
  519. }
  520. if ( i >= pi->in_cnt )
  521. return 0;
  522. }
  523. return 1;
  524. }
  525. /*-- dcIncOut ---------------------------------------------------------------*/
  526. /* assume that there are no don't cares */
  527. /* interpret the cube as a binary number and add 1 */
  528. /* returns 0 if there was a overflow */
  529. int dcIncOut(pinfo *pi, dcube *c)
  530. {
  531. int i = 0;
  532. for(;;)
  533. {
  534. if ( dcGetOut(c, i) == 0 )
  535. {
  536. dcSetOut(c, i, 1);
  537. break;
  538. }
  539. else
  540. {
  541. dcSetOut(c, i, 0);
  542. i++;
  543. }
  544. if ( i >= pi->out_cnt )
  545. return 0;
  546. }
  547. return 1;
  548. }
  549. /*-- dcIsEqualIn ------------------------------------------------------------*/
  550. int dcIsEqualIn(pinfo *pi, dcube *a, dcube *b)
  551. {
  552. register int i;
  553. for( i = 0; i < pi->in_words; i++ )
  554. if ( a->in[i] != b->in[i] )
  555. return 0;
  556. return 1;
  557. }
  558. /*-- dcIsEqualOut -----------------------------------------------------------*/
  559. int dcIsEqualOut(pinfo *pi, dcube *a, dcube *b)
  560. {
  561. register int i;
  562. for( i = 0; i < pi->out_words; i++ )
  563. if ( a->out[i] != b->out[i] )
  564. return 0;
  565. return 1;
  566. }
  567. /*-- dcIsEqualOutCnt --------------------------------------------------------*/
  568. int dcIsEqualOutCnt(dcube *a, dcube *b, int off, int cnt)
  569. {
  570. register int i;
  571. for( i = off; i < off+cnt; i++ )
  572. if ( dcGetOut(a, i) != dcGetOut(b, i) )
  573. return 0;
  574. return 1;
  575. }
  576. /*-- dcIsEqualOutRange ------------------------------------------------------*/
  577. int dcIsEqualOutRange(dcube *a, int off_a, dcube *b, int off_b, int cnt)
  578. {
  579. register int i;
  580. for( i = 0; i < cnt; i++ )
  581. if ( dcGetOut(a, i+off_a) != dcGetOut(b, i+off_b) )
  582. return 0;
  583. return 1;
  584. }
  585. /*-- dcIsEqual --------------------------------------------------------------*/
  586. int dcIsEqual(pinfo *pi, dcube *a, dcube *b)
  587. {
  588. register int i;
  589. for( i = 0; i < pi->in_words; i++ )
  590. if ( a->in[i] != b->in[i] )
  591. return 0;
  592. for( i = 0; i < pi->out_words; i++ )
  593. if ( a->out[i] != b->out[i] )
  594. return 0;
  595. return 1;
  596. }
  597. /*-- dcIntersection ---------------------------------------------------------*/
  598. int dcIntersectionOld(pinfo *pi, dcube *r, dcube *a, dcube *b)
  599. {
  600. register int i;
  601. if ( dcDeltaOut(pi, a, b) > 0 )
  602. return 0;
  603. if ( dcIsDeltaInNoneZero(pi, a, b) > 0 )
  604. return 0;
  605. for( i = 0; i < pi->in_words; i++ )
  606. r->in[i] = a->in[i] & b->in[i];
  607. for( i = 0; i < pi->out_words; i++ )
  608. r->out[i] = a->out[i] & b->out[i];
  609. return 1;
  610. }
  611. int dcIntersection(pinfo *pi, dcube *r, dcube *a, dcube *b)
  612. {
  613. register int i;
  614. register c_int c;
  615. for( i = 0; i < pi->in_words; i++ )
  616. {
  617. c = a->in[i] & b->in[i]; /* Problem: Wie oft kommt 00 vor? */
  618. r->in[i] = c;
  619. c |= c>>1; /* Reduktion: Wie oft kommt x0 vor? */
  620. c = ~c; /* Invertierung: Wie oft kommt x1 vor? */
  621. c &= CUBE_IN_MASK_ZERO; /* Maskierung: Wie oft kommt 01 vor? */
  622. if ( c > 0 )
  623. return 0;
  624. }
  625. if ( pi->out_cnt == 0 )
  626. return 1;
  627. c = 0;
  628. for( i = 0; i < pi->out_words; i++ )
  629. {
  630. r->out[i] = a->out[i] & b->out[i];
  631. c |= r->out[i];
  632. }
  633. if ( c == 0 )
  634. return 0;
  635. return 1;
  636. }
  637. /*-- dcIsInSubSet -----------------------------------------------------------*/
  638. /* Ist der Eingangs-Teil von b Teilmenge vom Eingangs-Teil von a? */
  639. /* Ja: Rueckgabe ist 1, nein: Rueckgabe ist 0 */
  640. int dcIsInSubSet(pinfo *pi, dcube *a, dcube *b)
  641. {
  642. register int i;
  643. for( i = 0; i < pi->in_words; i++ )
  644. if ( (a->in[i] & b->in[i]) != b->in[i] )
  645. return 0;
  646. return 1;
  647. }
  648. /*-- dcIsOutSubSet ----------------------------------------------------------*/
  649. /* Ist der Eingangs-Teil von b Teilmenge vom Eingangs-Teil von a? */
  650. /* Ja: Rueckgabe ist 1, nein: Rueckgabe ist 0 */
  651. int dcIsOutSubSet(pinfo *pi, dcube *a, dcube *b)
  652. {
  653. register int i;
  654. for( i = 0; i < pi->out_words; i++ )
  655. if ( (a->out[i] & b->out[i]) != b->out[i] )
  656. return 0;
  657. return 1;
  658. }
  659. /*-- dcIsSubSet -------------------------------------------------------------*/
  660. /* Ist b Teilmenge von a? */
  661. /* Ja: Rueckgabe ist 1, nein: Rueckgabe ist 0 */
  662. int dcIsSubSetReadable(pinfo *pi, dcube *a, dcube *b)
  663. {
  664. register int i;
  665. for( i = 0; i < pi->in_words; i++ )
  666. if ( (a->in[i] & b->in[i]) != b->in[i] )
  667. return 0;
  668. for( i = 0; i < pi->out_words; i++ )
  669. if ( (a->out[i] & b->out[i]) != b->out[i] )
  670. return 0;
  671. return 1;
  672. }
  673. int dcIsSubSet(pinfo *pi, dcube *a, dcube *b)
  674. {
  675. register int i;
  676. for( i = 0; i < pi->in_out_words_min; i++ )
  677. {
  678. if ( (~a->in[i] & b->in[i]) != 0 )
  679. return 0;
  680. if ( (~a->out[i] & b->out[i]) != 0 )
  681. return 0;
  682. }
  683. for( i = pi->in_out_words_min; i < pi->in_words; i++ )
  684. if ( (~a->in[i] & b->in[i]) != 0 )
  685. return 0;
  686. for( i = pi->in_out_words_min; i < pi->out_words; i++ )
  687. if ( (~a->out[i] & b->out[i]) != 0 )
  688. return 0;
  689. return 1;
  690. }
  691. int dcIsSubSet4(pinfo *pi, dcube *a1, dcube *a2, dcube *a3, dcube *a4, dcube *b)
  692. {
  693. register int i;
  694. register c_int r1, r2, r3, r4;
  695. r1 = 0;
  696. r2 = 0;
  697. r3 = 0;
  698. r4 = 0;
  699. for( i = 0; i < pi->in_words; i++ )
  700. {
  701. r1 |= (~a1->in[i] & b->in[i]);
  702. r2 |= (~a2->in[i] & b->in[i]);
  703. r3 |= (~a3->in[i] & b->in[i]);
  704. r4 |= (~a4->in[i] & b->in[i]);
  705. if ( r1 != 0 && r2 != 0 && r3 != 0 && r4 != 0 )
  706. return 0;
  707. }
  708. for( i = 0; i < pi->out_words; i++ )
  709. {
  710. r1 |= (~a1->out[i] & b->out[i]);
  711. r2 |= (~a2->out[i] & b->out[i]);
  712. r3 |= (~a3->out[i] & b->out[i]);
  713. r4 |= (~a4->out[i] & b->out[i]);
  714. if ( r1 != 0 && r2 != 0 && r3 != 0 && r4 != 0 )
  715. return 0;
  716. }
  717. return 1;
  718. }
  719. int dcIsSubSet6n(pinfo *pi, dcube *a, dcube *b1, dcube *b2, dcube *b3, dcube *b4, dcube *b5, dcube *b6)
  720. {
  721. register int i;
  722. register c_int r1, r2, r3, r4, r5, r6;
  723. register c_int aw;
  724. r1 = 0;
  725. r2 = 0;
  726. r3 = 0;
  727. r4 = 0;
  728. r5 = 0;
  729. r6 = 0;
  730. for( i = 0; i < pi->in_words; i++ )
  731. {
  732. aw = ~a->in[i];
  733. r1 |= (aw & b1->in[i]);
  734. r2 |= (aw & b2->in[i]);
  735. r3 |= (aw & b3->in[i]);
  736. r4 |= (aw & b4->in[i]);
  737. r5 |= (aw & b5->in[i]);
  738. r6 |= (aw & b6->in[i]);
  739. if ( r1 != 0 && r2 != 0 && r3 != 0 && r4 != 0 && r5 != 0 && r6 != 0 )
  740. return 0;
  741. }
  742. for( i = 0; i < pi->out_words; i++ )
  743. {
  744. aw = ~a->out[i];
  745. r1 |= (aw & b1->out[i]);
  746. r2 |= (aw & b2->out[i]);
  747. r3 |= (aw & b3->out[i]);
  748. r4 |= (aw & b4->out[i]);
  749. r5 |= (aw & b5->out[i]);
  750. r6 |= (aw & b6->out[i]);
  751. if ( r1 != 0 && r2 != 0 && r3 != 0 && r4 != 0 && r5 != 0 && r6 != 0 )
  752. return 0;
  753. }
  754. return 1;
  755. }
  756. /*-- dcInDCCnt --------------------------------------------------------------*/
  757. int dcInDCCnt(pinfo *pi, dcube *cube)
  758. {
  759. register c_int c;
  760. register int bc = 0;
  761. register int i;
  762. for( i = 0; i < pi->in_words; i++ )
  763. {
  764. c = cube->in[i]; /* Problem: Wie oft kommt 11 vor? */
  765. c = ~c; /* Problem: Wie oft kommt 00 vor? */
  766. c |= c>>1; /* Reduktion: Wie oft kommt x0 vor? */
  767. c = ~c; /* Invertierung: Wie oft kommt x1 vor? */
  768. c &= CUBE_IN_MASK_ZERO; /* Maskierung: Wie oft kommt 01 vor? */
  769. bc += bitcount(c);
  770. }
  771. if ( ((pi->in_cnt)&(CUBE_SIGNALS_PER_IN_WORD-1)) != 0 )
  772. bc -= CUBE_SIGNALS_PER_IN_WORD-((pi->in_cnt)&(CUBE_SIGNALS_PER_IN_WORD-1));
  773. return bc;
  774. }
  775. /*-- dcInDCMask--------------------------------------------------------------*/
  776. void dcInDCMask(pinfo *pi, dcube *cube)
  777. {
  778. register c_int c;
  779. register int i;
  780. for( i = 0; i < pi->in_words; i++ )
  781. {
  782. c = cube->in[i]; /* Problem: Wie oft kommt 11 vor? */
  783. c &= c>>1; /* Reduktion: Wie oft kommt x1 vor? */
  784. c &= CUBE_IN_MASK_ZERO; /* Maskierung: Wie oft kommt 01 vor? */
  785. c |= c<<1;
  786. cube->in[i] = c;
  787. }
  788. }
  789. /*-- dcInZeroCnt ------------------------------------------------------------*/
  790. int dcInZeroCnt(pinfo *pi, dcube *cube)
  791. {
  792. register c_int c;
  793. register int bc = 0;
  794. register int i;
  795. for( i = 0; i < pi->in_words; i++ )
  796. {
  797. c = cube->in[i]; /* Problem: Wie oft kommt 11 vor? */
  798. c = ~c; /* Problem: Wie oft kommt 00 vor? */
  799. c |= c>>1; /* Reduktion: Wie oft kommt x0 vor? */
  800. c = ~c; /* Invertierung: Wie oft kommt x1 vor? */
  801. c &= CUBE_IN_MASK_ZERO; /* Maskierung: Wie oft kommt 01 vor? */
  802. c |= c<<1;
  803. c = cube->in[i] & ~c;
  804. c &= CUBE_IN_MASK_ZERO; /* Maskierung: Wie oft kommt 01 vor? */
  805. bc += bitcount(c);
  806. }
  807. return bc;
  808. }
  809. /*-- dcInOneCnt -------------------------------------------------------------*/
  810. int dcInOneCnt(pinfo *pi, dcube *cube)
  811. {
  812. register c_int c;
  813. register int bc = 0;
  814. register int i;
  815. for( i = 0; i < pi->in_words; i++ )
  816. {
  817. c = cube->in[i]; /* Problem: Wie oft kommt 11 vor? */
  818. c = ~c; /* Problem: Wie oft kommt 00 vor? */
  819. c |= c>>1; /* Reduktion: Wie oft kommt x0 vor? */
  820. c = ~c; /* Invertierung: Wie oft kommt x1 vor? */
  821. c &= CUBE_IN_MASK_ZERO; /* Maskierung: Wie oft kommt 01 vor? */
  822. c |= c<<1;
  823. c = cube->in[i] & ~c;
  824. c = c>>1;
  825. c &= CUBE_IN_MASK_ZERO; /* Maskierung: Wie oft kommt 01 vor? */
  826. bc += bitcount(c);
  827. }
  828. return bc;
  829. }
  830. /*-- dcDeltaIn --------------------------------------------------------------*/
  831. int dcDeltaIn(pinfo *pi, dcube *a, dcube *b)
  832. {
  833. register c_int c;
  834. register int bc = 0;
  835. register int i;
  836. for( i = 0; i < pi->in_words; i++ )
  837. {
  838. c = a->in[i] & b->in[i]; /* Problem: Wie oft kommt 00 vor? */
  839. c |= c>>1; /* Reduktion: Wie oft kommt x0 vor? */
  840. c = ~c; /* Invertierung: Wie oft kommt x1 vor? */
  841. c &= CUBE_IN_MASK_ZERO; /* Maskierung: Wie oft kommt 01 vor? */
  842. bc += bitcount(c);
  843. }
  844. return bc;
  845. }
  846. /*-- dcOutCnt ---------------------------------------------------------------*/
  847. int dcOutCnt(pinfo *pi, dcube *c)
  848. {
  849. register int i;
  850. register int bc = 0;
  851. for( i = 0; i < pi->out_words; i++ )
  852. bc += bitcount(c->out[i]);
  853. return bc;
  854. }
  855. /*-- dcInvIn ----------------------------------------------------------------*/
  856. int dcInvIn(pinfo *pi, dcube *cube)
  857. {
  858. register c_int c;
  859. register int i;
  860. for( i = 0; i < pi->in_words; i++ )
  861. {
  862. c = cube->in[i]; /* Problem: Wie oft kommt 11 vor? */
  863. c &= c>>1; /* Reduktion: Wie oft kommt x1 vor? */
  864. c &= CUBE_IN_MASK_ZERO; /* Maskierung: Wie oft kommt 01 vor? */
  865. c |= c<<1; /* neue maske: 11 */
  866. cube->in[i] = ((~cube->in[i]) | c); /* 01 -> 10, 10 -> 01, 11 -> 11 */
  867. }
  868. return 0;
  869. }
  870. /*-- dcInvOut ---------------------------------------------------------------*/
  871. void dcInvOut(pinfo *pi, dcube *c)
  872. {
  873. register int i;
  874. for( i = 0; i < pi->out_words; i++ )
  875. c->out[i] = ~c->out[i];
  876. if ( pi->out_words > 0 )
  877. c->out[pi->out_words-1] &= pi->out_last_mask;
  878. }
  879. /*-- dcDeltaOut -------------------------------------------------------------*/
  880. int dcDeltaOut(pinfo *pi, dcube *a, dcube *b)
  881. {
  882. register int i;
  883. if ( pi->out_cnt == 0 )
  884. return 0;
  885. for( i = 0; i < pi->out_words; i++ )
  886. if ( (a->out[i] & b->out[i]) != 0 )
  887. return 0;
  888. return 1;
  889. }
  890. /*-- dcDelta ----------------------------------------------------------------*/
  891. int dcDelta(pinfo *pi, dcube *a, dcube *b)
  892. {
  893. return dcDeltaIn(pi, a, b) + dcDeltaOut(pi, a, b);
  894. }
  895. /*-- dcIsOutIllegal ---------------------------------------------------------*/
  896. int dcIsOutIllegal(pinfo *pi, dcube *c)
  897. {
  898. register int i;
  899. if ( pi->out_words == 0 )
  900. return 0;
  901. for( i = 0; i < pi->out_words; i++ )
  902. {
  903. if ( c->out[i] != 0 )
  904. break;
  905. }
  906. if ( i >= pi->out_words )
  907. return 1;
  908. return 0;
  909. }
  910. /*-- dcIsDeltaInNoneZero ----------------------------------------------------*/
  911. int dcIsDeltaInNoneZero(pinfo *pi, dcube *a, dcube *b)
  912. {
  913. register c_int c;
  914. register int i;
  915. for( i = 0; i < pi->in_words; i++ )
  916. {
  917. c = a->in[i] & b->in[i]; /* Problem: Wie oft kommt 00 vor? */
  918. c |= c>>1; /* Reduktion: Wie oft kommt x0 vor? */
  919. c = ~c; /* Invertierung: Wie oft kommt x1 vor? */
  920. c &= CUBE_IN_MASK_ZERO; /* Maskierung: Wie oft kommt 01 vor? */
  921. if ( c > 0 )
  922. return 1;
  923. }
  924. return 0;
  925. }
  926. /*-- dcIsInIllegal ----------------------------------------------------------*/
  927. int dcIsInIllegal(pinfo *pi, dcube *cube)
  928. {
  929. register c_int c;
  930. register int i;
  931. for( i = 0; i < pi->in_words; i++ )
  932. {
  933. c = cube->in[i]; /* Problem: Wie oft kommt 00 vor? */
  934. c |= c>>1; /* Reduktion: Wie oft kommt x0 vor? */
  935. c = ~c; /* Invertierung: Wie oft kommt x1 vor? */
  936. c &= CUBE_IN_MASK_ZERO; /* Maskierung: Wie oft kommt 01 vor? */
  937. if ( c > 0 )
  938. return 1;
  939. }
  940. return 0;
  941. }
  942. /*-- dcIsDeltaNoneZero ------------------------------------------------------*/
  943. int dcIsDeltaNoneZero(pinfo *pi, dcube *a, dcube *b)
  944. {
  945. if ( dcDeltaOut(pi, a, b) > 0 )
  946. return 1;
  947. return dcIsDeltaInNoneZero(pi, a, b);
  948. }
  949. /*-- dcIsIllegal ------------------------------------------------------------*/
  950. int dcIsIllegal(pinfo *pi, dcube *c)
  951. {
  952. if ( dcIsInIllegal(pi, c) != 0 )
  953. return 1;
  954. if ( dcIsOutIllegal(pi, c) != 0 )
  955. return 1;
  956. return 0;
  957. }
  958. /*-- dcCofactor -------------------------------------------------------------*/
  959. /* Berechnet den Kofaktor von a bezueglich b. */
  960. /* Das Ergebnis wird in r abgelegt. */
  961. /* Der Reuckgabewert ist 0, wenn kein Ergebnis */
  962. /* berechnet wurde. */
  963. static void dc_cofactor(pinfo *pi, dcube *r, dcube *a, dcube *b)
  964. {
  965. register int i;
  966. for( i = 0; i < pi->in_words; i++ )
  967. r->in[i] = a->in[i] | ~b->in[i];
  968. if ( pi->out_words > 0 )
  969. {
  970. for( i = 0; i < pi->out_words-1; i++ )
  971. r->out[i] = a->out[i] | (~b->out[i]);
  972. r->out[i] = a->out[i] | ((~b->out[i]) & pi->out_last_mask);
  973. }
  974. r->n = a->n; /* notwendig fuer den irredundant algorithmus */
  975. }
  976. int dcCofactor(pinfo *pi, dcube *r, dcube *a, dcube *b)
  977. {
  978. if ( dcIsDeltaNoneZero(pi, a, b) != 0 )
  979. return 0;
  980. dc_cofactor(pi, r, a, b);
  981. return 1;
  982. }
  983. /* cofactoren, die teilmenge des cofactors sind */
  984. int dcSubCofactor(pinfo *pi, dcube *r, dcube *a, dcube *b)
  985. {
  986. if ( dcIsSubSet(pi, b, a) == 0 )
  987. return 0;
  988. dc_cofactor(pi, r, a, b);
  989. return 1;
  990. }
  991. /* cofactoren, die reduziert werden muessen */
  992. int dcRedCofactor(pinfo *pi, dcube *r, dcube *a, dcube *b)
  993. {
  994. if ( dcIsSubSet(pi, b, a) != 0 )
  995. return 0;
  996. return dcCofactor(pi, r, a, b);
  997. }
  998. /*-- dcConsensus ------------------------------------------------------------*/
  999. int dcConsensus(pinfo *pi, dcube *r, dcube *a, dcube *b)
  1000. {
  1001. int i;
  1002. int d_in = dcDeltaIn(pi, a, b);
  1003. int d_out = dcDeltaOut(pi, a, b);
  1004. if ( d_in == 0 )
  1005. {
  1006. for( i = 0; i < pi->in_words; i++ )
  1007. r->in[i] = a->in[i] & b->in[i];
  1008. for( i = 0; i < pi->out_words; i++ )
  1009. r->out[i] = a->out[i] | b->out[i];
  1010. }
  1011. else if ( d_in == 1 && d_out == 0 )
  1012. {
  1013. c_int c;
  1014. c_int m;
  1015. for( i = 0; i < pi->in_words; i++ )
  1016. {
  1017. c = a->in[i] & b->in[i];
  1018. m = (~((c)|(c>>1))) & CUBE_IN_MASK_ZERO;
  1019. r->in[i] = c | m | (m<<1);
  1020. }
  1021. for( i = 0; i < pi->out_words; i++ )
  1022. r->out[i] = a->out[i] & b->out[i];
  1023. }
  1024. else
  1025. {
  1026. return 0;
  1027. }
  1028. return 1;
  1029. }
  1030. /*-- dcSharpIn --------------------------------------------------------------*/
  1031. int dcSharpIn(pinfo *pi, dcube *r, dcube *a, dcube *b, int k)
  1032. {
  1033. register int i;
  1034. dcAllClear(pi, &(pi->tmp[5]));
  1035. dcSetIn(&(pi->tmp[5]), k, 3);
  1036. for( i = 0; i < pi->in_words; i++ )
  1037. {
  1038. if ( pi->tmp[5].in[i] != 0 )
  1039. {
  1040. if ( ((a->in[i] & ~b->in[i]) & pi->tmp[5].in[i]) == 0 )
  1041. return 0;
  1042. r->in[i] = (a->in[i] & ~b->in[i]) & pi->tmp[5].in[i];
  1043. r->in[i] |= a->in[i] & ~pi->tmp[5].in[i];
  1044. }
  1045. else
  1046. {
  1047. r->in[i] = a->in[i];
  1048. }
  1049. }
  1050. for( i = 0; i < pi->out_words; i++ )
  1051. r->out[i] = a->out[i];
  1052. return 1;
  1053. }
  1054. /*-- dcSharpOut -------------------------------------------------------------*/
  1055. int dcSharpOut(pinfo *pi, dcube *r, dcube *a, dcube *b)
  1056. {
  1057. int i;
  1058. for( i = 0; i < pi->out_words; i++ )
  1059. if ( (a->out[i] & ~b->out[i]) != 0 )
  1060. break;
  1061. if ( i >= pi->out_words )
  1062. return 0;
  1063. for( i = 0; i < pi->in_words; i++ )
  1064. r->in[i] = a->in[i];
  1065. for( i = 0; i < pi->out_words; i++ )
  1066. r->out[i] = a->out[i] & ~b->out[i];
  1067. return 1;
  1068. }
  1069. /*-- dcD1SharpIn ------------------------------------------------------------*/
  1070. int dcD1SharpIn(pinfo *pi, dcube *r, dcube *a, dcube *b, int k)
  1071. {
  1072. register int i;
  1073. dcAllClear(pi, &(pi->tmp[5]));
  1074. dcSetIn(&(pi->tmp[5]), k, 3);
  1075. for( i = 0; i < pi->in_words; i++ )
  1076. {
  1077. if ( pi->tmp[5].in[i] != 0 )
  1078. {
  1079. if ( ((a->in[i] & ~b->in[i]) & pi->tmp[5].in[i]) == 0 )
  1080. return 0;
  1081. r->in[i] = (a->in[i] & ~b->in[i]) & pi->tmp[5].in[i];
  1082. r->in[i] |= b->in[i] & ~pi->tmp[5].in[i];
  1083. }
  1084. else
  1085. {
  1086. r->in[i] = b->in[i];
  1087. }
  1088. }
  1089. for( i = 0; i < pi->out_words; i++ )
  1090. r->out[i] = b->out[i];
  1091. return 1;
  1092. }
  1093. /*-- dcD1SharpOut -----------------------------------------------------------*/
  1094. int dcD1SharpOut(pinfo *pi, dcube *r, dcube *a, dcube *b)
  1095. {
  1096. int i;
  1097. for( i = 0; i < pi->out_words; i++ )
  1098. if ( (a->out[i] & ~b->out[i]) != 0 )
  1099. break;
  1100. if ( i >= pi->out_words )
  1101. return 0;
  1102. for( i = 0; i < pi->in_words; i++ )
  1103. r->in[i] = b->in[i];
  1104. for( i = 0; i < pi->out_words; i++ )
  1105. r->out[i] = a->out[i] & ~b->out[i];
  1106. return 1;
  1107. }
  1108. /*-- dcGetCofactorForSplit --------------------------------------------------*/
  1109. int dcGetBinateInVarCofactor(pinfo *pi, dcube *r, dcube *rinv, dclist cl, dcube *cof)
  1110. {
  1111. int i;
  1112. for( i = 0; i < pi->in_cnt; i++ )
  1113. {
  1114. if ( dclIsBinateInVar(cl, i) != 0 )
  1115. {
  1116. dcCopy(pi, r, cof);
  1117. dcCopy(pi, rinv, cof);
  1118. dcInSetAll(pi, r, CUBE_IN_MASK_DC);
  1119. dcInSetAll(pi, rinv, CUBE_IN_MASK_DC);
  1120. dcSetIn(r, i, 2);
  1121. dcSetIn(rinv, i, 1);
  1122. return 1;
  1123. }
  1124. }
  1125. return 0;
  1126. }
  1127. int dcGetNoneDCInVarCofactor(pinfo *pi, dcube *r, dcube *rinv, dclist cl, dcube *cof)
  1128. {
  1129. int i;
  1130. for( i = 0; i < pi->in_cnt; i++ )
  1131. {
  1132. if ( dclIsDCInVar(pi, cl, i) == 0 )
  1133. {
  1134. dcCopy(pi, r, cof);
  1135. dcCopy(pi, rinv, cof);
  1136. dcInSetAll(pi, r, CUBE_IN_MASK_DC);
  1137. dcInSetAll(pi, rinv, CUBE_IN_MASK_DC);
  1138. dcSetIn(r, i, 2);
  1139. dcSetIn(rinv, i, 1);
  1140. return 1;
  1141. }
  1142. }
  1143. return 0;
  1144. }
  1145. int dcGetOutVarCofactor(pinfo *pi, dcube *r, dcube *rinv, dclist cl, dcube *cof)
  1146. {
  1147. int i, j;
  1148. int aktive_bit_cnt;
  1149. aktive_bit_cnt = 0;
  1150. for( i = 0; i < pi->out_cnt; i++ )
  1151. if ( dcGetOut(cof, i) != 0 )
  1152. aktive_bit_cnt++;
  1153. if ( aktive_bit_cnt <= 1 )
  1154. return 0;
  1155. dcInSetAll(pi, r, CUBE_IN_MASK_DC);
  1156. dcOutSetAll(pi, r, 0);
  1157. dcInSetAll(pi, rinv, CUBE_IN_MASK_DC);
  1158. dcOutSetAll(pi, rinv, 0);
  1159. j = 0;
  1160. for( i = 0; i < pi->out_cnt; i++ )
  1161. if ( dcGetOut(cof, i) != 0 )
  1162. {
  1163. if ( j < aktive_bit_cnt/2 )
  1164. dcSetOut(r, i, 1);
  1165. else
  1166. dcSetOut(rinv, i, 1);
  1167. j++;
  1168. }
  1169. return 1;
  1170. }
  1171. int dcGetCofactorForSplit(pinfo *pi, dcube *l, dcube *r, dclist cl, dcube *cof)
  1172. {
  1173. /*
  1174. if ( dcGetBinateInVarCofactor(pi, l, r, cl, cof) != 0 )
  1175. return 1;
  1176. if ( dcGetOutVarCofactor(pi, l, r, cl, cof) != 0 )
  1177. return 1;
  1178. return 0;
  1179. */
  1180. /*
  1181. if ( pinfoGetInVarDCubeCofactor(pi, l, r, cl, cof) != 0 )
  1182. return 1;
  1183. if ( pinfoGetOutVarDCubeCofactor(pi, l, r, cl, cof) != 0 )
  1184. return 1;
  1185. */
  1186. return pinfoGetDCubeCofactorForSplitting(pi, l, r, cl, cof);
  1187. }
  1188. int dcGetNoneDCCofactorForSplit(pinfo *pi, dcube *l, dcube *r, dclist cl, dcube *cof)
  1189. {
  1190. /*
  1191. if ( pinfoGetOutVarDCubeCofactor(pi, l, r, cl, cof) != 0 )
  1192. return 1;
  1193. */
  1194. /*
  1195. if ( pinfoGetInVarDCubeCofactor(pi, l, r, cl, cof) != 0 )
  1196. return 1;
  1197. if ( dcGetNoneDCInVarCofactor(pi, l, r, cl, cof) != 0 )
  1198. return 1;
  1199. if ( pinfoGetOutVarDCubeCofactor(pi, l, r, cl, cof) != 0 )
  1200. return 1;
  1201. */
  1202. /*
  1203. if ( pinfoGetDCubeCofactorForSplitting(pi, l, r, cl, cof) != 0 )
  1204. return 1;
  1205. */
  1206. /* reihenfolge wichtig??? zuerst eingangs variablen */
  1207. if ( pinfoGetInVarDCubeCofactor(pi, l, r, cl, cof) != 0 )
  1208. return 1;
  1209. if ( dcGetOutVarCofactor(pi, l, r, cl, cof) != 0 )
  1210. return 1;
  1211. if ( dcGetNoneDCInVarCofactor(pi, l, r, cl, cof) != 0 )
  1212. return 1;
  1213. /* jetzt die ausgangsvariablen */
  1214. /* die pinfo out var function zerstoert das ergebnis hmmmm??? */
  1215. return 0;
  1216. }
  1217. /*-- dcIsInTautology --------------------------------------------------------*/
  1218. int dcIsInTautology(pinfo *pi, dcube *c)
  1219. {
  1220. register int i;
  1221. for( i = 0; i < pi->in_words; i++ )
  1222. if ( c->in[i] != CUBE_IN_MASK_DC )
  1223. return 0;
  1224. return 1;
  1225. }
  1226. /*-- dcIsTautology ----------------------------------------------------------*/
  1227. int dcIsTautology(pinfo *pi, dcube *c)
  1228. {
  1229. register int i;
  1230. for( i = 0; i < pi->in_words; i++ )
  1231. if ( c->in[i] != CUBE_IN_MASK_DC )
  1232. return 0;
  1233. if ( pi->out_words > 0 )
  1234. {
  1235. for( i = 0; i < pi->out_words-1; i++ )
  1236. {
  1237. if ( c->out[i] != CUBE_OUT_MASK )
  1238. return 0;
  1239. }
  1240. if ( (c->out[i]&pi->out_last_mask) != pi->out_last_mask )
  1241. return 0;
  1242. }
  1243. return 1;
  1244. }
  1245. /*-- dcNot ------------------------------------------------------------------*/
  1246. void dcNot(pinfo *pi, dcube *c)
  1247. {
  1248. register int i;
  1249. for( i = 0; i < pi->in_words; i++ )
  1250. c->in[i] = ~c->in[i];
  1251. for( i = 0; i < pi->out_words; i++ )
  1252. c->out[i] = ~c->out[i];
  1253. if ( pi->out_words > 0 )
  1254. c->out[pi->out_words-1] &= pi->out_last_mask;
  1255. }
  1256. /*-- dcOrIn -----------------------------------------------------------------*/
  1257. void dcOrIn(pinfo *pi, dcube *r, dcube *a, dcube *b)
  1258. {
  1259. register int i;
  1260. for( i = 0; i < pi->in_words; i++ )
  1261. r->in[i] = a->in[i] | b->in[i];
  1262. }
  1263. /*-- dcOrOut ----------------------------------------------------------------*/
  1264. void dcOrOut(pinfo *pi, dcube *r, dcube *a, dcube *b)
  1265. {
  1266. register int i;
  1267. for( i = 0; i < pi->out_words; i++ )
  1268. r->out[i] = a->out[i] | b->out[i];
  1269. }
  1270. /*-- dcOr -------------------------------------------------------------------*/
  1271. void dcOr(pinfo *pi, dcube *r, dcube *a, dcube *b)
  1272. {
  1273. register int i;
  1274. for( i = 0; i < pi->in_words; i++ )
  1275. r->in[i] = a->in[i] | b->in[i];
  1276. for( i = 0; i < pi->out_words; i++ )
  1277. r->out[i] = a->out[i] | b->out[i];
  1278. }
  1279. /*-- dcAnd ------------------------------------------------------------------*/
  1280. void dcAnd(pinfo *pi, dcube *r, dcube *a, dcube *b)
  1281. {
  1282. register int i;
  1283. for( i = 0; i < pi->in_words; i++ )
  1284. r->in[i] = a->in[i] & b->in[i];
  1285. for( i = 0; i < pi->out_words; i++ )
  1286. r->out[i] = a->out[i] & b->out[i];
  1287. }
  1288. /*-- dcAndIn ----------------------------------------------------------------*/
  1289. void dcAndIn(pinfo *pi, dcube *r, dcube *a, dcube *b)
  1290. {
  1291. register int i;
  1292. for( i = 0; i < pi->in_words; i++ )
  1293. r->in[i] = a->in[i] & b->in[i];
  1294. }
  1295. /*-- dcNotAndOut -----------------------------------------------------------*/
  1296. void dcNotAndOut(pinfo *pi, dcube *r, dcube *a, dcube *b)
  1297. {
  1298. register int i;
  1299. for( i = 0; i < pi->out_words; i++ )
  1300. r->out[i] = (~a->out[i]) & b->out[i];
  1301. }
  1302. /*-- dcXorOut -----------------------------------------------------------*/
  1303. void dcXorOut(pinfo *pi, dcube *r, dcube *a, dcube *b)
  1304. {
  1305. register int i;
  1306. for( i = 0; i < pi->out_words; i++ )
  1307. r->out[i] = a->out[i] ^ b->out[i];
  1308. }
  1309. /*-- dcGetLiteralCnt --------------------------------------------------------*/
  1310. int dcGetLiteralCnt(pinfo *pi, dcube *c)
  1311. {
  1312. return pi->in_cnt - dcInDCCnt(pi, c) + dcOutCnt(pi, c);
  1313. }
  1314. /*-- dcGetDichotomyWeight ---------------------------------------------------*/
  1315. int dcGetDichotomyWeight(pinfo *pi, dcube *c)
  1316. {
  1317. int z = dcInZeroCnt(pi, c);
  1318. int o = dcInOneCnt(pi, c);
  1319. int w;
  1320. w = z-o;
  1321. if ( w < 0 )
  1322. w = -w;
  1323. w = pi->in_cnt - w + 1;
  1324. return w;
  1325. }
  1326. /*-- dcExpand1 --------------------------------------------------------------*/
  1327. /* Spezial Expand algorithmus fuer das URP Complement */
  1328. static void dcExpand1(pinfo *pi, dcube *c, dclist cl_off)
  1329. {
  1330. dcube *b = &(pi->tmp[7]);
  1331. int delta_in;
  1332. int delta_out;
  1333. int i, cnt = dclCnt(cl_off);
  1334. dcSetTautology(pi, b);
  1335. dcInSetAll(pi, b, 0);
  1336. dcOutSetAll(pi, b, 0);
  1337. for( i = 0; i < cnt; i++ )
  1338. {
  1339. delta_in = dcDeltaIn(pi, c, dclGet(cl_off, i));
  1340. delta_out = dcDeltaOut(pi, c, dclGet(cl_off, i));
  1341. if ( delta_in + delta_out == 1 )
  1342. dcOr(pi, b, b, dclGet(cl_off, i));
  1343. }
  1344. dcNot(pi, b);
  1345. dcOr(pi, c, c, b);
  1346. }
  1347. /*-- dcWriteBin -------------------------------------------------------------*/
  1348. int dcWriteBin(pinfo *pi, dcube *c, FILE *fp)
  1349. {
  1350. int i, j;
  1351. dcube *a = &(pi->tmp[7]);
  1352. c_int w;
  1353. if ( pi->in_words != 0 )
  1354. {
  1355. for( i = 0; i < pi->in_words; i++ )
  1356. {
  1357. w = c->in[i];
  1358. for( j = 0; j < sizeof(c_int); j++ )
  1359. {
  1360. ((unsigned char *)a->in)[i*sizeof(c_int)+j] = (unsigned char)(w&255);
  1361. w>>=8;
  1362. }
  1363. }
  1364. if ( b_io_Write(fp, pi->in_words*sizeof(c_int), (unsigned char *)a->in) == 0 )
  1365. return 0;
  1366. }
  1367. if ( pi->out_words != 0 )
  1368. {
  1369. for( i = 0; i < pi->out_words; i++ )
  1370. {
  1371. w = c->out[i];
  1372. for( j = 0; j < sizeof(c_int); j++ )
  1373. {
  1374. ((unsigned char *)a->out)[i*sizeof(c_int)+j] = (unsigned char)(w&255);
  1375. w>>=8;
  1376. }
  1377. }
  1378. if ( b_io_Write(fp, pi->out_words*sizeof(c_int), (unsigned char *)a->out) == 0 )
  1379. return 0;
  1380. }
  1381. if ( b_io_WriteInt(fp, c->n) == 0 )
  1382. return 0;
  1383. return 1;
  1384. }
  1385. /*-- dcReadBin --------------------------------------------------------------*/
  1386. int dcReadBin(pinfo *pi, dcube *c, FILE *fp)
  1387. {
  1388. int i, j;
  1389. dcube *a = &(pi->tmp[7]);
  1390. c_int w;
  1391. if ( pi->in_words != 0 )
  1392. {
  1393. if ( b_io_Read(fp, pi->in_words*sizeof(c_int), (unsigned char *)a->in) == 0 )
  1394. return 0;
  1395. for( i = 0; i < pi->in_words; i++ )
  1396. {
  1397. w = 0;
  1398. for( j = 0; j < sizeof(c_int); j++ )
  1399. {
  1400. w<<=8;
  1401. w |= (c_int)((unsigned char *)a->in)[i*sizeof(c_int)+sizeof(c_int)-1-j];
  1402. }
  1403. c->in[i] = w;
  1404. }
  1405. }
  1406. if ( pi->out_words != 0 )
  1407. {
  1408. if ( b_io_Read(fp, pi->out_words*sizeof(c_int), (unsigned char *)a->out) == 0 )
  1409. return 0;
  1410. for( i = 0; i < pi->out_words; i++ )
  1411. {
  1412. w = 0;
  1413. for( j = 0; j < sizeof(c_int); j++ )
  1414. {
  1415. w<<=8;
  1416. w |= (c_int)((unsigned char *)a->out)[i*sizeof(c_int)+sizeof(c_int)-1-j];
  1417. }
  1418. c->out[i] = w;
  1419. }
  1420. }
  1421. if ( b_io_ReadInt(fp, &(c->n)) == 0 )
  1422. return 0;
  1423. return 1;
  1424. }
  1425. /*===========================================================================*/
  1426. /*-- dclInit ----------------------------------------------------------------*/
  1427. int dclInit(dclist *cl)
  1428. {
  1429. *cl = (dclist)malloc(sizeof(struct _dclist_struct));
  1430. if ( *cl == NULL )
  1431. return 0;
  1432. (*cl)->list = NULL;
  1433. (*cl)->max = 0;
  1434. (*cl)->cnt = 0;
  1435. (*cl)->flag_list = NULL;
  1436. return 1;
  1437. }
  1438. /*-- dclInitCached ----------------------------------------------------------*/
  1439. int dclInitCached(pinfo *pi, dclist *cl)
  1440. {
  1441. if ( pi->cache_cnt == 0 )
  1442. return dclInit(cl);
  1443. pi->cache_cnt--;
  1444. *cl = pi->cache_cl[pi->cache_cnt];
  1445. return 1;
  1446. }
  1447. /*-- dclInitVA --------------------------------------------------------------*/
  1448. int dclInitVA(int n, ...)
  1449. {
  1450. va_list va;
  1451. int i;
  1452. va_start(va, n);
  1453. for( i = 0; i < n; i++ )
  1454. if ( dclInit(va_arg(va, dclist *)) == 0 )
  1455. break;
  1456. va_end(va);
  1457. if ( i < n )
  1458. {
  1459. va_start(va, n);
  1460. while( i-- >= 0 )
  1461. dclDestroy(*va_arg(va, dclist *));
  1462. va_end(va);
  1463. return 0;
  1464. }
  1465. return 1;
  1466. }
  1467. /*-- dclInitCachedVA --------------------------------------------------------*/
  1468. int dclInitCachedVA(pinfo *pi, int n, ...)
  1469. {
  1470. va_list va;
  1471. int i;
  1472. va_start(va, n);
  1473. for( i = 0; i < n; i++ )
  1474. if ( dclInitCached(pi, va_arg(va, dclist *)) == 0 )
  1475. break;
  1476. va_end(va);
  1477. if ( i < n )
  1478. {
  1479. va_start(va, n);
  1480. while( i-- >= 0 )
  1481. dclDestroyCached(pi, *va_arg(va, dclist *));
  1482. va_end(va);
  1483. return 0;
  1484. }
  1485. return 1;
  1486. }
  1487. /*-- dclDestroy -------------------------------------------------------------*/
  1488. static void dcl_destroy(dclist cl)
  1489. {
  1490. int i;
  1491. for( i = 0; i < cl->max; i++ )
  1492. dcDestroy(cl->list+i);
  1493. if ( cl->list != NULL )
  1494. free(cl->list);
  1495. if ( cl->flag_list != NULL )
  1496. free(cl->flag_list);
  1497. cl->flag_list = NULL;
  1498. cl->list = NULL;
  1499. cl->max = 0;
  1500. cl->cnt = 0;
  1501. }
  1502. void dclDestroy(dclist cl)
  1503. {
  1504. dcl_destroy(cl);
  1505. free(cl);
  1506. }
  1507. /*-- dclDestroyCached -------------------------------------------------------*/
  1508. void dclDestroyCached(pinfo *pi, dclist cl)
  1509. {
  1510. if ( pi->cache_cnt >= PINFO_CACHE_CL )
  1511. dclDestroy(cl);
  1512. else
  1513. {
  1514. dclClear(cl);
  1515. pi->cache_cl[pi->cache_cnt++] = cl;
  1516. }
  1517. }
  1518. /*-- dclDestroyVA -----------------------------------------------------------*/
  1519. void dclDestroyVA(int n, ...)
  1520. {
  1521. va_list va;
  1522. int i;
  1523. va_start(va, n);
  1524. for( i = 0; i < n; i++ )
  1525. dclDestroy(va_arg(va, dclist));
  1526. va_end(va);
  1527. }
  1528. /*-- dclDestroyCachedVA -----------------------------------------------------*/
  1529. void dclDestroyCachedVA(pinfo *pi, int n, ...)
  1530. {
  1531. va_list va;
  1532. int i;
  1533. va_start(va, n);
  1534. for( i = 0; i < n; i++ )
  1535. dclDestroyCached(pi, va_arg(va, dclist));
  1536. va_end(va);
  1537. }
  1538. /*-- dclExpandFlagListTo ----------------------------------------------------*/
  1539. int dclExpandFlagListTo(dclist cl, int max)
  1540. {
  1541. void *ptr;
  1542. /* allocate at least one byte */
  1543. if ( max <= 0 )
  1544. max = 1;
  1545. if ( cl->flag_list != NULL )
  1546. {
  1547. if ( max == 0 )
  1548. {
  1549. /* 14 jan 2002: assigning a NULL pointer seems to be an error... */
  1550. /*
  1551. free(cl->flag_list);
  1552. cl->flag_list = NULL;
  1553. return 1;
  1554. */
  1555. /* instead, allocate at least one byte */
  1556. max = 1;
  1557. }
  1558. ptr = realloc(cl->flag_list, max);
  1559. }
  1560. else
  1561. {
  1562. ptr = malloc(max);
  1563. }
  1564. if ( ptr == NULL )
  1565. return 0;
  1566. cl->flag_list = (char *)ptr;
  1567. return 1;
  1568. }
  1569. /*-- dclExpandTo ------------------------------------------------------------*/
  1570. int dclExpandTo(pinfo *pi, dclist cl, int max)
  1571. {
  1572. void *ptr;
  1573. max = (max+31)&~31;
  1574. if ( max <= cl->max )
  1575. return 1;
  1576. if ( cl->list == NULL )
  1577. ptr = malloc(max*sizeof(dcube));
  1578. else
  1579. ptr = realloc(cl->list, max*sizeof(dcube));
  1580. if ( ptr == NULL )
  1581. return 0;
  1582. cl->list = (dcube *)ptr;
  1583. if ( cl->flag_list != NULL )
  1584. if ( dclExpandFlagListTo(cl, max) == 0 )
  1585. return 0;
  1586. while(cl->max < max)
  1587. {
  1588. if ( dcInitMem(pi, cl->list+cl->max) == 0 )
  1589. return 0;
  1590. if ( cl->flag_list != NULL )
  1591. cl->flag_list[cl->max] = 0;
  1592. cl->max++;
  1593. }
  1594. return 1;
  1595. }
  1596. /*-- dclAddEmpty ------------------------------------------------------------*/
  1597. /* returns position or -1 */
  1598. int dclAddEmpty(pinfo *pi, dclist cl)
  1599. {
  1600. if ( dclCnt(cl) >= cl->max )
  1601. if ( dclExpandTo(pi, cl, dclCnt(cl)+1) == 0 )
  1602. return -1;
  1603. dcInSetAll(pi, cl->list+cl->cnt, CUBE_IN_MASK_DC);
  1604. dcOutSetAll(pi, cl->list+cl->cnt, 0);
  1605. if ( cl->flag_list != NULL )
  1606. cl->flag_list[cl->cnt] = 0;
  1607. cl->cnt++;
  1608. return cl->cnt-1;
  1609. }
  1610. dcube *dclAddEmptyCube(pinfo *pi, dclist cl)
  1611. {
  1612. int pos;
  1613. pos = dclAddEmpty(pi, cl);
  1614. if ( pos < 0 )
  1615. return NULL;
  1616. return dclGet(cl, pos);
  1617. }
  1618. /*-- dclAdd -----------------------------------------------------------------*/
  1619. /* returns position or -1 */
  1620. int dclAdd(pinfo *pi, dclist cl, dcube *c)
  1621. {
  1622. if ( dclCnt(cl) >= cl->max )
  1623. {
  1624. /* there is an interessting possible bug here */
  1625. /* if c is an element of cl, c might become invalid */
  1626. /* if cl->list is expanded and moved to another */
  1627. /* location in the memory, c becomes invalid */
  1628. if ( c >= cl->list && c < cl->list+cl->max )
  1629. {
  1630. dcCopy(pi, pi->tmp+12, c);
  1631. c = pi->tmp+12;
  1632. }
  1633. if ( dclExpandTo(pi, cl, dclCnt(cl)+1) == 0 )
  1634. return -1;
  1635. assert(cl->max > cl->cnt);
  1636. }
  1637. {
  1638. register dcube *d;
  1639. int i;
  1640. d = cl->list+cl->cnt;
  1641. for( i = 0; i < pi->in_out_words_min; i++ )
  1642. {
  1643. d->in[i] = c->in[i];
  1644. d->out[i] = c->out[i];
  1645. }
  1646. for( i = pi->in_out_words_min; i < pi->in_words; i++ )
  1647. d->in[i] = c->in[i];
  1648. for( i = pi->in_out_words_min; i < pi->out_words; i++ )
  1649. d->out[i] = c->out[i];
  1650. d->n = c->n;
  1651. }
  1652. /* dcCopy(pi, cl->list+cl->cnt, c); */
  1653. if ( cl->flag_list != NULL )
  1654. cl->flag_list[cl->cnt] = 0;
  1655. cl->cnt++;
  1656. return cl->cnt-1;
  1657. }
  1658. /*-- dclAddUnique -----------------------------------------------------------*/
  1659. /* returns position or -1 */
  1660. int dclAddUnique(pinfo *pi, dclist cl, dcube *c)
  1661. {
  1662. int i, cnt = dclCnt(cl);
  1663. for( i = 0; i < cnt; i++ )
  1664. if ( dcIsEqual(pi, dclGet(cl, i), c) != 0 )
  1665. return i;
  1666. return dclAdd(pi, cl, c);
  1667. }
  1668. /*-- dclJoin ----------------------------------------------------------------*/
  1669. int dclJoin(pinfo *pi, dclist dest, dclist src)
  1670. {
  1671. int i, cnt = dclCnt(src);
  1672. if ( dclExpandTo(pi, dest, dclCnt(dest)+dclCnt(src)) == 0 )
  1673. return 0;
  1674. for( i = 0; i < cnt; i++ )
  1675. if ( dclAdd(pi, dest, dclGet(src, i)) < 0 )
  1676. return 0;
  1677. return 1;
  1678. }
  1679. /*-- dclCopy ----------------------------------------------------------------*/
  1680. int dclCopy(pinfo *pi, dclist dest, dclist src)
  1681. {
  1682. dclClear(dest);
  1683. return dclJoin(pi, dest, src);
  1684. }
  1685. /*-- dclClearFlags ----------------------------------------------------------*/
  1686. int dclClearFlags(dclist cl)
  1687. {
  1688. if ( dclExpandFlagListTo(cl, cl->max) == 0 )
  1689. return 0;
  1690. if ( cl->max == 0 )
  1691. return 1;
  1692. memset(cl->flag_list, 0, cl->max);
  1693. return 1;
  1694. }
  1695. /*-- dclSetFlag -------------------------------------------------------------*/
  1696. /*
  1697. void dclSetFlag(dclist cl, int pos)
  1698. {
  1699. cl->flag_list[pos] = 1;
  1700. }
  1701. */
  1702. /*-- dclIsFlag --------------------------------------------------------------*/
  1703. /*
  1704. int dclIsFlag(dclist cl, int pos)
  1705. {
  1706. return (int)cl->flag_list[pos];
  1707. }
  1708. */
  1709. /*-- dclDeleteCubesWithFlag -------------------------------------------------*/
  1710. void dclDeleteCubesWithFlag(pinfo *pi, dclist cl)
  1711. {
  1712. int src, dest;
  1713. src = 0;
  1714. dest = 0;
  1715. while( src < cl->cnt )
  1716. {
  1717. if ( cl->flag_list[src] != 0 )
  1718. {
  1719. src++;
  1720. }
  1721. else
  1722. {
  1723. if ( src != dest )
  1724. {
  1725. dcCopy(pi, cl->list+dest, cl->list+src);
  1726. cl->flag_list[dest] = cl->flag_list[src];
  1727. }
  1728. dest++;
  1729. src++;
  1730. }
  1731. }
  1732. memset(cl->flag_list, 0, cl->cnt);
  1733. cl->cnt = dest;
  1734. }
  1735. /*-- dclCopyCubesWithFlag ----------------------------------------------------*/
  1736. int dclCopyCubesWithFlag(pinfo *pi, dclist dest, dclist src)
  1737. {
  1738. int i, cnt = dclCnt(src);
  1739. dclClear(dest);
  1740. for( i = 0; i < cnt; i++ )
  1741. if ( dclIsFlag(src, i) != 0 )
  1742. if ( dclAdd(pi, dest, dclGet(src, i)) < 0 )
  1743. return 0;
  1744. return 1;
  1745. }
  1746. /*-- dclDeleteCube ----------------------------------------------------------*/
  1747. void dclDeleteCube(pinfo *pi, dclist cl, int pos)
  1748. {
  1749. if ( cl->cnt == 0 )
  1750. return;
  1751. if ( pos >= cl->cnt )
  1752. return;
  1753. pos++;
  1754. while( pos < cl->cnt )
  1755. {
  1756. dcCopy(pi, cl->list+pos-1, cl->list+pos);
  1757. pos++;
  1758. }
  1759. /* dcDestroy(cl->list+cl->cnt-1); */
  1760. cl->cnt--;
  1761. }
  1762. /*-- dclDeleteByCube --------------------------------------------------------*/
  1763. int dclDeleteByCube(pinfo *pi, dclist cl, dcube *c)
  1764. {
  1765. int i, cnt = dclCnt(cl);
  1766. if ( dclClearFlags(cl) == 0 )
  1767. return 0;
  1768. for( i = 0; i < cnt; i++ )
  1769. {
  1770. if ( dcIsEqual(pi, c, dclGet(cl, i)) != 0 )
  1771. dclSetFlag(cl, i);
  1772. }
  1773. dclDeleteCubesWithFlag(pi, cl);
  1774. return 1;
  1775. }
  1776. /*-- dclDeleteByCubeList ----------------------------------------------------*/
  1777. int