nysol-take 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +7 -0
  2. data/bin/mbiclique.rb +317 -0
  3. data/bin/mbipolish.rb +362 -0
  4. data/bin/mccomp.rb +235 -0
  5. data/bin/mclique.rb +295 -0
  6. data/bin/mclique2g.rb +105 -0
  7. data/bin/mcliqueInfo.rb +203 -0
  8. data/bin/mfriends.rb +202 -0
  9. data/bin/mgdiff.rb +252 -0
  10. data/bin/mhifriend.rb +456 -0
  11. data/bin/mhipolish.rb +465 -0
  12. data/bin/mitemset.rb +168 -0
  13. data/bin/mpal.rb +410 -0
  14. data/bin/mpolishing.rb +399 -0
  15. data/bin/msequence.rb +165 -0
  16. data/bin/mtra2g.rb +476 -0
  17. data/bin/mtra2gc.rb +360 -0
  18. data/ext/grhfilrun/extconf.rb +12 -0
  19. data/ext/grhfilrun/grhfilrun.c +85 -0
  20. data/ext/grhfilrun/src/_sspc.c +358 -0
  21. data/ext/grhfilrun/src/aheap.c +545 -0
  22. data/ext/grhfilrun/src/aheap.h +251 -0
  23. data/ext/grhfilrun/src/base.c +92 -0
  24. data/ext/grhfilrun/src/base.h +59 -0
  25. data/ext/grhfilrun/src/fstar.c +497 -0
  26. data/ext/grhfilrun/src/fstar.h +80 -0
  27. data/ext/grhfilrun/src/grhfil.c +214 -0
  28. data/ext/grhfilrun/src/itemset.c +713 -0
  29. data/ext/grhfilrun/src/itemset.h +170 -0
  30. data/ext/grhfilrun/src/problem.c +415 -0
  31. data/ext/grhfilrun/src/problem.h +179 -0
  32. data/ext/grhfilrun/src/queue.c +533 -0
  33. data/ext/grhfilrun/src/queue.h +182 -0
  34. data/ext/grhfilrun/src/sample.c +19 -0
  35. data/ext/grhfilrun/src/sspc.c +597 -0
  36. data/ext/grhfilrun/src/sspc2.c +491 -0
  37. data/ext/grhfilrun/src/stdlib2.c +1482 -0
  38. data/ext/grhfilrun/src/stdlib2.h +892 -0
  39. data/ext/grhfilrun/src/trsact.c +817 -0
  40. data/ext/grhfilrun/src/trsact.h +160 -0
  41. data/ext/grhfilrun/src/vec.c +745 -0
  42. data/ext/grhfilrun/src/vec.h +172 -0
  43. data/ext/lcmrun/extconf.rb +20 -0
  44. data/ext/lcmrun/lcmrun.cpp +99 -0
  45. data/ext/lcmrun/src/aheap.c +216 -0
  46. data/ext/lcmrun/src/aheap.h +111 -0
  47. data/ext/lcmrun/src/base.c +92 -0
  48. data/ext/lcmrun/src/base.h +59 -0
  49. data/ext/lcmrun/src/itemset.c +496 -0
  50. data/ext/lcmrun/src/itemset.h +157 -0
  51. data/ext/lcmrun/src/lcm.c +427 -0
  52. data/ext/lcmrun/src/problem.c +349 -0
  53. data/ext/lcmrun/src/problem.h +177 -0
  54. data/ext/lcmrun/src/queue.c +528 -0
  55. data/ext/lcmrun/src/queue.h +176 -0
  56. data/ext/lcmrun/src/sgraph.c +359 -0
  57. data/ext/lcmrun/src/sgraph.h +173 -0
  58. data/ext/lcmrun/src/stdlib2.c +1282 -0
  59. data/ext/lcmrun/src/stdlib2.h +823 -0
  60. data/ext/lcmrun/src/trsact.c +747 -0
  61. data/ext/lcmrun/src/trsact.h +159 -0
  62. data/ext/lcmrun/src/vec.c +731 -0
  63. data/ext/lcmrun/src/vec.h +171 -0
  64. data/ext/lcmseq0run/extconf.rb +20 -0
  65. data/ext/lcmseq0run/lcmseq0run.cpp +59 -0
  66. data/ext/lcmseq0run/src/aheap.c +216 -0
  67. data/ext/lcmseq0run/src/aheap.h +111 -0
  68. data/ext/lcmseq0run/src/base.c +92 -0
  69. data/ext/lcmseq0run/src/base.h +59 -0
  70. data/ext/lcmseq0run/src/itemset.c +518 -0
  71. data/ext/lcmseq0run/src/itemset.h +157 -0
  72. data/ext/lcmseq0run/src/itemset_zero.c +522 -0
  73. data/ext/lcmseq0run/src/lcm_seq.c +446 -0
  74. data/ext/lcmseq0run/src/lcm_seq_zero.c +446 -0
  75. data/ext/lcmseq0run/src/problem.c +439 -0
  76. data/ext/lcmseq0run/src/problem.h +179 -0
  77. data/ext/lcmseq0run/src/problem_zero.c +439 -0
  78. data/ext/lcmseq0run/src/queue.c +533 -0
  79. data/ext/lcmseq0run/src/queue.h +182 -0
  80. data/ext/lcmseq0run/src/stdlib2.c +1350 -0
  81. data/ext/lcmseq0run/src/stdlib2.h +864 -0
  82. data/ext/lcmseq0run/src/trsact.c +747 -0
  83. data/ext/lcmseq0run/src/trsact.h +159 -0
  84. data/ext/lcmseq0run/src/vec.c +779 -0
  85. data/ext/lcmseq0run/src/vec.h +172 -0
  86. data/ext/lcmseqrun/extconf.rb +20 -0
  87. data/ext/lcmseqrun/lcmseqrun.cpp +101 -0
  88. data/ext/lcmseqrun/src/aheap.c +216 -0
  89. data/ext/lcmseqrun/src/aheap.h +111 -0
  90. data/ext/lcmseqrun/src/base.c +92 -0
  91. data/ext/lcmseqrun/src/base.h +59 -0
  92. data/ext/lcmseqrun/src/itemset.c +518 -0
  93. data/ext/lcmseqrun/src/itemset.h +157 -0
  94. data/ext/lcmseqrun/src/itemset_zero.c +522 -0
  95. data/ext/lcmseqrun/src/lcm_seq.c +447 -0
  96. data/ext/lcmseqrun/src/lcm_seq_zero.c +446 -0
  97. data/ext/lcmseqrun/src/problem.c +439 -0
  98. data/ext/lcmseqrun/src/problem.h +179 -0
  99. data/ext/lcmseqrun/src/problem_zero.c +439 -0
  100. data/ext/lcmseqrun/src/queue.c +533 -0
  101. data/ext/lcmseqrun/src/queue.h +182 -0
  102. data/ext/lcmseqrun/src/stdlib2.c +1350 -0
  103. data/ext/lcmseqrun/src/stdlib2.h +864 -0
  104. data/ext/lcmseqrun/src/trsact.c +747 -0
  105. data/ext/lcmseqrun/src/trsact.h +159 -0
  106. data/ext/lcmseqrun/src/vec.c +779 -0
  107. data/ext/lcmseqrun/src/vec.h +172 -0
  108. data/ext/lcmtransrun/extconf.rb +18 -0
  109. data/ext/lcmtransrun/lcmtransrun.cpp +264 -0
  110. data/ext/macerun/extconf.rb +20 -0
  111. data/ext/macerun/macerun.cpp +57 -0
  112. data/ext/macerun/src/aheap.c +217 -0
  113. data/ext/macerun/src/aheap.h +112 -0
  114. data/ext/macerun/src/itemset.c +491 -0
  115. data/ext/macerun/src/itemset.h +158 -0
  116. data/ext/macerun/src/mace.c +503 -0
  117. data/ext/macerun/src/problem.c +346 -0
  118. data/ext/macerun/src/problem.h +174 -0
  119. data/ext/macerun/src/queue.c +529 -0
  120. data/ext/macerun/src/queue.h +177 -0
  121. data/ext/macerun/src/sgraph.c +360 -0
  122. data/ext/macerun/src/sgraph.h +174 -0
  123. data/ext/macerun/src/stdlib2.c +993 -0
  124. data/ext/macerun/src/stdlib2.h +811 -0
  125. data/ext/macerun/src/vec.c +634 -0
  126. data/ext/macerun/src/vec.h +170 -0
  127. data/ext/sspcrun/extconf.rb +20 -0
  128. data/ext/sspcrun/src/_sspc.c +358 -0
  129. data/ext/sspcrun/src/aheap.c +545 -0
  130. data/ext/sspcrun/src/aheap.h +251 -0
  131. data/ext/sspcrun/src/base.c +92 -0
  132. data/ext/sspcrun/src/base.h +59 -0
  133. data/ext/sspcrun/src/fstar.c +496 -0
  134. data/ext/sspcrun/src/fstar.h +80 -0
  135. data/ext/sspcrun/src/grhfil.c +213 -0
  136. data/ext/sspcrun/src/itemset.c +713 -0
  137. data/ext/sspcrun/src/itemset.h +170 -0
  138. data/ext/sspcrun/src/problem.c +415 -0
  139. data/ext/sspcrun/src/problem.h +179 -0
  140. data/ext/sspcrun/src/queue.c +533 -0
  141. data/ext/sspcrun/src/queue.h +182 -0
  142. data/ext/sspcrun/src/sample.c +19 -0
  143. data/ext/sspcrun/src/sspc.c +598 -0
  144. data/ext/sspcrun/src/sspc2.c +491 -0
  145. data/ext/sspcrun/src/stdlib2.c +1482 -0
  146. data/ext/sspcrun/src/stdlib2.h +892 -0
  147. data/ext/sspcrun/src/trsact.c +817 -0
  148. data/ext/sspcrun/src/trsact.h +160 -0
  149. data/ext/sspcrun/src/vec.c +745 -0
  150. data/ext/sspcrun/src/vec.h +172 -0
  151. data/ext/sspcrun/sspcrun.cpp +54 -0
  152. data/lib/nysol/enumLcmEp.rb +338 -0
  153. data/lib/nysol/enumLcmEsp.rb +284 -0
  154. data/lib/nysol/enumLcmIs.rb +275 -0
  155. data/lib/nysol/enumLcmSeq.rb +143 -0
  156. data/lib/nysol/items.rb +201 -0
  157. data/lib/nysol/seqDB.rb +256 -0
  158. data/lib/nysol/take.rb +39 -0
  159. data/lib/nysol/taxonomy.rb +113 -0
  160. data/lib/nysol/traDB.rb +257 -0
  161. metadata +239 -0
