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,217 @@
1
+ /*
2
+ array-based simple heap (fixex size)
3
+ 12/Apr/2001 by Takeaki Uno e-mail:uno@nii.jp,
4
+ homepage: http://research.nii.ac.jp/~uno/index.html */
5
+ /* This program is available for only academic use, basically.
6
+ Anyone can modify this program, but he/she has to write down
7
+ the change of the modification on the top of the source code.
8
+ Neither contact nor appointment to Takeaki Uno is needed.
9
+ If one wants to re-distribute this code, do not forget to
10
+ refer the newest code, and show the link to homepage of
11
+ Takeaki Uno, to notify the news about the codes for the users.
12
+ For the commercial use, please make a contact to Takeaki Uno. */
13
+
14
+ #ifndef _aheap_c_
15
+ #define _aheap_c_
16
+
17
+ #include"aheap.h"
18
+
19
+ QSORT_TYPE (AHEAP_KEY, AHEAP_KEY)
20
+ QSORT_TYPE (AHEAP_ID, AHEAP_ID)
21
+ AHEAP INIT_AHEAP = {TYPE_AHEAP,NULL,0,0};
22
+
23
+ /* allocate memory */
24
+ void AHEAP_alloc (AHEAP *H, AHEAP_ID num){
25
+ AHEAP_ID i;
26
+ #ifdef ERROR_CHECK
27
+ if ( num<0 ) error_num ("size is out of range", num, EXIT);
28
+ #endif
29
+ *H = INIT_AHEAP;
30
+ if ( num>0 ) malloc2 (H->v, num*2, EXIT);
31
+ H->end = num;
32
+ ARY_FILL (H->v, 0, num*2, AHEAP_KEYHUGE);
33
+ for (i=0 ; i<num-1 ; i=i*2+1);
34
+ H->base = i - num + 1;
35
+ }
36
+
37
+ /* termination */
38
+ void AHEAP_end (AHEAP *H){
39
+ free2 (H->v);
40
+ *H = INIT_AHEAP;
41
+ }
42
+
43
+ /* return the index of the leaf having the minimum key among the descendants
44
+ of the given node i. If several leaves with the smallest key are there,
45
+ return the minimum index among them if f=0, maximum index if f=1, and
46
+ random choice if f=2 */
47
+ /* random choice version. choose one child to go down randomly for each node,
48
+ thus it is not uniformly random */
49
+ /* node_ returns the ID of leaf */
50
+ AHEAP_ID AHEAP_findmin_node_ (AHEAP *H, AHEAP_ID i, int f){
51
+ while ( i < H->end-1 ){
52
+ if ( H->v[i*2+1] == H->v[i] )
53
+ if ( H->v[i*2+2] == H->v[i] )
54
+ if ( f == 2 ) i = i*2 + 1 + rand()%2;
55
+ else i = i*2+1+f;
56
+ else i = i*2+1;
57
+ else i = i*2+2;
58
+ }
59
+ return (i);
60
+ }
61
+ AHEAP_ID AHEAP_findmin_node (AHEAP *H, AHEAP_ID i, int f){
62
+ if ( H->end <= 0 ) return (-1);
63
+ return (AHEAP_IDX(*H, AHEAP_findmin_node_ (H, i, f)));
64
+ }
65
+ AHEAP_ID AHEAP_findmin_head (AHEAP *H){ return (AHEAP_findmin_node (H, 0, 0) ); }
66
+ AHEAP_ID AHEAP_findmin_tail (AHEAP *H){ return (AHEAP_findmin_node (H, 0, 1) ); }
67
+ AHEAP_ID AHEAP_findmin_rnd (AHEAP *H){ return (AHEAP_findmin_node (H, 0, 2) ); }
68
+
69
+ /* return the index of the leaf having smaller value than a among the
70
+ descendants of the given node i. If several leaves with the smallest key
71
+ are there, return the minimum index among them if f=0, maximum index if f=1,
72
+ and random choice if f=2 */
73
+ AHEAP_ID AHEAP_findlow_node (AHEAP *H, AHEAP_KEY a, AHEAP_ID i, int f){
74
+ if ( H->end == 0 ) return (-1);
75
+ if ( H->v[0] > a ) return (-1);
76
+ while ( i < H->end-1 ){
77
+ if ( f == 2 ) {
78
+ if ( H->v[i*2+1] <= a )
79
+ if ( H->v[i*2+2] <= a ) i = i*2 + 1 + rand()%2;
80
+ else i = i*2+1;
81
+ else i = i*2+2;
82
+ } else if ( H->v[i*2+1] <= a ) i = i*2+1+f; else i = i*2+2-f;
83
+ }
84
+ return (AHEAP_IDX(*H, i) );
85
+ }
86
+ AHEAP_ID AHEAP_findlow_head (AHEAP *H, AHEAP_KEY a){ return (AHEAP_findlow_node (H, a, 0, 0) ); }
87
+ AHEAP_ID AHEAP_findlow_tail (AHEAP *H, AHEAP_KEY a){ return (AHEAP_findlow_node (H, a, 0, 1) ); }
88
+ AHEAP_ID AHEAP_findlow_rnd (AHEAP *H, AHEAP_KEY a){ return (AHEAP_findlow_node (H, a, 0, 2) ); }
89
+
90
+ /* return the index of the leaf having smaller value than a next/previous to
91
+ leaf i. return -1 if such a leaf does not exist */
92
+ AHEAP_ID AHEAP_findlow_nxt (AHEAP *H, AHEAP_ID i, AHEAP_KEY a){
93
+ if ( H->end == 0 ) return (-1);
94
+ if ( i<0 || i>= H->end ) return ( AHEAP_findlow_head (H, a));
95
+ for (i=AHEAP_LEAF(*H,i); i>0 ; i=(i-1)/2){
96
+ /* i is the child of smaller index, and the key of the sibling of i is less than a */
97
+ if ( i%2 == 1 && H->v[i+1] <= a ) return (AHEAP_findlow_node (H, a, i+1, 0) );
98
+ }
99
+ return (-1);
100
+ }
101
+ AHEAP_ID AHEAP_findlow_prv (AHEAP *H, AHEAP_ID i, AHEAP_KEY a){
102
+ if ( H->end == 0 ) return (-1);
103
+ if ( i<0 || i>= H->end ) return ( AHEAP_findlow_head (H, a));
104
+ for (i=AHEAP_LEAF(*H,i); i>0 ; i=(i-1)/2){
105
+ /* i is the child of larger index, and the key of the sibling of i is less than a */
106
+ if ( i%2 == 0 && H->v[i-1] <= a ) return (AHEAP_findlow_node (H, a, i-1, 1) );
107
+ }
108
+ return (-1);
109
+ }
110
+
111
+ /* change the key of node i to a /Add a to the key of node i, and update heap H */
112
+ void AHEAP_chg (AHEAP *H, AHEAP_ID i, AHEAP_KEY a){
113
+ i = AHEAP_LEAF (*H, i);
114
+ H->v[i] = a;
115
+ AHEAP_update (H, i);
116
+ }
117
+ void AHEAP_add (AHEAP *H, AHEAP_ID i, AHEAP_KEY a){
118
+ i = AHEAP_LEAF (*H, i);
119
+ H->v[i] += a;
120
+ AHEAP_update (H, i);
121
+ }
122
+
123
+ /* update the ancestor of node i */
124
+ void AHEAP_update (AHEAP *H, AHEAP_ID i){
125
+ AHEAP_ID j;
126
+ AHEAP_KEY a = H->v[i];
127
+ while ( i>0 ){
128
+ j = i - 1 + (i%2)*2; /* j = the sibling of i */
129
+ i = (i-1) / 2;
130
+ if ( H->v[j] < a ) a = H->v[j];
131
+ if ( a == H->v[i] ) break;
132
+ H->v[i] = a;
133
+ }
134
+ }
135
+
136
+ /* find the leaf with the minimum key value among the leaves having index
137
+ smaller/larger than i, or between i and j */
138
+ AHEAP_ID AHEAP_upper_min (AHEAP *H, AHEAP_ID i){
139
+ AHEAP_ID fi=0, j = AHEAP_LEAF (*H, H->end - 1);
140
+ AHEAP_KEY fm = AHEAP_KEYHUGE;
141
+ if ( i == 0 ) return (AHEAP_findmin_head (H) );
142
+ i = AHEAP_LEAF (*H, i-1);
143
+ while ( i != j ){
144
+ if ( i%2 ){ /* if i is the child with smaller index */
145
+ if ( fm > H->v[i+1] ){
146
+ fm = H->v[i+1];
147
+ fi = i+1;
148
+ }
149
+ }
150
+ i = (i-1)/2;
151
+ if ( j == i ) break; /* stop if the right pointer and the left pointer are the same */
152
+ j = (j-1)/2;
153
+ }
154
+ while ( fi < H->end-1 ) fi = fi*2 + (H->v[fi*2+1]<=fm?1:2);
155
+ return ( AHEAP_IDX(*H, fi) );
156
+ }
157
+ AHEAP_ID AHEAP_lower_min (AHEAP *H, AHEAP_ID i){
158
+ AHEAP_ID fi=0, j = AHEAP_LEAF (*H, 0);
159
+ AHEAP_KEY fm = AHEAP_KEYHUGE;
160
+ if ( i == H->end-1 ) return (AHEAP_findmin_head (H) );
161
+ i = AHEAP_LEAF (*H, i+1);
162
+ while ( i != j ){
163
+ if ( i%2 == 0 ){ /* if i is the child of larger index */
164
+ if ( fm > H->v[i-1] ){
165
+ fm = H->v[i-1];
166
+ fi = i-1;
167
+ }
168
+ }
169
+ j = (j-1)/2;
170
+ if ( j == i ) break; /* stop if the right pointer and the left pointer are the same */
171
+ i = (i-1)/2;
172
+ }
173
+ while ( fi < H->end-1 ) fi = fi*2 + (H->v[fi*2+1]<=fm?1:2);
174
+ return (AHEAP_IDX(*H, fi) );
175
+ }
176
+
177
+ /* find the index having the minimum among given two indices */
178
+ AHEAP_ID AHEAP_interval_min (AHEAP *H, AHEAP_ID i, AHEAP_ID j){
179
+ AHEAP_ID fi=0;
180
+ AHEAP_KEY fm = AHEAP_KEYHUGE;
181
+ if ( i == 0 ) return (AHEAP_lower_min (H, j) );
182
+ if ( j == H->end-1 ) return (AHEAP_upper_min (H, i) );
183
+ i = AHEAP_LEAF (*H, i-1);
184
+ j = AHEAP_LEAF (*H, j+1);
185
+ while ( i != j && i != j-1 ){
186
+ if ( i%2 ){ /* if i is the child of smaller index */
187
+ if ( fm > H->v[i+1] ){
188
+ fm = H->v[i+1];
189
+ fi = i+1;
190
+ }
191
+ }
192
+ i = (i-1)/2;
193
+ if ( j == i || j == i+1 ) break; /* stop if the right pointer and the left pointer are the same */
194
+ if ( j%2 == 0 ){ /* if j is the child of larger index */
195
+ if ( fm > H->v[j-1] ){
196
+ fm = H->v[j-1];
197
+ fi = j-1;
198
+ }
199
+ }
200
+ j = (j-1)/2;
201
+ }
202
+ while ( fi < H->end-1 )
203
+ fi = fi*2 + (H->v[fi*2+1] <= fm?1:2);
204
+ return (AHEAP_IDX(*H, fi) );
205
+ }
206
+
207
+ /* print heap keys according to the structure of the heap */
208
+ void AHEAP_print (AHEAP *H){
209
+ AHEAP_ID i, j=1;
210
+ while ( j<=H->end*2-1 ){
211
+ FLOOP (i, j-1, MIN(j, H->end)*2-1) printf (AHEAP_KEYF ",", H->v[i] );
212
+ printf ("\n");
213
+ j = j*2;
214
+ }
215
+ }
216
+
217
+ #endif
@@ -0,0 +1,112 @@
1
+ /*
2
+ array-based simple heap (fixed size)
3
+ 12/Apr/2001 by Takeaki Uno e-mail:uno@nii.jp,
4
+ homepage: http://research.nii.ac.jp/~uno/index.html */
5
+ /* This program is available for only academic use, basically.
6
+ Anyone can modify this program, but he/she has to write down
7
+ the change of the modification on the top of the source code.
8
+ Neither contact nor appointment to Takeaki Uno is needed.
9
+ If one wants to re-distribute this code, do not forget to
10
+ refer the newest code, and show the link to homepage of
11
+ Takeaki Uno, to notify the news about the codes for the users.
12
+ For the commercial use, please make a contact to Takeaki Uno. */
13
+
14
+ /* bench mark
15
+ PentiumIII 500MHz, Memory 256MB Linux
16
+ values 0-1,000,000 : set & del & get 1,000,000 times
17
+ 2.55sec
18
+
19
+ # rotation == 1/5 per 1 set/del
20
+
21
+ *** simple array ***
22
+ value 0-1,000,000 set & set & set 1,000,000 times,
23
+ 0.88sec
24
+ */
25
+
26
+ #ifndef _aheap_h_
27
+ #define _aheap_h_
28
+
29
+ #include"stdlib2.h"
30
+
31
+ #ifndef AHEAP_KEY
32
+ #ifdef AHEAP_KEY_DOUBLE
33
+ #define AHEAP_KEY double
34
+ #define AHEAP_KEYHUGE DOUBLEHUGE
35
+ #define AHEAP_KEYF "%f"
36
+ #elif defined(AHEAP_KEY_WEIGHT)
37
+ #define AHEAP_KEY WEIGHT
38
+ #define AHEAP_KEYHUGE WEIGHTHUGE
39
+ #define AHEAP_KEYF WEIGHTF
40
+ #else
41
+ #define AHEAP_KEY int
42
+ #define AHEAP_KEYHUGE INTHUGE
43
+ #define AHEAP_KEYF "%d"
44
+ #endif
45
+ #endif
46
+
47
+ #ifndef AHEAP_ID
48
+ #define AHEAP_ID int
49
+ #define AHEAP_ID_END INTHUGE
50
+ #define AHEAP_IDF "%d"
51
+ #endif
52
+
53
+ #define AHEAP_IDX(H,i) (((i)+1-(H).base)%(H).end)
54
+ #define AHEAP_LEAF(H,i) (((i)+(H).base)%(H).end+(H).end-1)
55
+ #define AHEAP_H(H,i) (H).v[(((i)+(H).base)%(H).end+(H).end-1)]
56
+
57
+ typedef struct {
58
+ unsigned char type;
59
+ AHEAP_KEY *v; /* array for heap key */
60
+ int end; /* the number of maximum elements */
61
+ int base; /* the constant for set 0 to the leftmost leaf */
62
+ } AHEAP;
63
+
64
+ QSORT_TYPE_HEADER (AHEAP_KEY, AHEAP_KEY)
65
+ QSORT_TYPE_HEADER (AHEAP_ID, AHEAP_ID)
66
+ extern AHEAP INIT_AHEAP;
67
+
68
+ /* initialization. allocate memory for H and fill it by +infinity */
69
+ void AHEAP_alloc (AHEAP *H, int num);
70
+ void AHEAP_end (AHEAP *H);
71
+
72
+ /* return the index of the leaf having the minimum key among the descendants
73
+ of the given node i. If several leaves with the smallest key are there,
74
+ return the minimum index among them if f=0, maximum index if f=1, and
75
+ random choice if f=2 */
76
+ AHEAP_ID AHEAP_findmin_node_ (AHEAP *H, AHEAP_ID i, int f);
77
+ AHEAP_ID AHEAP_findmin_node (AHEAP *H, AHEAP_ID i, int f);
78
+ AHEAP_ID AHEAP_findmin_head (AHEAP *H);
79
+ AHEAP_ID AHEAP_findmin_tail (AHEAP *H);
80
+ AHEAP_ID AHEAP_findmin_rnd (AHEAP *H);
81
+
82
+ /* return the index of the leaf having smaller value than a among the
83
+ descendants of the given node i. If several leaves with the smallest key
84
+ are there, return the minimum index among them if f=0, maximum index if f=1,
85
+ and random choice if f=2 */
86
+ AHEAP_ID AHEAP_findlow_node (AHEAP *H, AHEAP_KEY a, AHEAP_ID i, int f);
87
+ AHEAP_ID AHEAP_findlow_head (AHEAP *H, AHEAP_KEY a);
88
+ AHEAP_ID AHEAP_findlow_tail (AHEAP *H, AHEAP_KEY a);
89
+ AHEAP_ID AHEAP_findlow_rnd (AHEAP *H, AHEAP_KEY a);
90
+
91
+ /* return the index of the leaf having smaller value than a next/previous to
92
+ leaf i. return -1 if such a leaf does not exist */
93
+ AHEAP_ID AHEAP_findlow_nxt (AHEAP *H, AHEAP_ID i, AHEAP_KEY a);
94
+ AHEAP_ID AHEAP_findlow_prv (AHEAP *H, AHEAP_ID i, AHEAP_KEY a);
95
+
96
+ /* change the key of node i to a /Add a to the key of node i, and update heap H */
97
+ void AHEAP_chg (AHEAP *H, AHEAP_ID i, AHEAP_KEY a);
98
+ void AHEAP_add (AHEAP *H, AHEAP_ID i, AHEAP_KEY a);
99
+
100
+ /* update the ancestor of node i */
101
+ void AHEAP_update (AHEAP *H, AHEAP_ID i);
102
+
103
+ /* find the leaf with the minimum key value among the leaves having index
104
+ smaller/larger than i, or between i and j */
105
+ AHEAP_ID AHEAP_upper_min (AHEAP *H, AHEAP_ID i);
106
+ AHEAP_ID AHEAP_lower_min (AHEAP *H, AHEAP_ID i);
107
+ AHEAP_ID AHEAP_interval_min (AHEAP *H, AHEAP_ID i, AHEAP_ID j);
108
+
109
+ /* print heap keys according to the structure of the heap */
110
+ void AHEAP_print (AHEAP *H);
111
+
112
+ #endif