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,528 @@
1
+ /* Library of queue: spped priority implementation
2
+ 12/Apr/2001 by Takeaki Uno 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 _queue_c_
13
+ #define _queue_c_
14
+
15
+
16
+ #include"queue.h"
17
+ #include"stdlib2.c"
18
+
19
+ QSORT_TYPE(QUEUE_INT, QUEUE_INT)
20
+ QSORT_TYPE(QUEUE_ID, QUEUE_ID)
21
+ QUEUE INIT_QUEUE = {TYPE_QUEUE,NULL,0,0,0};
22
+ QUEUE_INT *common_QUEUE_INTp;
23
+
24
+ /* initialization, not fill the memory by 0 */
25
+ void QUEUE_alloc (QUEUE *Q, QUEUE_ID siz){
26
+ *Q = INIT_QUEUE;
27
+ Q->end = siz+1;
28
+ malloc2 (Q->v, siz+1, EXIT);
29
+ }
30
+
31
+ /* termination processing */
32
+ void QUEUE_end (QUEUE *Q){
33
+ free2 (Q->v);
34
+ *Q = INIT_QUEUE;
35
+ }
36
+
37
+ /* tranpose the matrix ; counting/transpose/memory_allocate */
38
+ void QUEUE_delivery(QUEUE *OQ, VEC_ID *c, QUEUE *jump, QUEUE *Q, QUEUE *occ, VEC_ID t, QUEUE_INT M){ VEC_ID i, e;
39
+ QUEUE_INT *x;
40
+ FLOOP(i, 0, occ? occ->t: t){
41
+ e = occ? occ->v[i]: i;
42
+ if ( c ){
43
+ if ( jump ){ MLOOP (x, Q[e].v, M){ if ( c[*x]==0 ) QUE_INS (*jump, *x); c[*x]++; }
44
+ } else { MLOOP (x, Q[e].v, M){ c[*x]++; }}
45
+ } else {
46
+ if ( jump ){ MLOOP (x, Q[e].v, M){ if ( OQ[*x].t==0 ) QUE_INS (*jump, *x); QUE_INS (OQ[*x], e); }
47
+ } else MLOOP (x, Q[e].v, M){ QUE_INS (OQ[*x], e); }
48
+ }
49
+ }
50
+ }
51
+
52
+ /* sort a QUEUE with WEIGHT, with already allocated memory */
53
+ void QUEUE_perm_WEIGHT (QUEUE *Q, WEIGHT *w, PERM *invperm, int flag){
54
+ WEIGHT y;
55
+ if ( w ){
56
+ qsort_perm__QUEUE_INT (Q->v, Q->t, invperm, flag);
57
+ ARY_INVPERMUTE_ (w, invperm, y, Q->t);
58
+ }
59
+ qsort_QUEUE_INT (Q->v, Q->t, flag);
60
+ }
61
+
62
+ /* remove (or unify) the consecutive same ID's in a QUEUE (duplication delete, if sorted) */
63
+ void QUEUE_rm_dup_WEIGHT (QUEUE *Q, WEIGHT *w){
64
+ VEC_ID j, jj=0;
65
+ if ( w ){
66
+ FLOOP (j, 1, Q->t){
67
+ if ( Q->v[j-1] != Q->v[j] ){
68
+ Q->v[++jj] = Q->v[j];
69
+ w[jj] = w[j];
70
+ } else w[jj] += w[j];
71
+ }
72
+ } else FLOOP (j, 1, Q->t){
73
+ if ( Q->v[j-1] != Q->v[j] ) Q->v[++jj] = Q->v[j];
74
+ }
75
+ if ( Q->t>0 ) Q->t = jj+1;
76
+ }
77
+
78
+ /***********************************************************************/
79
+ /* duplicate occ's in jump, ( copy occ's to allocated QUEUE array) */
80
+ /* Q[i].end := original item, clear each original occ */
81
+ /* buffer size is multiplied by u */
82
+ /*******************************************************/
83
+ void QUEUE_occ_dup (QUEUE *jump, QUEUE **QQ, QUEUE *Q, WEIGHT **ww, WEIGHT *w, WEIGHT **ppw, WEIGHT *pw, int u){
84
+ QUEUE_ID i, l=QUEUE_LENGTH_(*jump);
85
+ size_t cnt=0;
86
+ QUEUE_INT e, *x;
87
+ char *buf;
88
+ int unit = sizeof(*Q) + (w?sizeof(*w):0) + (pw?sizeof(*pw):0);
89
+
90
+ ENMAX (u, sizeof(*x));
91
+ MQUE_FLOOP (*jump, x) cnt += Q[*x].t;
92
+ if ( cnt == 0 ){ *QQ=NULL; return; }
93
+ malloc2 (buf, l*unit + (cnt+l)*u, EXIT);
94
+ *QQ = (QUEUE*)buf; buf += sizeof(*Q) *l;
95
+ if ( w ){ *ww = (WEIGHT *)buf; buf += sizeof(*w)*l; }
96
+ if ( pw ){ *ppw = (WEIGHT *)buf; buf += sizeof(*pw)*l; }
97
+ for (i=0 ; i<jump->t ; i++){
98
+ e = jump->v[i];
99
+ (*QQ)[i].end = e;
100
+ (*QQ)[i].v = (QUEUE_INT *)buf;
101
+ (*QQ)[i].t = Q[e].t;
102
+ memcpy (buf, Q[e].v, (Q[e].t+1)*u);
103
+ buf += (Q[e].t+1) *u;
104
+ if ( w ) (*ww)[i] = w[e];
105
+ if ( pw ) (*ppw)[i] = pw[e];
106
+ }
107
+ }
108
+
109
+
110
+ /* return the position of the first element having value e. return -1 if no such element exists */
111
+ LONG QUEUE_ele (QUEUE *Q, QUEUE_INT e){
112
+ QUEUE_INT *x;
113
+ MQUE_FLOOP (*Q, x)
114
+ if ( *x == e ) return (x - Q->v);
115
+ return (-1);
116
+ }
117
+
118
+ /* insert an element to the tail */
119
+ void QUEUE_ins_ (QUEUE *Q, QUEUE_INT e){
120
+ Q->v[Q->t] = e;
121
+ Q->t++;
122
+ }
123
+ void QUEUE_ins (QUEUE *Q, QUEUE_INT e){
124
+ Q->v[Q->t] = e;
125
+ QUEUE_INCREMENT (*Q, Q->t);
126
+ if (Q->s == Q->t ) error_num ("QUEUE_ins: overflow", Q->s, EXIT);
127
+ }
128
+
129
+ /* insert an element to the head */
130
+ void QUEUE_ins_head_ (QUEUE *Q, QUEUE_INT e){
131
+ Q->s--;
132
+ Q->v[Q->s] = e;
133
+ }
134
+ void QUEUE_ins_head (QUEUE *Q, QUEUE_INT e){
135
+ QUEUE_DECREMENT(*Q,Q->s);
136
+ Q->v[Q->s] = e;
137
+ if (Q->s == Q->t ) error_num ("QUEUE_ins_head: underflow", Q->s, EXIT);
138
+ }
139
+
140
+ /* extract an element from the head, without checking underflow */
141
+ QUEUE_INT QUEUE_ext_ (QUEUE *Q){
142
+ (Q->s)++;
143
+ return (Q->v[Q->s-1]);
144
+ }
145
+ QUEUE_INT QUEUE_ext (QUEUE *Q){
146
+ QUEUE_INT e;
147
+ if (Q->s == Q->t ) error_num ("QUEUE_ext: empty queue", Q->s, EXIT0);
148
+ e = Q->v[Q->s];
149
+ QUEUE_INCREMENT(*Q,Q->s);
150
+ return ( e);
151
+ }
152
+
153
+ /* extract an element from the tail, without checking underflow */
154
+ QUEUE_INT QUEUE_ext_tail_ (QUEUE *Q){
155
+ (Q->t)--;
156
+ return (Q->v[Q->t]);
157
+ }
158
+ QUEUE_INT QUEUE_ext_tail (QUEUE *Q){
159
+ if ( Q->s == Q->t ) error_num ("QUEUE_ext_tail: empty queue", Q->s, EXIT0);
160
+ QUEUE_DECREMENT(*Q,Q->t);
161
+ return (Q->v[Q->t]);
162
+ }
163
+
164
+ /* remove the j-th element and replace it by the tail */
165
+ void QUEUE_rm_ (QUEUE *Q, QUEUE_ID j){
166
+ Q->t--;
167
+ Q->v[j] = Q->v[Q->t];
168
+ }
169
+ void QUEUE_rm (QUEUE *Q, QUEUE_ID j){
170
+ if ( Q->s <= Q->t ){
171
+ if ( j < Q->s || j >= Q->t ) error ("QUEUE_rm: j is out of queue", EXIT);
172
+ } else if ( j < Q->s && j >= Q->t ) error ("QUEUE_rm: j is out of queue", EXIT);
173
+ QUEUE_DECREMENT(*Q,Q->t);
174
+ Q->v[j] = Q->v[Q->t];
175
+ }
176
+
177
+ /* remove the j-th element and replace it by the head */
178
+ void QUEUE_rm_head_ (QUEUE *Q, QUEUE_ID j){
179
+ Q->v[j] = Q->v[Q->s];
180
+ Q->s++;
181
+ }
182
+ void QUEUE_rm_head (QUEUE *Q, QUEUE_ID j){
183
+ if ( Q->s <= Q->t ){
184
+ if ( j < Q->s || j >= Q->t ) error ("QUEUE_rm: j is out of queue", EXIT);
185
+ } else if ( j < Q->s && j >= Q->t ) error ("QUEUE_rm: j is out of queue", EXIT);
186
+ Q->v[j] = Q->v[Q->s];
187
+ QUEUE_INCREMENT(*Q,Q->s);
188
+ }
189
+
190
+ /* remove the j-th element and shift the following elements to fill the gap */
191
+ int QUEUE_rm_ele_ (QUEUE *Q, QUEUE_INT e){
192
+ QUEUE_ID i;
193
+ QUEUE_F_LOOP (*Q, i){
194
+ if ( Q->v[i] == e ){
195
+ memcpy ( &(Q->v[i]), &(Q->v[i+1]), (Q->t-i-1)*sizeof(QUEUE_INT));
196
+ Q->t--;
197
+ return (1);
198
+ }
199
+ }
200
+ return (0);
201
+ }
202
+ /* insert e to the position determined by the increasing order of elements */
203
+ void QUEUE_ins_ele_ (QUEUE *Q, QUEUE_INT e){
204
+ QUEUE_ID i;
205
+ QUEUE_INT ee;
206
+ QUEUE_BE_LOOP_ (*Q, i, ee){
207
+ if ( ee<e ) break;
208
+ Q->v[i+1] = ee;
209
+ }
210
+ Q->v[i+1] = e;
211
+ Q->t++;
212
+ }
213
+
214
+ /* Append Q2 to the tail of Q1. Q2 will not be deleted */
215
+ void QUEUE_concat_ (QUEUE *Q1, QUEUE *Q2){
216
+ memcpy ( &(Q1->v[Q1->t]), &(Q2->v[Q2->s]), (Q2->t-Q2->s)*sizeof(QUEUE_INT));
217
+ Q1->t += Q2->t-Q2->s;
218
+ }
219
+ void QUEUE_concat (QUEUE *Q1, QUEUE *Q2){
220
+ QUEUE_ID e = Q2->s;
221
+ while ( e != Q2->t){
222
+ QUEUE_ins (Q1, Q2->v[e]);
223
+ QUEUE_INCREMENT(*Q2,e);
224
+ }
225
+ }
226
+ /* Append Q2 to the tail of Q1. Q2 will be deleted */
227
+ void QUEUE_append_ (QUEUE *Q1, QUEUE *Q2){
228
+ QUEUE_concat_ (Q1, Q2);
229
+ QUEUE_RMALL (*Q2);
230
+ }
231
+ void QUEUE_append (QUEUE *Q1, QUEUE *Q2){ // more improvement can be
232
+ while ( Q2->s != Q2->t )
233
+ QUEUE_ins (Q1, QUEUE_ext(Q2));
234
+ }
235
+
236
+ /* Append from j to jj th elements to the tail of Q1. Q2 will not be deleted */
237
+ void QUEUE_subconcat_ (QUEUE *Q1, QUEUE *Q2, QUEUE_ID j, QUEUE_ID jj){
238
+ for ( ; j<=jj ; j++){
239
+ Q1->v[Q1->t] = Q2->v[j];
240
+ Q1->t++;
241
+ }
242
+ }
243
+ void QUEUE_subconcat (QUEUE *Q1, QUEUE *Q2, QUEUE_ID j, QUEUE_ID jj){
244
+ while (1){
245
+ QUEUE_ins (Q1, Q2->v[j]);
246
+ if ( j == jj ) break;
247
+ QUEUE_INCREMENT(*Q2,j);
248
+ }
249
+ }
250
+
251
+ /* initialize Q1 by length of Q2, and copy Q2 to Q1 */
252
+ void QUEUE_store_ (QUEUE *Q1, QUEUE *Q2){
253
+ QUEUE_alloc (Q1, QUEUE_LENGTH(*Q2));
254
+ QUEUE_concat_ (Q1, Q2);
255
+ }
256
+ void QUEUE_store (QUEUE *Q1, QUEUE *Q2){
257
+ QUEUE_alloc (Q1, QUEUE_LENGTH(*Q2));
258
+ QUEUE_concat (Q1, Q2);
259
+ }
260
+ /* copy Q2 to Q1 and delete Q2 */
261
+ void QUEUE_restore_ (QUEUE *Q1, QUEUE *Q2){
262
+ QUEUE_RMALL (*Q1);
263
+ QUEUE_concat_ (Q1, Q2);
264
+ QUEUE_end (Q2);
265
+ }
266
+ void QUEUE_restore (QUEUE *Q1, QUEUE *Q2){
267
+ QUEUE_RMALL (*Q1);
268
+ QUEUE_concat (Q1, Q2);
269
+ QUEUE_end (Q2);
270
+ }
271
+
272
+ /* copy Q2 to Q1 */
273
+ void QUEUE_cpy_ (QUEUE *Q1, QUEUE *Q2){
274
+ Q1->s = Q1->t = 0;
275
+ QUEUE_concat_ (Q1, Q2);
276
+ }
277
+ void QUEUE_cpy (QUEUE *Q1, QUEUE *Q2){
278
+ QUEUE_RMALL (*Q1);
279
+ QUEUE_concat (Q1, Q2);
280
+ }
281
+
282
+ /* compare two queues */
283
+ int QUEUE_cmp_ (QUEUE *Q1, QUEUE *Q2){
284
+ QUEUE_INT *x, *y=Q2->v;
285
+ MQUE_FLOOP (*Q1, x){
286
+ if ( *x != *y ) return (0);
287
+ y++;
288
+ }
289
+ return (1);
290
+ }
291
+
292
+ /* copy l elements of Q2 starting from s2 to the s1th position of Q1.
293
+ size of Q1 is not increasing */
294
+ void QUEUE_subcpy_ (QUEUE *Q1, QUEUE_ID s1, QUEUE *Q2, QUEUE_ID s2, QUEUE_ID l){
295
+ memcpy ( &(Q1->v[s1]), &(Q2->v[s2]), (l-s2)*sizeof(QUEUE_INT));
296
+ }
297
+ void QUEUE_subcpy (QUEUE *Q1, QUEUE_ID s1, QUEUE *Q2, QUEUE_ID s2, QUEUE_ID l){
298
+ for ( ; s2!=l ; QUEUE_INCREMENT(*Q1,s1),QUEUE_INCREMENT(*Q2,s2) )
299
+ Q1->v[s1] = Q2->v[s2];
300
+ Q1->v[s1] = Q2->v[s2];
301
+ }
302
+
303
+ /* duplicate Q2 to Q1. The memory size will be the length of Q2 */
304
+ QUEUE QUEUE_dup_ (QUEUE *Q){
305
+ QUEUE QQ;
306
+ QUEUE_alloc (&QQ, MAX(Q->t+1, Q->end-1));
307
+ QUEUE_cpy_ (&QQ, Q);
308
+ return (QQ);
309
+ }
310
+
311
+ /* merge Q1 and Q2 by insert all elements of Q2 to Q1 with deleting duplications. Both Q1 and Q2 have to be sorted in increasing order */
312
+ void QUEUE_merge_ (QUEUE *Q1, QUEUE *Q2){
313
+ QUEUE_ID i=Q1->t-1, j=Q2->t-1, t=i+j-Q2->s+1;
314
+ QUEUE_INT ei, ej;
315
+ if ( i+1 == Q1->s || j+1 == Q2->s ){
316
+ QUEUE_concat_ (Q1, Q2);
317
+ return;
318
+ }
319
+ Q1->t = t+1;
320
+ ei = Q1->v[i];
321
+ ej = Q2->v[j];
322
+ while (1){
323
+ if ( ei > ej ){
324
+ Q1->v[t] = ei;
325
+ if ( i == Q1->s ){
326
+ QUEUE_subcpy_ (Q1, Q1->s, Q2, Q2->s, j);
327
+ return;
328
+ }
329
+ i--;
330
+ ei = Q1->v[i];
331
+ } else {
332
+ Q1->v[t] = ej;
333
+ if ( j == Q2->s ) return;
334
+ j--;
335
+ ej = Q2->v[j];
336
+ }
337
+ t--;
338
+ }
339
+ }
340
+ void QUEUE_merge (QUEUE *Q1, QUEUE *Q2){
341
+ QUEUE_ID i=Q1->t, j=Q2->t;
342
+ QUEUE_INT ei, ej;
343
+ QUEUE_ID t = (Q1->t + QUEUE_LENGTH(*Q2)-1) % Q1->end;
344
+ if ( QUEUE_LENGTH(*Q1) + QUEUE_LENGTH(*Q2) >= Q1->end ){
345
+ print_err ("QUEUE_merge: overflow Q1->end="QUEUE_INTF", Q1length="QUEUE_INTF", Q2length="QUEUE_INTF"\n", Q1->end, QUEUE_LENGTH(*Q1), QUEUE_LENGTH(*Q2));
346
+ exit (1);
347
+ }
348
+ if ( i == Q1->s || j == Q2->s ){
349
+ QUEUE_concat (Q1, Q2);
350
+ return;
351
+ }
352
+
353
+ Q1->t = t;
354
+ QUEUE_DECREMENT(*Q1,i);
355
+ QUEUE_DECREMENT(*Q2,j);
356
+ ei = Q1->v[i];
357
+ ej = Q2->v[j];
358
+ while (1){
359
+ if ( ei > ej ){
360
+ Q1->v[t] = ei;
361
+ if ( i == Q1->s ){
362
+ QUEUE_subcpy (Q1, Q1->s, Q2, Q2->s, (j+Q2->end-Q2->s)%Q2->end);
363
+ return;
364
+ }
365
+ QUEUE_DECREMENT(*Q1,i);
366
+ ei = Q1->v[i];
367
+ } else {
368
+ Q1->v[t] = ej;
369
+ if ( j == Q2->s ) return;
370
+ QUEUE_DECREMENT(*Q2,j);
371
+ ej = Q2->v[j];
372
+ }
373
+ QUEUE_DECREMENT(*Q1,t);
374
+ }
375
+ }
376
+
377
+ /* delete all elements of Q1 included in Q2.
378
+ both Q1 and Q2 have to be sorted in increasing order */
379
+ void QUEUE_minus_ (QUEUE *Q1, QUEUE *Q2){
380
+ QUEUE_ID i=Q1->s, i2 = Q2->s, ii=Q1->s;
381
+ while ( i != Q1->t && i2 != Q2->t){
382
+ if (Q1->v[i] > Q2->v[i2] ) i2++;
383
+ else {
384
+ if (Q1->v[i] < Q2->v[i2] ){
385
+ Q1->v[ii] = Q1->v[i];
386
+ ii++;
387
+ }
388
+ i++;
389
+ }
390
+ }
391
+ while ( i != Q1->t ){
392
+ Q1->v[ii] = Q1->v[i];
393
+ i++;
394
+ ii++;
395
+ }
396
+ Q1->t = ii;
397
+ }
398
+ void QUEUE_minus (QUEUE *Q1, QUEUE *Q2){
399
+ QUEUE_ID i=Q1->s, i2 = Q2->s, ii=Q1->s;
400
+ while ( i != Q1->t && i2 != Q2->t ){
401
+ if ( Q1->v[i] > Q2->v[i2] ) QUEUE_INCREMENT (*Q2, i2);
402
+ else {
403
+ if ( Q1->v[i] < Q2->v[i2] ){
404
+ Q1->v[ii] = Q1->v[i];
405
+ QUEUE_INCREMENT (*Q1, ii);
406
+ }
407
+ QUEUE_INCREMENT (*Q1, i);
408
+ }
409
+ }
410
+ while ( i != Q1->t ){
411
+ Q1->v[ii] = Q1->v[i];
412
+ QUEUE_INCREMENT (*Q1, i);
413
+ QUEUE_INCREMENT (*Q1, ii);
414
+ }
415
+ Q1->t = ii;
416
+ }
417
+
418
+ /* Delete all elements of Q1 which are not included in Q2.
419
+ both Q1 and Q2 have to be sorted in increasing order */
420
+ QUEUE_ID QUEUE_intsec_ (QUEUE *Q1, QUEUE *Q2){
421
+ QUEUE_ID i=Q1->s, i2 = Q2->s, c=0;
422
+ while ( i != Q1->t ){
423
+ if ( Q1->v[i] > Q2->v[i2] ){
424
+ if ( ++i2 == Q2->t ) break;
425
+ } else {
426
+ if ( Q1->v[i] == Q2->v[i2] ) c++;
427
+ i++;
428
+ }
429
+ }
430
+ return (c);
431
+ }
432
+ void QUEUE_and_ (QUEUE *Q1, QUEUE *Q2){
433
+ QUEUE_ID i=Q1->s, i2 = Q2->s, ii=Q1->s;
434
+ while ( i != Q1->t ){
435
+ if ( Q1->v[i] > Q2->v[i2] ){
436
+ if ( ++i2 == Q2->t ) break;
437
+ } else {
438
+ if ( Q1->v[i] == Q2->v[i2] ) Q1->v[ii++] = Q1->v[i];
439
+ i++;
440
+ }
441
+ }
442
+ Q1->t = ii;
443
+ }
444
+ void QUEUE_and (QUEUE *Q1, QUEUE *Q2){
445
+ QUEUE_ID i=Q1->s, i2 = Q2->s, ii=Q1->s;
446
+ while ( i != Q1->t && i2 != Q2->t){
447
+ if ( Q1->v[i] > Q2->v[i2] ) QUEUE_INCREMENT (*Q2, i2);
448
+ else {
449
+ if ( Q1->v[i] == Q2->v[i2] ){
450
+ Q1->v[ii] = Q1->v[i];
451
+ QUEUE_INCREMENT (*Q1, ii);
452
+ }
453
+ QUEUE_INCREMENT (*Q1, i);
454
+ }
455
+ }
456
+ Q1->t = ii;
457
+ }
458
+
459
+ /* insertion sort */
460
+ void QUEUE_sort (QUEUE *Q){
461
+ QUEUE_ID i = Q->s, j, jj;
462
+ QUEUE_INT e;
463
+ if ( i== Q->t ) return;
464
+ QUEUE_INCREMENT(*Q,i);
465
+ for ( ; i!=Q->t ; QUEUE_INCREMENT(*Q,i) ){
466
+ e=Q->v[i];
467
+ j=i;
468
+ while (1){
469
+ jj = j;
470
+ QUEUE_DECREMENT(*Q,j);
471
+ if ( Q->v[j] <= e ) { Q->v[jj] = e; break; }
472
+ Q->v[jj] = Q->v[j];
473
+ if ( j == Q->s) { Q->v[j] = e; break; }
474
+ }
475
+ }
476
+ }
477
+
478
+
479
+ /* print a queue */
480
+ void QUEUE_print (QUEUE *Q){
481
+ QUEUE_ID i;
482
+ for ( i=Q->s ; i!=Q->t ; ){
483
+ printf (QUEUE_INTF" ", Q->v[i]);
484
+ QUEUE_INCREMENT(*Q,i);
485
+ }
486
+ printf ("\n");
487
+ }
488
+ /* permutation version */
489
+ void QUEUE_perm_print (QUEUE *Q, QUEUE_ID *q){
490
+ QUEUE_ID i;
491
+ for ( i=Q->s ; i!=Q->t ; ){
492
+ printf (QUEUE_INTF" ", q[Q->v[i]]);
493
+ QUEUE_INCREMENT(*Q,i);
494
+ }
495
+ printf ("\n");
496
+ }
497
+ void QUEUE_printn (QUEUE *Q){
498
+ QUEUE_ID i;
499
+ for ( i=Q->s ; i!=Q->t ; ){
500
+ printf (QUEUE_INTF" ", Q->v[i]);
501
+ QUEUE_INCREMENT(*Q,i);
502
+ }
503
+ }
504
+ void QUEUE_perm_printn (QUEUE *Q, QUEUE_ID *q){
505
+ QUEUE_ID i;
506
+ for ( i=Q->s ; i!=Q->t ; ){
507
+ printf (QUEUE_INTF" ",q[Q->v[i]]);
508
+ QUEUE_INCREMENT(*Q,i);
509
+ }
510
+ }
511
+ void QUEUE_print_ (QUEUE *Q){
512
+ QUEUE_ID i;
513
+ printf("s="QUEUE_IDF",t="QUEUE_INTF": ", Q->s, Q->t);
514
+ for ( i=Q->s ; i!=Q->t ; ){
515
+ printf (QUEUE_INTF" ",Q->v[i]);
516
+ QUEUE_INCREMENT(*Q,i);
517
+ }
518
+ printf ("\n");
519
+ }
520
+
521
+ void QUEUE_print__ (QUEUE *Q){
522
+ QUEUE_ID i;
523
+ printf("s="QUEUE_IDF",t="QUEUE_IDF": ", Q->s, Q->t);
524
+ for ( i=Q->s ; i!=Q->t ; i++ ) printf (QUEUE_INTF" ",Q->v[i]);
525
+ printf ("\n");
526
+ }
527
+
528
+ #endif
@@ -0,0 +1,176 @@
1
+ /* Library of queue: spped priority implementation
2
+ 12/Apr/2001 by Takeaki Uno 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 _queue_h_
13
+ #define _queue_h_
14
+
15
+ #include"stdlib2.h"
16
+
17
+ #ifndef QUEUE_INT
18
+ #ifdef QUEUE_INT_LONG
19
+ #define QUEUE_INT LONG // define the type before if change is needed
20
+ #define QUEUE_INTHUGE LONGHUGE // comment out if QUEUE_INT is "short"
21
+ #define QUEUE_INTF LONGF
22
+ #else
23
+ #define QUEUE_INT int // define the type before if change is needed
24
+ #define QUEUE_INTHUGE INTHUGE // comment out if QUEUE_INT is "short"
25
+ #define QUEUE_INTF "%d"
26
+ #endif
27
+ #endif
28
+
29
+ #ifndef QUEUE_ID
30
+ #ifdef QUEUE_ID_LONG
31
+ #define QUEUE_ID LONG // define the type before if change is needed
32
+ #define QUEUE_IDHUGE LONGHUGE // comment out if QUEUE_INT is "short"
33
+ #define QUEUE_IDF LONGF
34
+ #else
35
+ #define QUEUE_ID int // define the type before if change is needed
36
+ #define QUEUE_IDHUGE INTHUGE // comment out if QUEUE_INT is "short"
37
+ #define QUEUE_IDF "%d"
38
+ #endif
39
+ #endif
40
+ #define SWAP_QUEUE_INT(a,b) (common_QUEUE_INT=a,a=b,b=common_QUEUE_INT)
41
+ #define SWAP_QUEUE_ID(a,b) (common_QUEUE_ID=a,a=b,b=common_QUEUE_ID)
42
+
43
+ typedef struct {
44
+ unsigned char type; // type of the structure
45
+ QUEUE_INT *v; // pointer to the array
46
+ QUEUE_ID end; // the length of the array
47
+ QUEUE_ID t; // end position+1
48
+ QUEUE_ID s; // start position
49
+ } QUEUE;
50
+
51
+ /* QUEUE stores at most end-1 elements. Overflow occurs after inserting end-1 elements */
52
+
53
+ #define QUEUE_INCREMENT(Q,i) ((i)=((i)>=(Q).end-1)?0:(i)+1)
54
+ #define QUEUE_DECREMENT(Q,i) ((i)=(i)==0?(Q).end-1:(i)-1)
55
+ #define QUEUE_LENGTH(Q) (((Q).t-(Q).s+(Q).end)%(Q).end)
56
+ #define QUEUE_LENGTH_(Q) ((Q).t-(Q).s)
57
+
58
+ /* macro for loop w.r.t., QUEUE */
59
+ #define QUEUE_F_LOOP(Q,i) for((i)=(Q).s;(i)!=(Q).t;((i)=((i)>=(Q).end-1)?0:(i)+1))
60
+ #define QUEUE_F_LOOP_(Q,i) for((i)=(Q).s;(i)<(Q).t;(i)++)
61
+ #define QUEUE_FE_LOOP(Q,i,x) for((i)=(Q).s,x=(Q).v[i];(i)!=(Q).t;((i)=((i)>=(Q).end-1)?0:(i)+1),x=(Q).v[i])
62
+ #define QUEUE_FE_LOOP_(Q,i,x) for((i)=(Q).s,x=(Q).v[i];(i)<(Q).t;(i)++,x=(Q).v[i])
63
+ #define QUEUE_B_LOOP(Q,i) for((i)=(Q).t==0?(Q).end-1:(Q).t-1;(i)!=(Q).s;(i)=(i)==0?(Q).end-1:(i)-1)
64
+ #define QUEUE_B_LOOP_(Q,i) for((i)=(Q).t-1;(i)>=(Q).s;(i)--)
65
+ #define QUEUE_BE_LOOP(Q,i,x) for((i)=(Q).t==0?(Q).end-1:(Q).t-1,x=(Q).v[i];(i)!=(Q).s;(i)=(i)==0?(Q).end-1:(i)-1,x=(Q).v[i])
66
+ #define QUEUE_BE_LOOP_(Q,i,x) for((i)=(Q).t-1;((i)>=(Q).s)?((x=(Q).v[i])||1):0;(i)--)
67
+
68
+ #define QUEUE_RMALL(Q) ((Q).t=(Q).s)
69
+ #define QUEUE_RMALL_(Q) ((Q).t=0)
70
+ #define QUEUE_HEAD(Q) ((Q).v[(Q).s])
71
+ #define QUEUE_TAIL_(Q) ((Q).v[(Q).t-1])
72
+
73
+ extern QUEUE INIT_QUEUE;
74
+ extern QUEUE_INT common_QUEUE_INT, *common_QUEUE_INTp;
75
+ QSORT_TYPE_HEADER(QUEUE_INT, QUEUE_INT)
76
+ QSORT_TYPE_HEADER(QUEUE_ID, QUEUE_ID)
77
+
78
+
79
+ /* initialization, not fill the memory by 0 */
80
+ void QUEUE_alloc (QUEUE *Q, QUEUE_ID siz);
81
+
82
+ /* termination processing */
83
+ void QUEUE_end (QUEUE *Q);
84
+
85
+ /* delivery: transpose that matrinx (transaction database) Q. Each row of the
86
+ transposed matrix is called occurrence.
87
+
88
+ variables to be set.
89
+ OQ:array for occurrences, c: for counting frequency, jump: list of items with non-empty OQ
90
+ if c!=NULL, count the frequency and set to c, and set occurrences to OQ, otherwise.
91
+ if jump==NULL, then the list of non-empty item will not be generated
92
+ Q:matrix, of an array of QUEUE, occ: list of rows of Q to be scaned, t; maximum ID of the
93
+ row to be scaned; if occ==NULL, occ will be ignored, otherwise t will be ignored.
94
+ M: end mark of each QUEUE. */
95
+ void QUEUE_delivery(QUEUE *OQ, VEC_ID *c, QUEUE *jump, QUEUE *Q, QUEUE *occ, VEC_ID t, QUEUE_INT M);
96
+ /* sort a QUEUE with WEIGHT, with already allocated memory (size have to no less than the size of QUEUE) */
97
+ void QUEUE_perm_WEIGHT (QUEUE *Q, WEIGHT *w, PERM *invperm, int flag);
98
+
99
+ /* remove (or unify) the consecutive same ID's in a QUEUE (duplication delete, if sorted) */
100
+ void QUEUE_rm_dup_WEIGHT (QUEUE *Q, WEIGHT *w);
101
+
102
+ /***********************************************************************/
103
+ /* duplicate occ's in jump, ( copy occ's to allocated QUEUE array) */
104
+ /* Q[i].end := original item, clear each original occ */
105
+ /* buffer size is multiplied by u */
106
+ /*******************************************************/
107
+
108
+
109
+ void QUEUE_occ_dup (QUEUE *jump, QUEUE **QQ, QUEUE *Q, WEIGHT **ww, WEIGHT *w, WEIGHT **ppw, WEIGHT *pw, int u);
110
+
111
+ /* return the position of the first element having value e. return -1 if no such element exists */
112
+ LONG QUEUE_ele (QUEUE *Q, QUEUE_INT e);
113
+
114
+ /* insert an element to the tail/head */
115
+ void QUEUE_ins_ (QUEUE *Q, QUEUE_INT e);
116
+ void QUEUE_ins (QUEUE *Q, QUEUE_INT e);
117
+ void QUEUE_ins_head_ (QUEUE *Q, QUEUE_INT e);
118
+ void QUEUE_ins_head (QUEUE *Q, QUEUE_INT e);
119
+
120
+ /* extract an element from the head/tail, without checking the underflow */
121
+ QUEUE_INT QUEUE_ext_ (QUEUE *Q);
122
+ QUEUE_INT QUEUE_ext (QUEUE *Q);
123
+ QUEUE_INT QUEUE_ext_tail_ (QUEUE *Q);
124
+ QUEUE_INT QUEUE_ext_tail (QUEUE *Q);
125
+
126
+ /* remove the j-th element and replace it by the tail/head or shift */
127
+ void QUEUE_rm_ (QUEUE *Q, QUEUE_ID j);
128
+ void QUEUE_rm (QUEUE *Q, QUEUE_ID j);
129
+ void QUEUE_rm_head_ (QUEUE *Q, QUEUE_ID j);
130
+ void QUEUE_rm_head (QUEUE *Q, QUEUE_ID j);
131
+ int QUEUE_rm_ele_ (QUEUE *Q, QUEUE_INT e);
132
+
133
+ /* Append Q2 to the tail of Q1. Q2 will (not) be deleted */
134
+ void QUEUE_append_ (QUEUE *Q1, QUEUE *Q2);
135
+ void QUEUE_append (QUEUE *Q1, QUEUE *Q2);
136
+ void QUEUE_concat_ (QUEUE *Q1, QUEUE *Q2);
137
+ void QUEUE_concat (QUEUE *Q1, QUEUE *Q2);
138
+
139
+ /* Append from j to jj th elements to the tail of Q1. Q2 will not be deleted */
140
+ void QUEUE_subconcat_ (QUEUE *Q1, QUEUE *Q2, QUEUE_ID j, QUEUE_ID jj);
141
+ void QUEUE_subconcat (QUEUE *Q1, QUEUE *Q2, QUEUE_ID j, QUEUE_ID jj);
142
+
143
+ /* initialize Q1 by length of Q2, and copy Q2 to Q1 */
144
+ void QUEUE_store_ (QUEUE *Q1, QUEUE *Q2);
145
+ void QUEUE_store (QUEUE *Q1, QUEUE *Q2);
146
+ /* copy Q2 to Q1 and delete Q2 */
147
+ void QUEUE_restore_ (QUEUE *Q1, QUEUE *Q2);
148
+ void QUEUE_restore (QUEUE *Q1, QUEUE *Q2);
149
+
150
+ /* copy Q2 to Q1 */
151
+ void QUEUE_cpy_ (QUEUE *Q1, QUEUE *Q2);
152
+ void QUEUE_cpy (QUEUE *Q1, QUEUE *Q2);
153
+ QUEUE QUEUE_dup_ (QUEUE *Q);
154
+ /* copy l elements of Q2 starting from s2 to the s1th position of Q1.
155
+ size of Q1 is not increasing */
156
+ void QUEUE_subcpy_ (QUEUE *Q1, QUEUE_ID s1, QUEUE *Q2, QUEUE_ID s2, QUEUE_ID l);
157
+ void QUEUE_subcpy (QUEUE *Q1, QUEUE_ID s1, QUEUE *Q2, QUEUE_ID s2, QUEUE_ID l);
158
+
159
+ /* merge/minum/intersection of Q1 and Q2, and set Q1 to it.
160
+ Both Q1 and Q2 have to be sorted in increasing order */
161
+ void QUEUE_merge_ (QUEUE *Q1, QUEUE *Q2);
162
+ void QUEUE_merge (QUEUE *Q1, QUEUE *Q2);
163
+ void QUEUE_minus_ (QUEUE *Q1, QUEUE *Q2);
164
+ void QUEUE_minus (QUEUE *Q1, QUEUE *Q2);
165
+ void QUEUE_and_ (QUEUE *Q1, QUEUE *Q2);
166
+ void QUEUE_and (QUEUE *Q1, QUEUE *Q2);
167
+
168
+ /* insertion sort */
169
+ void QUEUE_sort (QUEUE *Q);
170
+
171
+ /* print */
172
+ void QUEUE_print (QUEUE *Q);
173
+ void QUEUE_print_ (QUEUE *Q);
174
+
175
+
176
+ #endif