@@ -0,0 +1,892 @@
1
+ /* library for standard macros and functions
2
+ by Takeaki Uno 2/22/2002 e-mail: uno@nii.jp
3
+ homepage: http://research.nii.ac.jp/~uno/index.html */
4
+ /* This program is available for only academic use, basically.
5
+ Anyone can modify this program, but he/she has to write down
6
+ the change of the modification on the top of the source code.
7
+ Neither contact nor appointment to Takeaki Uno is needed.
8
+ If one wants to re-distribute this code, please
9
+ refer the newest code, and show the link to homepage of
10
+ Takeaki Uno, to notify the news about the codes for the users. */
11
+
12
+ #ifndef _stdlib2_h_
13
+ #define _stdlib2_h_
14
+
15
+ #include<stdlib.h>
16
+ #include<stdio.h>
17
+ #include<string.h>
18
+ #include<math.h>
19
+ #include<time.h>
20
+ #include<stdarg.h>
21
+
22
+ #ifdef USE_SIMD
23
+ #include<emmintrin.h> // use MMX-SSE2;
24
+ #endif
25
+
26
+
27
+ #if defined(__cplusplus) && defined(__GNUC__)
28
+ #define _cplusplus_
29
+ #endif
30
+
31
+ // for visual C++ (use typeid insead of typeof)
32
+ #ifdef _MSC_VER
33
+ #define typeof(a) typeid(a).name()
34
+ #endif
35
+
36
+ #ifdef MULTI_CORE
37
+ #include <sys/types.h>
38
+ #include <pthread.h>
39
+ #endif
40
+ #define CORE_MAX 16
41
+
42
+ /* comment out the following line if no error check is needed */
43
+ //#define ERROR_CHECK
44
+ /* comment out the following if exit is not needed after each error routine */
45
+ //#define ERROR_RET
46
+
47
+ #ifdef ERROR_RET // definition of the process for errors
48
+ #define EXIT return
49
+ #define EXIT0 return(0)
50
+ #else
51
+ #define EXIT exit(1)
52
+ #define EXIT0 exit(1)
53
+ #endif
54
+
55
+ // for dealing with files more than 2GB
56
+ #define _LARGEFILE_SOURCE
57
+ #define _FILE_OFFSET_BITS 64
58
+
59
+ #ifndef NULL
60
+ #define NULL 0
61
+ #endif
62
+
63
+ #ifdef MTWISTER
64
+ #define RANDOM ((long)(dsfmt_gv_genrand_close_open()*2147483648LL))
65
+ #define RAND1 dsfmt_gv_genrand_close_open()
66
+ #define RAND_INIT dsfmt_gv_init_gen_rand(514346237)
67
+ #elif defined(__GNUC__)
68
+ #define RANDOM xor128()
69
+ #define RAND1 ((double)xor128())/4294967296.0
70
+ #define RAND_INIT xor128()
71
+ #else
72
+ #define RANDOM rand()
73
+ #define RAND1 ((double)rand())/2147483648.0
74
+ #define RAND_INIT srand(0)
75
+ #endif
76
+
77
+
78
+ // 64bit integer
79
+ #ifdef LONG_32
80
+ #define LONG int
81
+ #define LONGHUGE INTHUGE
82
+ #define LONGF "%d"
83
+ #elif !defined(LONG)
84
+ #define LONG long long
85
+ #define LONGHUGE 9000000000000000000LL
86
+ #define LONGF "%lld"
87
+ #endif
88
+
89
+ // actual int (most proper sized integer, for the processor)
90
+ #ifdef INT_64
91
+ #define INT LONG
92
+ #define INTF LONGF
93
+ #else
94
+ #define INT int
95
+ #define INTF "%d"
96
+ #endif
97
+
98
+ #ifndef FILE_LONG
99
+ #define FILE_LONG LONG
100
+ #define FILE_LONGHUGE LONGHUGE
101
+ #define FILE_LONGF LONGF
102
+ #endif
103
+
104
+ #define UINTHUGE 4000000000U
105
+ #define INTHUGE 2000000000
106
+ #define USHORTHUGE 32767
107
+ #define SHORTHUGE 65535
108
+ #define DOUBLEHUGE 999999999999999999999999999999.9
109
+ #define ISEQUAL_VALUE 0.0000001
110
+ #define ISEQUAL_VALUE2 0.00001
111
+ #define PI 3.1415926535897932384647950288
112
+ #define PI_INT 31416
113
+ #define NPE 2.718281828459045235360287471352
114
+ #define NPE_INT 27183
115
+
116
+ #ifndef WEIGHT
117
+ #ifdef WEIGHT_DOUBLE
118
+ #define WEIGHT double
119
+ #define WEIGHTHUGE DOUBLEHUGE
120
+ #define WEIGHTF "%f"
121
+ #else // define WEIGHT by int if it's undefined
122
+ #define WEIGHT int
123
+ #define WEIGHTHUGE INTHUGE
124
+ #define WEIGHTF "%d"
125
+ #endif
126
+ #endif
127
+
128
+ #ifndef PERM
129
+ #ifdef PERM_LONG
130
+ #define PERM LONG
131
+ #define PERMHUGE LONGHUGE
132
+ #define PERMF LONGF
133
+ #else
134
+ #define PERM int
135
+ #define PERMHUGE INTHUGE
136
+ #define PERMF "%d"
137
+ #endif
138
+ #endif
139
+
140
+ // for loading/writing file from array (emulation)
141
+ #ifdef _FILE2_LOAD_FROM_MEMORY_
142
+ #define _NO_MAIN_
143
+ extern void *__load_from_memory__, *__load_from_memory_org__, *__load_from_memory_org2__;
144
+ extern char *__write_to_memory__, *__write_to_memory_org__, *__write_to_memory_next__;
145
+ #define FILE2_LOAD_FROM_MEMORY_ENDTYPE int
146
+ #ifndef FILE2_LOAD_FROM_MEMORY_END
147
+ #define FILE2_LOAD_FROM_MEMORY_END INTHUGE
148
+ #endif
149
+ #define FILE2_WRITE_MEMORY(a,b) \
150
+ do{ \
151
+ if( __write_to_memory__ >= __write_to_memory_next__ ){ \
152
+ common_size_t = __write_to_memory__ -__write_to_memory_org__; \
153
+ realloc2 (__write_to_memory_org__, common_size_t*2+ 1024, EXIT); \
154
+ __write_to_memory__ = __write_to_memory_org__ + common_size_t; \
155
+ __write_to_memory_next__ = __write_to_memory_org__ + common_size_t*2+512; \
156
+ } \
157
+ *((a *)__write_to_memory__) = b; \
158
+ __write_to_memory__ = (char *)(((a *)__write_to_memory__) +1); \
159
+ }while(0)
160
+ #endif
161
+
162
+
163
+ extern size_t common_size_t;
164
+ extern INT common_INT, common_INT2;
165
+ extern char *common_pnt, *common_charp;
166
+ extern FILE *common_FILE;
167
+ extern WEIGHT common_WEIGHT, *common_WEIGHTp;
168
+ extern char *ERROR_MES;
169
+ extern int print_time_flag;
170
+ extern char common_comm[], common_comm2[], *common_argv[];
171
+ typedef struct {
172
+ int i1, i2, i3, i4, i5, i6, i7, i8, i9;
173
+ LONG l1, l2, l3, l4, l5, l6, l7, l8, l9;
174
+ double d1, d2, d3, d4, d5, d6, d7, d8, d9;
175
+ char *s1, *s2, *s3, *s4, *s5, *s6, *s7, *s8, *s9;
176
+ void *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8, *p9;
177
+ } PARAMS;
178
+ extern PARAMS internal_params;
179
+
180
+
181
+ /* lock&unlock for multi-core mode */
182
+ #ifdef MULTI_CORE
183
+ extern int SPIN_LOCK_dummy;
184
+ #define SPIN_LOCK(b,a) (SPIN_LOCK_dummy=(((b)>1)&&pthread_spin_lock(&(a))))
185
+ #define SPIN_UNLOCK(b,a) (SPIN_LOCK_dummy=(((b)>1)&&pthread_spin_unlock(&(a))))
186
+ #else
187
+ #define SPIN_LOCK(b,a)
188
+ #define SPIN_UNLOCK(b,a)
189
+ #endif
190
+
191
+ #define TYPE_VEC 1
192
+ #define TYPE_MAT 2
193
+ #define TYPE_SVEC 3
194
+ #define TYPE_SMAT 4
195
+ #define TYPE_QUEUE 5
196
+ #define TYPE_SETFAMILY 6
197
+ #define TYPE_TRSACT 7
198
+ #define TYPE_ALIST 8
199
+ #define TYPE_MALIST 9
200
+ #define TYPE_AGRAPH 10
201
+ #define TYPE_SGRAPH 11
202
+ #define TYPE_AHEAP 12
203
+ #define TYPE_BASE 13
204
+ #define TYPE_FSTAR 14
205
+ #define TYPE_SEQ 15
206
+ #define TYPE_BARRAY 16
207
+ #define TYPE_VHEAP 17
208
+ #define TYPE_IHEAP 18
209
+
210
+ #define TYPE_FILE2 32
211
+
212
+ #define ADDR_FLOOR16(x) do{common_charp=((char *)x)+15;x=(typeof(x))(common_charp-(((size_t)common_charp)&15));}while(0)
213
+ double SQRT(double x);
214
+
215
+ /* random */
216
+ #define rnd(a) (random()%(a))
217
+ #define prob(a) ((random()%65536)<(int)((a)*65536.0))
218
+
219
+ #define MARK 1
220
+ #define UNMARK 0
221
+ #define TRUE 1
222
+ #define FALSE 0
223
+
224
+ /* equal/inequal with allowing numerical error for double */
225
+ #define ISEQUAL(a,b) ((a)-(b)<ISEQUAL_VALUE&&(b)-(a)<ISEQUAL_VALUE)
226
+ #define ISGREAT(a,b) ((a)-(b)>ISEQUAL_VALUE)
227
+ #define ISLESS(a,b) ((b)-(a)>ISEQUAL_VALUE)
228
+ #define RANGE(a,b,c) (((a)<=(b))&&((b)<=(c)))
229
+ #define BITRM(a,b) ((a)-=((a)&(b)));
230
+
231
+ /* macro for getting maximum/minimum of two values */
232
+ #define MAX(a,b) (((a)>(b))?(a):(b))
233
+ #define ENMAX(a,b) ((a)=(((a)>(b))?(a):(b)))
234
+ #define MIN(a,b) (((a)<(b))?(a):(b))
235
+ #define ENMIN(a,b) ((a)=(((a)<(b))?(a):(b)))
236
+
237
+ /* error routine */
238
+ #define error(mes,x) do{ERROR_MES=mes;fprintf(stderr,"%s\n",mes);x;}while(0)
239
+ #define error_num(mes,n,x) do{ERROR_MES=mes;fprintf(stderr,"%s: %g\n",mes,(double)(n));x;}while(0)
240
+ #define error_range(f,x,y,mes) do{if(!RANGE((x),(f),(y))){ERROR_MES=mes;fprintf(stderr,"%s: %g\n",mes,(double)(f));EXIT;}}while(0)
241
+ #define error_str(mes,s,x) do{ERROR_MES=mes;fprintf(stderr,"%s: %s\n",mes,s);x;}while(0)
242
+ #define print_err(...) fprintf(stderr,__VA_ARGS__)
243
+ #define print_mes(S,...) do{if(((S)->flag)&1)fprintf(stderr,__VA_ARGS__);}while(0)
244
+ //#define print_fname(s,fname,...) do{if(fname)fprintf(stderr,s,fname,__VA_ARGS__);}while(0)
245
+ #define print_fname(s,fname,...) do{if(fname)fprintf(stderr,s,fname);}while(0)
246
+ #define mfree(...) mfree_(NULL, __VA_ARGS__, (void *)1)
247
+ #define mfree2(...) mfree2_(NULL, __VA_ARGS__, (void *)1)
248
+
249
+
250
+ /* basic array operations and loops */
251
+ #define ARY_FILL(f,start,end,c) do{for(common_size_t=(size_t)(start);common_size_t<(size_t)(end);common_size_t++)(f)[common_size_t]=(c);}while(0)
252
+ //#define ARY_FLOOP(V,i,x) for( (i)=0,x=(V).v[0] ; (i)<(V).t ; (i)++,x=(V).v[i])
253
+ //#define ARY_BLOOP(V,i,x) for( (i)=(V).t-1,x=i>0?(V).v[i]:0 ; (i)>=0 ; (i)--,(x)=(i)>0?(V).v[i]:0)
254
+ #define FLOOP(i,x,y) for ((i)=(x) ; (i)<(y) ; (i)++)
255
+ #define BLOOP(i,x,y) for ((i)=(x) ; ((i)--)>(y) ; )
256
+ #define MLOOP(z,x,M) for ((z)=(x) ; *(z)<(M) ; (z)++)
257
+ /* binary search: return maximum index no larger than c */
258
+ #define BIN_SRCH(x,a,s,t,c) \
259
+ do {\
260
+ x=s; common_size_t=t; while ( x<common_size_t-1 ){\
261
+ if ( a[(x+common_size_t)/2] <= c ) x = (x+common_size_t)/2; else common_size_t = (x+common_size_t)/2;\
262
+ } while (0)\
263
+
264
+ /* allocate memory, and exit with error message if fault */
265
+ #ifdef _cplusplus_
266
+ #define malloc2(f,b,x) do{if(!((f)=(typeof(f))malloc(((size_t)sizeof((f)[0]))*(b)))){fprintf(stderr,"memory allocation error: line %d" #f " (" LONGF " byte)\n",__LINE__,(LONG)((LONG)sizeof((f)[0])*(b)));ERROR_MES="out of memory";x;}}while(0)
267
+ #define calloc2(f,b,x) do{if(!((f)=(typeof(f))calloc(sizeof((f)[0]),b))){fprintf(stderr,"memory allocation error: line %d" #f " (" LONGF " byte)\n",__LINE__,(LONG)((LONG)sizeof((f)[0])*(b)));ERROR_MES="out of memory";x;}}while(0)
268
+ #define realloc2(f,b,x) do{if(!(f=(typeof(f))realloc(f,((size_t)sizeof((f)[0]))*(b)))){fprintf(stderr,"memory allocation error: line %d" #f " (" LONGF " byte)\n",__LINE__,(LONG)((LONG)sizeof((f)[0])*(b)));ERROR_MES="out of memory";x;}}while(0)
269
+ #else
270
+ #define malloc2(f,b,x) do{if(!((f)=malloc(((size_t)sizeof((f)[0]))*(b)))){fprintf(stderr,"memory allocation error: line %d" #f " (" LONGF " byte)\n",__LINE__,(LONG)((LONG)sizeof((f)[0])*(b)));ERROR_MES="out of memory";x;}}while(0)
271
+ #define calloc2(f,b,x) do{if(!((f)=calloc(sizeof((f)[0]),b))){fprintf(stderr,"memory allocation error: line %d: " #f " (" LONGF " byte)\n",__LINE__,(LONG)((LONG)sizeof((f)[0])*(b)));ERROR_MES="out of memory";x;}}while(0)
272
+ #define realloc2(f,b,x) do{if(!(f=realloc(f,((size_t)sizeof((f)[0]))*(b)))){fprintf(stderr,"memory allocation error: line %d: " #f " (" LONGF " byte)\n",__LINE__, (LONG)((LONG)sizeof((f)[0])*(b)));ERROR_MES="out of memory";x;}}while(0)
273
+ #endif
274
+
275
+ #define malloc2d(f,b,d,x) do{malloc2(f,b,x);malloc2((f)[0],(b)*(d)+2,{free2(f);x;});FLOOP(common_size_t,0,(size_t)b)(f)[common_size_t]=&((f)[0][common_size_t*(d)]);}while(0)
276
+ #define calloc2d(f,b,d,x) do{malloc2(f,b,x);calloc2((f)[0],((size_t)(b))*((size_t)(d))+2,{free2(f);x;});FLOOP(common_size_t,0,(size_t)b)(f)[common_size_t]=&((f)[0][common_size_t*(d)]);}while(0)
277
+
278
+ /* reallocate memory and expand the memory size */
279
+ #define reallocx_(f,end,end2,e,x) do{realloc2(f,end2,x);FLOOP(common_size_t,(size_t)end,(size_t)end2)(f)[common_size_t]=(e);}while(0)
280
+ #define reallocx(f,end,i,e,x) do{if((size_t)(i)>=(size_t)(end)){reallocx_(f,end,MAX((end)*2+16,(i)+1),e,x);end=MAX((end)*2,(i)+1);}}while(0)
281
+ #define reallocz(f,end,i,x) do{if((size_t)(i)>=(size_t)(end)){end=MAX((end)*2,(i)+1);realloc2(f,end,x);}}while(0)
282
+ #define realloc_set(f,end,i,e,ee,x) do{if((size_t)(i)>=(size_t)(end)){reallocx_(f,end,MAX((end)*2+16,(i)+1),e,x);end=MAX((end)*2,(i)+1);}f[i]=ee;}while(0)
283
+ #define realloci(f,i,x) do{if(!((i)&((i)-1)))realloc2(f,(i)*2+1,x);}while(0)
284
+
285
+ /* basic array operations */
286
+ #define ARY_REALLOCX(f,i,e,x) reallocz((f).v,(f).end,i,e,x)
287
+ #define ARY_REALLOCZ(f,i,x) reallocz((f).v,(f).end,i,x)
288
+ #define ARY_DUP(f,p,end,x) do{malloc2(f,end,x);memcpy(f,p,sizeof(*(f))*(end));}while(0)
289
+ #define ARY_MAX(m,i,f,x,y) do{(m)=(f)[x];(i)=(x);FLOOP(common_INT,(x)+1,(y))if((m)<(f)[common_INT]){(i)=common_INT;(m)=(f)[i];}}while(0)
290
+ #define ARY_MIN(m,i,f,x,y) do{(m)=(f)[x];(i)=(x);FLOOP(common_INT,(x)+1,y)if((m)>(f)[common_INT]){(i)=common_INT;(m)=(f)[i];}}while(0)
291
+ #define ARY_SUM(f,v,x,y) do{(f)=0;FLOOP(common_INT,x,y)(f)+=(v)[common_INT];}while(0)
292
+ #define ARY_REV(S,start,end,tmp) do{FLOOP(common_size_t,0,((end)-(start))/2){(tmp)=(S)[(start)+common_size_t];(S)[(start)+common_size_t]=(S)[(end)-1-common_size_t];(S)[(end)-1-common_size_t]=tmp;}}while(0)
293
+ #define ARY_NORM(f,v,b) do{(f)=0;FLOOP(common_INT,0,b)(f)+=(v)[common_INT]*(v)[common_INT];(f)=sqrt(f);}while(0)
294
+ #define ARY_NORMALIZE(v,b) do{ARY_NORM(common_double,v,b);FLOOP(common_INT,0,b)(v)[common_INT]/=common_double;}while(0)
295
+ #define ARY_INPRO(f,u,v,b) do{(f)=0;for (common_INT=0 ; common_INT<(b)-3 ; common_INT+=4) (f)+=(u)[common_INT]*(v)[common_INT] + (u)[common_INT+1]*(v)[common_INT+1] + (u)[common_INT+2]*(v)[common_INT+2] + (u)[common_INT+3]*(v)[common_INT+3]; if (common_INT+1<(b)){(f)+=(u)[common_INT]*v[common_INT]+(u)[common_INT+1]*(v)[common_INT+1]; if (common_INT+2<(b)) (f)+=(u)[common_INT+2]*(v)[common_INT+2];} else if (common_INT<(b)) (f)+=(u)[common_INT]*(v)[common_INT];}while(0)
296
+ #define ARY_DIST(f,u,v,b) do{(f)=0;for (common_INT=0 ; common_INT<(b) ; common_INT++) (f)+=((u)[common_INT]-(v)[common_INT])*((u)[common_INT]-(v)[common_INT]); (f)=sqrt(f);}while(0)
297
+
298
+
299
+ /* macros for permutation arrays */
300
+ #define ARY_INIT_PERM(f,end) do{FLOOP(common_INT,0,(INT)end)(f)[common_INT]=common_INT;}while(0)
301
+ #define ARY_INV_PERM_(f,p,end) do{ARY_FILL(f,0,end,-1);FLOOP(common_INT,0,end)if((p)[common_INT]>=0&&(p)[common_INT]<(end))(f)[(p)[common_INT]]=common_INT;}while(0)
302
+ #define ARY_INV_PERM(f,p,end,x) do{malloc2(f,end,x);ARY_INV_PERM_(f,p,end);}while(0)
303
+ #define ARY_RND_PERM_(f,end) do{(f)[0]=0;FLOOP(common_INT,1,end){common_INT2=rnd(common_INT+1);(f)[common_INT]=(f)[common_INT2];(f)[common_INT2]=common_INT;}}while(0)
304
+ #define ARY_RND_PERM(f,end,x) do{malloc2(f,end,x);ARY_RND_PERM_(f,end);}while(0)
305
+ /* permute f so that f[i]=f[p[i]] (inverse perm). p will be destroyed (filled by end). s is temporary variable of type same as f[] */
306
+ #define ARY_INVPERMUTE_(f,p,s,end) do{ FLOOP(common_INT,0,end){ if ( (p)[common_INT]<(end) ){ (s)=(f)[common_INT]; do { common_INT2=common_INT; common_INT=(p)[common_INT]; (f)[common_INT2]=(f)[common_INT]; (p)[common_INT2]=end; }while ( (p)[common_INT]<(end) ); (f)[common_INT2] = (s);}}}while(0)
307
+ /* permute f so that f[i]=f[p[i]] (inverse perm). not destroy p by allocating tmp memory, s is temporary variable of type same as f[] */
308
+ #define ARY_INVPERMUTE(f,p,s,end,x) do{ calloc2(common_pnt,end,x);FLOOP(common_INT,0,end){ if ( common_pnt[common_INT]==0 ){ (s)=(f)[common_INT]; do{ common_INT2=common_INT; common_INT=(p)[common_INT]; (f)[common_INT2]=(f)[common_INT]; common_pnt[common_INT2]=1; }while( common_pnt[common_INT]==0 ); (f)[common_INT2] = (s); }} free(common_pnt); }while(0)
309
+ //#define ARY_PERM(f,p,s,mark,end) do{FLOOP(common_size_t,0,end){ }}while(0)
310
+
311
+ /* macros for printing (writing to file) arrays */
312
+ #define ARY_PRINT(f,x,y,a) do{FLOOP(common_size_t,x,y)printf(a,(f)[common_size_t]);printf("\n");}while(0)
313
+ #define ARY_FPRINT(fp,f,x,y,a) do{FLOOP(common_size_t,(size_t)x,(size_t)y)fprintf((FILE *)fp,a,(f)[common_size_t]);fputc('\n',(FILE *)fp);}while(0)
314
+
315
+ #define ST_MAX(m,i,S,a,x,y) do{(m)=(S)[x].a;(i)=(x);FLOOP(common_INT,(x)+1,y)if((m)<(S)[common_INT].a){(i)=common_INT;(m)=(S)[i].a;}}while(0)
316
+ #define ST_MIN(m,i,S,a,x,y) do{(m)=(S)[x].a;(i)=(x);FLOOP(common_INT,(x)+1,y)if((m)>(S)[common_INT].a){(i)=common_INT;(m)=(S)[i].a;}}while(0)
317
+ #define ST_SUM(k,S,a,x,y) do{(k)=0;FLOOP(common_INT,x,y)(k)+=(S)[common_INT].a;}while(0)
318
+ #define ST_FILL(S,a,start,end,c) do{for(common_INT=(start);common_INT<(end);common_INT++)(S)[common_INT].a = (c);}while(0)
319
+ #define ST_PRINT(S,a,start,end,form) do{FLOOP(common_size_t,start,end)printf(form,(S)[common_size_t].a );printf("\n");}while(0)
320
+
321
+
322
+ /* macros for QUE type structure (have .s, .t, .v) */
323
+ #define QUE_EXP(f,a,x) do{reallocx((f).v,a,(f).end,(f).t,e,x);}while(0)
324
+ #define QUE_INS(f,b) do{(f).v[(f).t++]=(b);}while(0)
325
+ #define QUE_INSZ(f,a,x) do{reallocz((f).v,(f).end,(f).t+1,x);QUE_INS(f,a);}while(0)
326
+ #define QUE_INIT_PERM(f,end) do{ARY_INIT_PERM((f).v,(end));(f).t=(end);(f).s=0;}while(0)
327
+
328
+ /* a macro for open files with exiting if an error occurs */
329
+ #ifdef _MSC_
330
+ #define fopen2(f,a,b,x) do{fopen_s(&f,a,b);if(!f){ERROR_MES="file open error";fprintf(stderr,"file open error: file name %s, open mode %s\n",a,b);x;}}while(0)
331
+ #else
332
+ #define fopen2(f,a,b,x) do{if(!((f)=fopen(a,b))){ERROR_MES="file open error";fprintf(stderr,"file open error: file name %s, open mode %s\n",a,b);x;}}while(0)
333
+ #endif
334
+
335
+ #ifdef _FILE2_LOAD_FROM_MEMORY_
336
+ #define FILE2_open(f,a,b,x) do{__load_from_memory__=__load_from_memory_org__;(f).fp=NULL;malloc2((f).buf_org,FILE2_BUFSIZ+1,x);(f).buf=(f).buf_org;(f).buf_end=(f).buf_org-1;(f).bit=0;*(f).buf=0;}while(0)
337
+ #define FILE2_open_(f,a,x) do{__load_from_memory__=__load_from_memory_org__;(f).fp=a;malloc2((f).buf_org,FILE2_BUFSIZ+1,x);(f).buf=(f).buf_org;(f).buf_end=(f).buf_org-1;(f).bit=0;*(f).buf=0;}while(0)
338
+ #else
339
+ #define FILE2_open(f,a,b,x) do{if(a)fopen2((f).fp,a,b,x);else(f).fp=NULL;malloc2((f).buf_org,FILE2_BUFSIZ+1,x);(f).buf=(f).buf_org;(f).buf_end=(f).buf_org-1;(f).bit=0;*(f).buf=0;}while(0)
340
+ #define FILE2_open_(f,a,x) do{(f).fp=a;malloc2((f).buf_org,FILE2_BUFSIZ+1,x);(f).buf=(f).buf_org;(f).buf_end=(f).buf_org-1;(f).bit=0;*(f).buf=0;}while(0)
341
+ #endif
342
+
343
+ /* macros for allocating memory with exiting if an error occurs */
344
+ #define free2(a) do{if(a){free(a);(a)=NULL;}}while(0)
345
+ #define free2d(a) do{if(a){free2((a)[0]);free(a);(a)=NULL;}}while(0)
346
+ #ifdef _FILE2_LOAD_FROM_MEMORY_
347
+ #define fclose2(a) do{if(a){(a)=NULL;}}while(0)
348
+ #else
349
+ #define fclose2(a) do{if(a){fclose(a);(a)=NULL;}}while(0)
350
+ #endif
351
+ /* macros for reading integers from file, d=0 read one-line, d=1 read all file */
352
+ //#define ARY_SCAN(k,a,fp,d) do{(k)=0;do{do{FILE2_read_##a(&(fp));}while((FILE_err&6)==8-(d)*4);if(FILE_err&(4-2*(d)))break;(k)++;}while((FILE_err&(3-(d)))==0);}while(0)
353
+ #define ARY_SCAN(num,type,fp,d) do{(num)=0;do{do{FILE2_read_##type(&(fp));}while((FILE_err&((d)*5))==5);if(RANGE(5+(int)(d),FILE_err,6))break;(num)++;}while((FILE_err&(3-(int)(d)))==0);}while(0)
354
+ #define ARY_READ_LINE(f,type,num,fp) do{(num)=0;do{(f)[num]=FILE2_read_##type(&(fp));(num)+=(FILE_err&4)?0:1;}while((FILE_err&3)==0);}while(0)
355
+ #define ARY_READ(f,type,num,fp) do{FLOOP(common_size_t,0,(size_t)num){do{(f)[common_size_t]=FILE2_read_##type(&(fp));}while((FILE_err&6)==4);if(FILE_err&2)break;}}while(0)
356
+ #define ARY_LOAD(f,type,num,fname,d,x) do{FILE2_open(common_FILE2,fname,"r",x);ARY_SCAN(num,type,common_FILE2,d);malloc2(f,(num)+1,x);FILE2_reset(&common_FILE2);ARY_READ(f,type,num,common_FILE2);FILE2_close(&common_FILE2);}while(0)
357
+ #define ARY_WRITE(n,f,num,q,x) do{fopen2(common_FILE,n,"w",x);ARY_FPRINT(common_FILE,f,0,num,q);fclose(common_FILE);}while(0)
358
+
359
+ #ifndef MQUE_ONEMORE
360
+ #define MQUE_ONEMORE 1
361
+ #endif
362
+
363
+ /* macros for generalized queue; end mark is necessary for INTSEC */
364
+ #define MQUE_FLOOP(V,z) for((z)=(V).v;(z)<(V).v+(V).t ; (z)++)
365
+ #define MQUE_FLOOP2(V,z,zz) for((z)=(V).v,(zz)=(z)+(V).t;(z)<(zz) ; (z)++)
366
+ #define MQUE_BLOOP(V,z) for((z)=(V).v+(V).t-1;(z)>=(V).v ; (z)--)
367
+ #define MQUE_SLOOP(V,z) for((z)=(V).v+(V).s;(z)<(V).v+(V).t ; (z)++)
368
+ #define MQUE_SLOOP2(V,z,zz) for((z)=(V).v+(V).s,(zz)=(z)+(V).t;(z)<(zz) ; (z)++)
369
+ #define MQUE_SBLOOP(V,z) for((z)=(V).v+(V).t-1;(z)>=(V).v+(V).s ; (z)--)
370
+
371
+ #ifdef _cplusplus_
372
+ #define MQUE_FLOOP_(V,z,s) for((z)=(V).v ; (char *)(z)<((char *)(V).v)+(V).t*(s) ; (z)=(typeof(z))(((char *)(z))+(s)))
373
+ #else
374
+ #define MQUE_FLOOP_(V,z,s) for((z)=(V).v ; (char *)(z)<((char *)(V).v)+(V).t*(s) ; (z)=(void *)(((char *)(z))+(s)))
375
+ #endif
376
+
377
+ #define MQUE_MLOOP(V,z,M) for((z)=(V).v; *((QUEUE_INT *)z)<(M) ; (z)++)
378
+
379
+ /// !!! errr MQUE_INTSEC !!!!!
380
+ #define MQUE_INTSEC(f,U,V) do{\
381
+ common_INT=0;(f)=0;\
382
+ FLOOP(common_INT2,0,(U).t){\
383
+ while(*((QUEUE_INT *)(&((V).v[common_INT])))<*((QUEUE_INT *)(&((U).v[common_INT2])))&&common_INT<(V).t){ \
384
+ if (++common_INT >= (V).t) break;\
385
+ }if(*((QUEUE_INT *)(&((V).v[common_INT])))==*((QUEUE_INT *)(&((U).v[common_INT2]))))(f)++;\
386
+ }}while(0)
387
+ #define MQUE_UNION(f,U,V) do{MQUE_INTSEC(f,U,V);(f)=(U).t+(V).t-(f);}while(0)
388
+ #define MQUE_DIF(f,U,V) do{MQUE_INTSEC(f,U,V);(f)=(U).t+(V).t-(f)-(f);}while(0)
389
+ #define MQUE_RM_DUP(V) do{\
390
+ if((V).t>1){\
391
+ common_INT=1;\
392
+ FLOOP(common_INT2,1,(V).t){\
393
+ if ( *((QUEUE_INT *)(&((V).v[common_INT2-1]))) != *((QUEUE_INT *)(&((V).v[common_INT2]))) ) (V).v[common_INT++]=(V).v[common_INT2];\
394
+ } (V).t=common_INT;\
395
+ }\
396
+ }while(0)
397
+
398
+ #define MQUE_UNIFY(V,a) do{\
399
+ if((V).t>1){\
400
+ common_INT=0;\
401
+ FLOOP(common_INT2,1,(V).t){\
402
+ if ( *((QUEUE_INT *)(&((V).v[common_INT2-1]))) != *((QUEUE_INT *)(&((V).v[common_INT2]))) ) (V).v[++common_INT]=(V).v[common_INT2];\
403
+ else *((a*)(((QUEUE_INT *)(&((V).v[common_INT2])))+1)) += *((a*)(((QUEUE_INT *)(&((V).v[common_INT2])))+1));\
404
+ } (V).t=common_INT+1;\
405
+ }}while(0)
406
+
407
+
408
+
409
+
410
+ #ifndef VEC_VAL
411
+ #ifdef VEC_VAL_CHAR
412
+ #define VEC_VAL char
413
+ #define VEC_VAL2 LONG
414
+ #define VEC_VAL_END 128
415
+ #define VEC_VAL2_END LONGHUGE
416
+ #define VEC_VALF "%hhd"
417
+ #elif defined(VEC_VAL_UCHAR)
418
+ #define VEC_VAL unsigned char
419
+ #define VEC_VAL2 LONG
420
+ #define VEC_VAL_END 256
421
+ #define VEC_VAL2_END LONGHUGE
422
+ #define VEC_VALF "%hhu"
423
+ #elif defined(VEC_VAL_INT)
424
+ #define VEC_VAL int
425
+ #define VEC_VAL2 LONG
426
+ #define VEC_VAL_END INTHUGE
427
+ #define VEC_VAL2_END LONGHUGE
428
+ #define VEC_VALF "%d"
429
+ #else
430
+ #define VEC_VAL double
431
+ #define VEC_VAL2 double
432
+ #define VEC_VAL_END DOUBLEHUGE
433
+ #define VEC_VAL2_END DOUBLEHUGE
434
+ #define VEC_VALF "%f"
435
+ #endif
436
+ #endif
437
+
438
+ #ifndef VEC_ID
439
+ #ifdef VEC_ID_LONG
440
+ #define VEC_ID LONG
441
+ #define VEC_ID_END LONGHUGE
442
+ #define VEC_IDF LONGF
443
+ #else
444
+ #define VEC_ID int
445
+ #define VEC_ID_END INTHUGE
446
+ #define VEC_IDF "%d"
447
+ #endif
448
+ #endif
449
+
450
+
451
+ /* vector */
452
+ typedef struct {
453
+ unsigned char type; // mark to identify type of the structure
454
+ VEC_VAL *v;
455
+ VEC_ID end;
456
+ VEC_ID t;
457
+ } VEC;
458
+
459
+ extern VEC INIT_VEC;
460
+ extern PERM common_PERM, *common_PERMp;
461
+ extern VEC_VAL common_VEC_VAL, *common_VEC_VALp;
462
+ extern VEC_ID common_VEC_ID;
463
+
464
+ /* tranpose the matrix ; counting/transpose/memory_allocate */
465
+ #define MQUE_DELIVERY_CNT(c,jump,f,y,M) do{ \
466
+ FLOOP(common_VEC_ID, 0, (f).t){ \
467
+ MQUE_MLOOP( (f).v[common_VEC_ID], y, M){ \
468
+ if( (c)[*((QUEUE_INT *)y)] == 0 ) QUE_INS(jump, *((QUEUE_INT *)y)); \
469
+ (c)[*((QUEUE_INT *)y)]++; \
470
+ } \
471
+ }}while(0)
472
+ #define MQUE_DELIVERY(occ,jump,f,y,M) do{ \
473
+ FLOOP (common_VEC_ID, 0, (f).t){ \
474
+ MQUE_MLOOP ((f).v[common_VEC_ID], y, M){ \
475
+ if( (occ)[*((QUEUE_INT *)y)].t == 0 ) QUE_INS( jump, *((QUEUE_INT *)y)); \
476
+ QUE_INS( (occ)[*((QUEUE_INT *)y)], common_VEC_ID); \
477
+ } \
478
+ }}while(0)
479
+
480
+ // allocate QUEUE of QUEUE, according to rows (cells of "ext" will be add to each row)
481
+ #ifdef _cplusplus_
482
+ #define MQUE_ALLOC(Q,rows,rowt,unit,ext,x) do{ \
483
+ common_size_t=0; \
484
+ FLOOP (common_VEC_ID, 0, rows) common_size_t += rowt[common_VEC_ID]; \
485
+ calloc2 (Q, (rows)+1, x); \
486
+ malloc2 (common_pnt, (common_size_t+(rows)*(ext)+2)*((unit)<sizeof(QUEUE_INT)?sizeof(QUEUE_INT):(unit)), {free(Q);x;}); \
487
+ FLOOP (common_VEC_ID, 0, rows){ \
488
+ (Q)[common_VEC_ID].end = rowt[common_VEC_ID]; \
489
+ (Q)[common_VEC_ID].v = (typeof((Q)[common_VEC_ID].v))common_pnt; \
490
+ common_pnt += ((unit)<sizeof(QUEUE_INT)?sizeof(QUEUE_INT):(unit))*(rowt[common_VEC_ID]+(ext));\
491
+ }}while(0)
492
+ #else
493
+ #define MQUE_ALLOC(Q,rows,rowt,unit,ext,x) do{ \
494
+ common_size_t=0; \
495
+ FLOOP (common_VEC_ID, 0, rows) common_size_t += rowt[common_VEC_ID]; \
496
+ calloc2 (Q, (rows)+1, x); \
497
+ malloc2 (common_pnt, (common_size_t+(rows)*(ext)+2)*((unit)<sizeof(QUEUE_INT)?sizeof(QUEUE_INT):(unit)), {free(Q);x;}); \
498
+ FLOOP (common_VEC_ID, 0, rows){ \
499
+ (Q)[common_VEC_ID].end = rowt[common_VEC_ID]; \
500
+ (Q)[common_VEC_ID].v = (void *)common_pnt; \
501
+ common_pnt += ((unit)<sizeof(QUEUE_INT)?sizeof(QUEUE_INT):(unit))*(rowt[common_VEC_ID]+(ext));\
502
+ }}while(0)
503
+ #endif
504
+
505
+ /**********************************************************/
506
+ /* macro for execute the programs as subroutine */
507
+ /* do not nest the macro; <= variable will be used doubly */
508
+ /**********************************************************/
509
+ // execute the main routine of the program as a subroutine
510
+ #define EXECSUB(func,flag,err,fmt,...) do{\
511
+ sprintf (common_comm, fmt, __VA_ARGS__);\
512
+ if ( flag&SHOW_MESSAGE ) print_err ("%s\n", common_comm);\
513
+ common_INT = string_decompose (common_argv, common_comm, ' ', 100);\
514
+ if ( func (common_INT, common_argv) ) err;\
515
+ }while(0)
516
+ // remove a file on the specified directory
517
+ #define REMOV(dir,fn) do{ sprintf(common_comm,"%s%s",dir,fn); remove (common_comm); }while(0)
518
+ #define RENAM(dir,fn,fn2) do{ sprintf(common_comm,"%s%s",dir,fn); sprintf(common_comm2,"%s%s",dir,fn2); rename (common_comm, common_comm2); }while(0)
519
+ #define MREMOV(dir,...) mremove_(dir, __VA_ARGS__, NULL, NULL)
520
+
521
+
522
+ /*********************************************************/
523
+
524
+
525
+ #define SHOW_MESSAGE 1 // not print messages
526
+ #define SHOW_PROGRESS 2 // show progress of the computation
527
+ #define APPEND_OUTPUT 4 // append the output to existing file
528
+ #define NO_REMOVE 8 // do not remove the temporal files
529
+ #define LOAD_PERM 64 // permute the nodes/items by something
530
+ #define LOAD_RM_DUP 128 // duplicate items in each row, for loading data
531
+ #define LOAD_INCSORT 256 // sort rows in increasing order, for loading data
532
+ #define LOAD_DECSORT 512 // sort rows in decreasing order, for loading data
533
+ #define LOAD_ELE 1024 // load tuple-list file
534
+ #define LOAD_TPOSE 2048 // transpose the file when load
535
+ #define LOAD_DBLBUF 4096 // allocate double-size memory for element buffer
536
+ #define LOAD_WSORT 8192 // sort rows by their weights
537
+ #define LOAD_SIZSORT 16384 // sort rows by their sizes
538
+ #define LOAD_DECROWSORT 32768 // sort rows in decreasing order
539
+ #define LOAD_NUM 65536 // read #columns, #rows and #elements from the 1st line of the file
540
+
541
+ #define LOAD_EDGEW 131072 // read edge weight
542
+ //#define LOAD_ARCW 262144 // read arc weight
543
+ #define LOAD_NODEW 524288 // read node weight
544
+ #define LOAD_BIPARTITE 1048576 // read bipartite graph
545
+ #define LOAD_EDGE 2097152 // read edge
546
+ #define LOAD_ARC 4194304 // read arc
547
+ #define LOAD_GRAPHNUM 8388608 // read #vertices and #edges from the 1st line of the file
548
+ #define LOAD_ID1 16777216 // node ID begins from 1
549
+ #define LOAD_COMP 33554432 // read as a complement
550
+ #define LOAD_RC_SAME 67108864 // set #rows and #columns to the maximum of them
551
+
552
+ #define FILE_COUNT_ROWT 32 // count size of each row
553
+ #define FILE_COUNT_CLMT 64 // count size of each column
554
+ #define FILE_COUNT_NUM LOAD_NUM // read #columns, #rows and #elements
555
+ #define FILE_COUNT_GRAPHNUM LOAD_GRAPHNUM // read #vertices and #edges
556
+
557
+ #define FILE2_BUFSIZ 16384
558
+ typedef struct { // structure for fast file reader routines
559
+ unsigned char type; // type definition
560
+ FILE *fp;
561
+ char *buf_org, *buf, *buf_end; // head/current/tail of buffer
562
+ char bit;
563
+ } FILE2;
564
+ extern FILE2 INIT_FILE2, common_FILE2;
565
+
566
+ void FILE2_flush (FILE2 *fp);
567
+ void FILE2_close (FILE2 *fp);
568
+ void FILE2_closew (FILE2 *fp);
569
+ void FILE2_reset (FILE2 *fp);
570
+ void FILE2_copy (char *f1, char *f2);
571
+
572
+ int FILE2_getc (FILE2 *fp);
573
+ void FILE2_puts (FILE2 *fp, char *s);
574
+ void FILE2_putc (FILE2 *fp, char c);
575
+ int FILE2_getbit (FILE2 *fp);
576
+ void FILE2_putbit (FILE2 *fp, int a);
577
+
578
+ /* message output */
579
+ //void print_mes (int flag, char *mes, ...);
580
+ //void print_err (char *mes, ...);
581
+
582
+ /* free many pointers*/
583
+ void mfree_(void *x, ...);
584
+ void mfree2_(void *x, ...);
585
+
586
+ /* remove many files */
587
+ void mremove_ (char *x, ...);
588
+
589
+ /* compute the minimum prime no less than n */
590
+ LONG min_prime (LONG n);
591
+
592
+ /* decompose the string by separator, and set v[i] to each resulted string.
593
+ consecutive separators are regarded as one separator. */
594
+ int string_decompose (char **v, char *s, char sep, int max);
595
+
596
+ /* make two random numbers under normal distribution N(0,1) */
597
+ void rand_mk_2normal (double *a, double *b);
598
+ /* make a random point on a supersphere of d-dim., and set to double array already allocated */
599
+ void rand_d_gaussian (double *p, int d);
600
+ void rand_sphere (double *p, int d);
601
+
602
+
603
+
604
+ /* Read an integer from the file and return it,
605
+ with read through the non-numeric letters.
606
+ If it reaches to the end-of-file, then set FILE_err=2, if it reads a
607
+ newline, then set FILE_err=1.
608
+ If read either the end-of-file or newline before reading an integer,
609
+ return -1 */
610
+ FILE_LONG FILE2_read_int (FILE2 *fp);
611
+ double FILE2_read_double (FILE2 *fp);
612
+ WEIGHT FILE2_read_WEIGHT (FILE2 *fp);
613
+ LONG FILE2_read_mpint (FILE2 *fp, int max, int skip); // multi-precise
614
+ LONG FILE2_read_intbit (FILE2 *fp, int k); // read k bits as integer
615
+
616
+
617
+ /* fast file routine, print number, c is the char to be printed preceding to the number
618
+ if c==0, nothing will be printed preceding the number
619
+ if len<0 then the #digits following '.' does not change (filed by '0') */
620
+ void FILE2_print_int (FILE2 *fp, LONG n, char c);
621
+ void FILE2_print_real (FILE2 *fp, double n, int len, char c);
622
+ void FILE2_print_WEIGHT (FILE2 *fp, WEIGHT w, int len, char c);
623
+ void FILE2_printf (FILE2 *fp, char *mes, ...);
624
+ void FILE2_print_mpint (FILE2 *fp, LONG a, int max, int skip); // multi-precise
625
+ void FILE2_print_intbit (FILE2 *fp, LONG a, int k); // print lowest k-bits
626
+
627
+ /* print a real number in a good style */
628
+ void fprint_real (FILE *fp, double f);
629
+ void print_real (double f);
630
+ void fprint_WEIGHT (FILE *fp, WEIGHT f);
631
+ void print_WEIGHT (WEIGHT f);
632
+
633
+ #define FILE_COUNT_INT VEC_ID
634
+ #define FILE_COUNT_INTF VEC_IDF
635
+ typedef struct {
636
+ int flag;
637
+ FILE_COUNT_INT clms, rows, eles, clm_end, row_end, row_btm, clm_btm; // #rows, #column, #elements, minimum elements
638
+ FILE_COUNT_INT row_min, row_max, clm_min, clm_max; // maximum/minimum size of column
639
+ FILE_COUNT_INT *rowt, *clmt; // size of each row/clmn
640
+ WEIGHT total_rw, total_cw, *rw, *cw; // WEIGHTs for rows/columns ... reserved.
641
+ FILE_COUNT_INT rw_end, cw_end;
642
+ PERM *rperm, *cperm; // permutation (original->internal) of rows and columns
643
+ } FILE_COUNT;
644
+
645
+ extern FILE_COUNT INIT_FILE_COUNT;
646
+
647
+ /* count the clms, rows, items, each row size, each column size */
648
+ /* file types can be, array list and element list*/
649
+ /* support transpose */
650
+ int FILE2_read_pair (FILE2 *fp, LONG *x, LONG *y, double *w, int flag);
651
+ FILE_COUNT FILE2_count (FILE2 *fp, int flag, int skip_rows, int int_rows, int skip_clms, int int_clms, FILE_COUNT_INT row_limit);
652
+
653
+ /******************* integer array routines **************************/
654
+
655
+ /******************************* permutation routines ****************/
656
+ /* permutation is given by an integer array */
657
+
658
+ /* sort an array of size "siz", composed of a structure of size "unit" byte
659
+ in the order of perm */
660
+ /* use temporary memory of siz*unit byte */
661
+ //void perm_struct (void *a, int unit, int *perm, size_t siz);
662
+
663
+ /* SLIST:very simple one-sided list */
664
+ void SLIST_init (int *l, int num, int siz);
665
+ void SLIST_end (int *l);
666
+ #define SLIST_INS(l,m,e) (l[e]=l[m],l[m]=e);
667
+
668
+ #define QQSORT_ELE(a,x) ((a *)(&(common_pnt[(*((PERM *)(x)))*common_int])))
669
+ #define QQSORT_ELEt(a,x) (((a *)&(common_pnt[(*((PERM *)(x)))*common_int]))->t)
670
+ /* quick sort macros */
671
+ #define QSORT_TYPE(a,b) \
672
+ b common_##a; \
673
+ int qsort_cmp_##a (const void *x, const void *y){ \
674
+ if ( *((b *)x) < *((b *)y) ) return (-1); else return ( *((b *)x) > *((b *)y) ); \
675
+ } \
676
+ int qsort_cmp__##a (const void *x, const void *y){ \
677
+ if ( *((b *)x) > *((b *)y) ) return (-1); else return ( *((b *)x) < *((b *)y) ); \
678
+ } \
679
+ int qqsort_cmp_##a (const void *x, const void *y){ \
680
+ b *xx=QQSORT_ELE(b,x), *yy=QQSORT_ELE(b,y); \
681
+ if ( *xx < *yy ) return (-1); \
682
+ else return ( *xx > *yy ); \
683
+ } \
684
+ int qqsort_cmp__##a (const void *x, const void *y){ \
685
+ b *xx=QQSORT_ELE(b,x), *yy=QQSORT_ELE(b,y); \
686
+ if ( *xx > *yy ) return (-1); \
687
+ else return ( *xx < *yy ); \
688
+ } \
689
+ void qsort_##a (b *v, size_t siz, int unit){ \
690
+ if ( unit == 1 || unit==-1 ) unit *= sizeof (b); \
691
+ if (unit<0) qsort (v, siz, -unit, qsort_cmp__##a); else qsort (v, siz, unit, qsort_cmp_##a); \
692
+ } \
693
+ void qsort_perm__##a (b *v, size_t siz, PERM *perm, int unit){ \
694
+ if ( unit == 1 || unit==-1 ) unit *= sizeof (*v); \
695
+ common_int = MAX(unit,-unit); common_pnt = (char *)v; \
696
+ if (unit<0) qsort (perm, siz, sizeof(PERM), qqsort_cmp__##a); \
697
+ else qsort (perm, siz, sizeof(PERM), qqsort_cmp_##a); \
698
+ } \
699
+ PERM *qsort_perm_##a (b *v, size_t siz, int unit){ \
700
+ PERM *perm; malloc2(perm, siz, EXIT0); \
701
+ ARY_INIT_PERM (perm,(PERM)siz); \
702
+ qsort_perm__##a (v, siz, perm, unit); return (perm); \
703
+ } \
704
+ size_t bin_search_##a (b *v, b u, size_t siz, int unit){ \
705
+ size_t s=0, t; \
706
+ b n; \
707
+ if ( unit == 1 ) unit *= sizeof (b); \
708
+ while (1){ \
709
+ if ( siz-s <= 2 ){ \
710
+ if ( u <= *((b *)(((char *)v)+unit*s)) ) return (s);\
711
+ if ( siz == s+1 || u <= *((b *)(((char *)v)+unit*(s+1))) ) return (s+1);\
712
+ return (s+2);\
713
+ }\
714
+ t = (s+siz) /2; \
715
+ n = *((b *)(((char *)v)+unit*t));\
716
+ if ( u < n ) siz = t; else s = t;\
717
+ }\
718
+ }
719
+ // bin search returns the position that is equal to u, or the smallest in larger's
720
+
721
+ #define QSORT_TYPE_HEADER(a,b) \
722
+ extern b common_##a; \
723
+ int qsort_cmp_##a (const void *x, const void *y); \
724
+ int qsort_cmp__##a (const void *x, const void *y); \
725
+ int qqsort_cmp_##a (const void *x, const void *y); \
726
+ int qqsort_cmp__##a (const void *x, const void *y); \
727
+ void qsort_##a(b *v, size_t siz, int unit); \
728
+ void qsort_perm__##a (b *v, size_t siz, PERM *perm, int unit); \
729
+ PERM *qsort_perm_##a (b *v, size_t siz, int unit); \
730
+ size_t bin_search_##a (b *v, b u, size_t siz, int unit);
731
+
732
+ QSORT_TYPE_HEADER(int, int)
733
+ QSORT_TYPE_HEADER(uint, unsigned int)
734
+ QSORT_TYPE_HEADER(double, double)
735
+ QSORT_TYPE_HEADER(char, char)
736
+ QSORT_TYPE_HEADER(uchar, unsigned char)
737
+ QSORT_TYPE_HEADER(short, short)
738
+ QSORT_TYPE_HEADER(ushort, unsigned short)
739
+ QSORT_TYPE_HEADER(WEIGHT, WEIGHT)
740
+ QSORT_TYPE_HEADER(LONG, LONG)
741
+ QSORT_TYPE_HEADER(VEC_ID, VEC_ID)
742
+ QSORT_TYPE_HEADER(VEC_VAL, VEC_VAL)
743
+ QSORT_TYPE_HEADER(VEC_VAL2, VEC_VAL2)
744
+ QSORT_TYPE_HEADER(FILE_COUNT_INT, FILE_COUNT_INT)
745
+
746
+ int qsort_cmp_VECt (const void *x, const void *y);
747
+ int qsort_cmp__VECt (const void *x, const void *y);
748
+ void qsort_VECt (VEC *v, size_t siz, int unit);
749
+ int qqsort_cmp_VECt (const void *x, const void *y);
750
+ int qqsort_cmp__VECt (const void *x, const void *y);
751
+ void qsort_perm__VECt (VEC *v, size_t siz, PERM *perm, int unit);
752
+ PERM *qsort_perm_VECt (VEC *v, size_t siz, int unit);
753
+
754
+ /* swap macro for integer, double, char, and pointer */
755
+ #define SWAP_INT(a,b) (common_LONG=a,a=b,b=common_LONG)
756
+ #define SWAP_LONG(a,b) (common_LONG=a,a=b,b=common_LONG)
757
+ #define SWAP_DOUBLE(a,b) (common_double=a,a=b,b=common_double)
758
+ #define SWAP_size_t(a,b) (common_size_t=a,a=b,b=common_size_t)
759
+ #ifdef _cplusplus_
760
+ #define SWAP_PNT(a,b) (common_pnt=(typeof(common_pnt))a,a=(typeof(a))b,b=(typeof(b))common_pnt)
761
+ #else
762
+ #define SWAP_PNT(a,b) (common_pnt=(void *)a,a=(void *)b,b=(void *)common_pnt)
763
+ #endif
764
+
765
+ #define SWAP_VEC_ID(a,b) (common_VEC_ID=a,a=b,b=common_VEC_ID)
766
+ #define SWAP_FILE_COUNT_INT(a,b) (common_FILE_COUNT_INT=a,a=b,b=common_FILE_COUNT_INT)
767
+
768
+ /* sort index(int)/WEIGHT array and return the indices of the result */
769
+ /* perm[i*2] := rank of ith cell */
770
+ /* perm[i*2+1] := index of ith smallest cell */
771
+ /* flag!=NULL => opposite direction sort */
772
+
773
+ //int *int_index_sort (int *w, size_t siz, int flag);
774
+ //int *WEIGHT_index_sort (WEIGHT *w, size_t siz, int flag);
775
+
776
+ /* radix sort for array of structures, by their integer members
777
+ ranging from mm to m */
778
+ /* sort array "perm" according to (int/void*) array "a".
779
+ if perm==NULL, allocate memory and for perm */
780
+ /* return the permutation array of the result of the sorting
781
+ in the decreasing order if unit<0 (unimplemented!!!) */
782
+ int *radix_sort (void *a, size_t siz, int unit, int mm, int m, int *perm);
783
+
784
+ /* permutate structure array *tt of unit size unit of size num, according to perm array *pp */
785
+ /* num has to be <INTHUGE/2 */
786
+ /* unit<0 means decreasing order (un-implemented!!!) */
787
+ void structure_permute (void *tt, int unit, int num, void *pp, int weight_siz);
788
+
789
+ #ifdef STDLIB2_RADIX_SORT // radix sort with 1M byte static memory
790
+ void intarray_sort_iter (unsigned int *a, size_t siz, int unit);
791
+ void intarray_sort_iter_ (unsigned int *a, size_t siz, int unit);
792
+ void intarray_sort (unsigned *a, size_t siz, int unit);
793
+ #endif
794
+
795
+ /* bitmasks, used for bit operations */
796
+ extern int BITMASK_UPPER1[32];
797
+ extern int BITMASK_UPPER1_[32];
798
+ extern int BITMASK_LOWER1[32];
799
+ extern int BITMASK_LOWER1_[32];
800
+ extern int BITMASK_1[32];
801
+ extern int BITMASK_31[32];
802
+ extern int BITMASK_16[8];
803
+ extern int BITMASK_UPPER16[8];
804
+ extern int BITMASK_LOWER16[8];
805
+ extern int BITMASK_FACT16[8];
806
+
807
+ /* bit operations */
808
+ #define BIT_SET(v,x) (v[x/32]|=BITMASK_1[x%32])
809
+ #define BIT_DEL(v,x) (v[x/32]&=BITMASK_31[x%32])
810
+ #define ISBIT(v,x) (v[x/32]&BITMASK_1[x%32])
811
+
812
+ #ifndef UNIONFIND_ID
813
+ #ifdef UNIONFIND_ID_LONG
814
+ #define UNIONFIND_ID LONG
815
+ #define UNIONFIND_ID_END LONGHUGE
816
+ #define UNIONFIND_IDF LONGF
817
+ #elif defined(UNIONFIND_ID_QUEUE)
818
+ #define UNIONFIND_ID QUEUE_ID
819
+ #define UNIONFIND_ID_END QUEUE_ID_END
820
+ #define UNIONFIND_IDF QUEUE_IDF
821
+ #elif defined(UNIONFIND_ID_ALIST)
822
+ #define UNIONFIND_ID ALIST_ID
823
+ #define UNIONFIND_ID_END ALIST_ID_END
824
+ #define UNIONFIND_IDF ALIST_IDF
825
+ #else
826
+ #define UNIONFIND_ID int
827
+ #define UNIONFIND_ID_END INTHUGE
828
+ #define UNIONFIND_IDF "%d"
829
+ #endif
830
+ #endif
831
+ UNIONFIND_ID UNIONFIND_getID (UNIONFIND_ID v, UNIONFIND_ID *ID);
832
+ void UNIONFIND_unify (UNIONFIND_ID u, UNIONFIND_ID v, UNIONFIND_ID *ID);
833
+
834
+
835
+ #endif
836
+
837
+
838
+ /******************************************/
839
+ /* ==== terminology for comments ====
840
+ range check: to check the input parameter is valid, or in the valid range.
841
+ If a function does not have this, its comment has "no range check"
842
+ */
843
+
844
+ /* ==== rules for the name of functions and routines ====
845
+ init: initialization for an object, structure, etc. memory is allocated
846
+ if needed.
847
+ end: compared to init, termination of structures, etc.
848
+ free allocated memory if it exists, but not free itself.
849
+ different from ordinary new, create, del, free.
850
+
851
+ cpy: copy an object without allocating memory
852
+ dup: make a duplication of an object with allocating new memory
853
+
854
+ new: new. allocate memory for new object. also used for re-allocation from
855
+ the list of deleted objects
856
+ del: delete. free memory, or insert it to the list of deleted objects
857
+
858
+ ins : insert. insert an element (active, not deleted) to an object, possible
859
+ at the given position.
860
+ out : extract. extract an element, possibly specified, from an object.
861
+ it will be not deleted.
862
+ rm : extract, and delete
863
+ rmall: delete all (specified) elements of an object
864
+ mk : make. new+ins�B
865
+ mv : move. move the elements from an object to another,
866
+ or change the position.
867
+
868
+ update : update an object, possibly of specified position, to the exact,
869
+ or to the current one.
870
+ chg : change the status of an object to the specified one.
871
+
872
+ prv: point the previous element
873
+ nxt: point the next element
874
+ end: the maximum size (allocated size) of an array, etc.
875
+ num: the (current) number of elements in an array, etc.
876
+ kth: for the use of "first k object"
877
+ tkth: for the use of "first k object from the end". to kth.
878
+ rnd: random
879
+ print: print structure and etc.
880
+ find: search or find an specified element from the set of structures, etc.
881
+ */
882
+
883
+ /* ==== rules for the name of variables ====
884
+ - use i or j for the counter in loops
885
+ - use e for elements
886
+ - use k for the specified rank
887
+ - use f or flag for flagment
888
+ - use m for maximum value or minimum value
889
+ - use c for counters
890
+ */
891
+
892
+