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