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