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,251 @@
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, please
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
+
13
+ /* bench mark
14
+ PentiumIII 500MHz, Memory 256MB Linux
15
+ values 0-1,000,000 : set & del & get 1,000,000 times
16
+ 2.55sec
17
+
18
+ # rotation == 1/5 per 1 set/del
19
+
20
+ *** simple array ***
21
+ value 0-1,000,000 set & set & set 1,000,000 times,
22
+ 0.88sec
23
+ */
24
+
25
+ #ifndef _aheap_h_
26
+ #define _aheap_h_
27
+
28
+ #include"stdlib2.h"
29
+
30
+ #ifndef AHEAP_KEY
31
+ #ifdef AHEAP_KEY_DOUBLE
32
+ #define AHEAP_KEY double
33
+ #define AHEAP_KEYHUGE DOUBLEHUGE
34
+ #define AHEAP_KEYF "%f"
35
+ #elif defined(AHEAP_KEY_WEIGHT)
36
+ #define AHEAP_KEY WEIGHT
37
+ #define AHEAP_KEYHUGE WEIGHTHUGE
38
+ #define AHEAP_KEYF WEIGHTF
39
+ #else
40
+ #define AHEAP_KEY int
41
+ #define AHEAP_KEYHUGE INTHUGE
42
+ #define AHEAP_KEYF "%d"
43
+ #endif
44
+ #endif
45
+
46
+ #ifndef AHEAP_ID
47
+ #define AHEAP_ID int
48
+ #define AHEAP_ID_HUGE INTHUGE
49
+ #define AHEAP_IDF "%d"
50
+ #endif
51
+
52
+ #define AHEAP_IDX(H,i) (((i)+1-(H).base)%(H).end)
53
+ #define AHEAP_LEAF(H,i) (((i)+(H).base)%(H).end+(H).end-1)
54
+ #define AHEAP_H(H,i) (H).v[(((i)+(H).base)%(H).end+(H).end-1)]
55
+
56
+ typedef struct {
57
+ unsigned char type;
58
+ AHEAP_KEY *v; /* array for heap key */
59
+ AHEAP_ID end; /* the number of maximum elements */
60
+ AHEAP_ID base; /* the constant for set 0 to the leftmost leaf */
61
+ } AHEAP;
62
+
63
+ QSORT_TYPE_HEADER (AHEAP_KEY, AHEAP_KEY)
64
+ QSORT_TYPE_HEADER (AHEAP_ID, AHEAP_ID)
65
+ extern AHEAP INIT_AHEAP;
66
+
67
+ /* initialization. allocate memory for H and fill it by +infinity */
68
+ void AHEAP_alloc (AHEAP *H, int num);
69
+ void AHEAP_end (AHEAP *H);
70
+
71
+ /* return the index of the leaf having the minimum key among the descendants
72
+ of the given node i. If several leaves with the smallest key are there,
73
+ return the minimum index among them if f=0, maximum index if f=1, and
74
+ random choice if f=2 */
75
+ AHEAP_ID AHEAP_findmin_node_ (AHEAP *H, AHEAP_ID i, int f);
76
+ AHEAP_ID AHEAP_findmin_node (AHEAP *H, AHEAP_ID i, int f);
77
+ AHEAP_ID AHEAP_findmin_head (AHEAP *H);
78
+ AHEAP_ID AHEAP_findmin_tail (AHEAP *H);
79
+ AHEAP_ID AHEAP_findmin_rnd (AHEAP *H);
80
+
81
+ /* return the index of the leaf having smaller value than a among the
82
+ descendants of the given node i. If several leaves with the smallest key
83
+ are there, return the minimum index among them if f=0, maximum index if f=1,
84
+ and random choice if f=2 */
85
+ AHEAP_ID AHEAP_findlow_node (AHEAP *H, AHEAP_KEY a, AHEAP_ID i, int f);
86
+ AHEAP_ID AHEAP_findlow_head (AHEAP *H, AHEAP_KEY a);
87
+ AHEAP_ID AHEAP_findlow_tail (AHEAP *H, AHEAP_KEY a);
88
+ AHEAP_ID AHEAP_findlow_rnd (AHEAP *H, AHEAP_KEY a);
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
+ AHEAP_ID AHEAP_findlow_prv (AHEAP *H, AHEAP_ID i, AHEAP_KEY a);
94
+
95
+ /* change the key of node i to a /Add a to the key of node i, and update heap H */
96
+ void AHEAP_chg (AHEAP *H, AHEAP_ID i, AHEAP_KEY a);
97
+ void AHEAP_add (AHEAP *H, AHEAP_ID i, AHEAP_KEY a);
98
+
99
+ /* update the ancestor of node i */
100
+ void AHEAP_update (AHEAP *H, AHEAP_ID i);
101
+
102
+ /* find the leaf with the minimum key value among the leaves having index
103
+ smaller/larger than i, or between i and j */
104
+ AHEAP_ID AHEAP_upper_min (AHEAP *H, AHEAP_ID i);
105
+ AHEAP_ID AHEAP_lower_min (AHEAP *H, AHEAP_ID i);
106
+ AHEAP_ID AHEAP_interval_min (AHEAP *H, AHEAP_ID i, AHEAP_ID j);
107
+
108
+ /* print heap keys according to the structure of the heap */
109
+ void AHEAP_print (AHEAP *H);
110
+
111
+
112
+ /******************************************************************************/
113
+ /* VHEAP: variable size heap */
114
+ /******************************************************************************/
115
+
116
+
117
+ #ifndef VHEAP_KEY
118
+ #ifdef VHEAP_KEY_DOUBLE
119
+ #define VHEAP_KEY double
120
+ #define VHEAP_KEYHUGE DOUBLEHUGE
121
+ #define VHEAP_KEYF "%f"
122
+ #elif defined(VHEAP_KEY_WEIGHT)
123
+ #define VHEAP_KEY WEIGHT
124
+ #define VHEAP_KEYHUGE WEIGHTHUGE
125
+ #define VHEAP_KEYF WEIGHTF
126
+ #else
127
+ #define VHEAP_KEY int
128
+ #define VHEAP_KEYHUGE INTHUGE
129
+ #define VHEAP_KEYF "%d"
130
+ #endif
131
+ #endif
132
+
133
+ #ifndef VHEAP_ID
134
+ #define VHEAP_ID int
135
+ #define VHEAP_ID_HUGE INTHUGE
136
+ #define VHEAP_IDF "%d"
137
+ #endif
138
+
139
+ typedef struct {
140
+ unsigned char type;
141
+ char *v; // array for heap key
142
+ VHEAP_ID siz, end; // the current size, and the maximum size
143
+ int unit; // size of a cell (element) the first has to be VHEAP_KEY
144
+ // int *f();
145
+ } VHEAP;
146
+
147
+ // structure for elements of VHEAP
148
+ typedef struct {
149
+ VHEAP_KEY *w; // weight
150
+ VHEAP_ID i; // ID
151
+ } VHEAP_ELE;
152
+
153
+ QSORT_TYPE_HEADER (VHEAP_KEY, VHEAP_KEY)
154
+ QSORT_TYPE_HEADER (VHEAP_ID, VHEAP_ID)
155
+ extern VHEAP INIT_VHEAP;
156
+
157
+ #define VHEAP_I(H,i) (*((VHEAP_ID *)(((VHEAP_KEY *)(&(H).v[(H).unit*i]))+1)))
158
+ #define VHEAP_V(H,i) (*((VHEAP_KEY *)(&(H).v[(H).unit*i])))
159
+
160
+
161
+ /* initialization. allocate memory for H and fill it by +infinity */
162
+ void VHEAP_print (FILE *fp, VHEAP *H);
163
+ void VHEAP_print_ele (FILE *fp, VHEAP *H);
164
+ void VHEAP_alloc (VHEAP *H, int num, int unit);
165
+ void VHEAP_end (VHEAP *H);
166
+
167
+ /* change the value of i-th node to w, return the position to which the cell moved */
168
+ VHEAP_ID VHEAP_dec_ (VHEAP *H, VHEAP_ID i, VHEAP_KEY w);
169
+ VHEAP_ID VHEAP_inc_ (VHEAP *H, VHEAP_ID i, VHEAP_KEY w);
170
+ VHEAP_ID VHEAP_chg_ (VHEAP *H, VHEAP_ID i, VHEAP_KEY w);
171
+ VHEAP_ID VHEAP_dec (VHEAP *H, VHEAP_ID i, VHEAP_KEY w, size_t ii, VHEAP_KEY **hh);
172
+ VHEAP_ID VHEAP_inc (VHEAP *H, VHEAP_ID i, VHEAP_KEY w, size_t ii, VHEAP_KEY **hh);
173
+ VHEAP_ID VHEAP_chg (VHEAP *H, VHEAP_ID i, VHEAP_KEY w);
174
+
175
+ /* insert/delete an element */
176
+ void VHEAP_ins_ (VHEAP *H, VHEAP_KEY w);
177
+ VHEAP_ID VHEAP_ins (VHEAP *H, VHEAP_KEY w); // return the final position of inserted cell
178
+ void VHEAP_ins_ele (VHEAP *H, VHEAP_KEY w, VHEAP_ID v);
179
+ void VHEAP_rm_ (VHEAP *H, VHEAP_ID i);
180
+ void VHEAP_rm (VHEAP *H, VHEAP_ID i);
181
+
182
+ /* extract the minimum element from H */
183
+ VHEAP_KEY VHEAP_ext_min_ (VHEAP *H);
184
+ VHEAP_KEY VHEAP_ext_min (VHEAP *H);
185
+ VHEAP_KEY VHEAP_ext_min_ele (VHEAP *H, VHEAP_ID *i);
186
+
187
+
188
+ /******************************************************************************/
189
+ /* IHEAP: variable size, index heap */
190
+ /******************************************************************************/
191
+
192
+
193
+ #ifndef IHEAP_KEY
194
+ #ifdef IHEAP_KEY_DOUBLE
195
+ #define IHEAP_KEY double
196
+ #define IHEAP_KEYHUGE DOUBLEHUGE
197
+ #define IHEAP_KEYF "%f"
198
+ #elif defined(IHEAP_KEY_WEIGHT)
199
+ #define IHEAP_KEY WEIGHT
200
+ #define IHEAP_KEYHUGE WEIGHTHUGE
201
+ #define IHEAP_KEYF WEIGHTF
202
+ #else
203
+ #define IHEAP_KEY int
204
+ #define IHEAP_KEYHUGE INTHUGE
205
+ #define IHEAP_KEYF "%d"
206
+ #endif
207
+ #endif
208
+
209
+ #ifndef IHEAP_ID
210
+ #define IHEAP_ID int
211
+ #define IHEAP_ID_HUGE INTHUGE
212
+ #define IHEAP_IDF "%d"
213
+ #endif
214
+
215
+
216
+ typedef struct {
217
+ unsigned char type;
218
+ IHEAP_ID *v; // array for heap ID's
219
+ IHEAP_ID siz, end; // the current size, and the maximum size
220
+ IHEAP_KEY *x; // array for the values (IHEAP does not prepare this)
221
+ int mode; // mode; minheap = 1, maxhead = 2;
222
+ int *f; // function for comparing the values; under construction
223
+ int unit; // size of a value-cell in H->x
224
+ } IHEAP;
225
+
226
+ QSORT_TYPE_HEADER (IHEAP_KEY, IHEAP_KEY)
227
+ QSORT_TYPE_HEADER (IHEAP_ID, IHEAP_ID)
228
+ extern IHEAP INIT_IHEAP;
229
+
230
+ #define IHEAP_P(H,i) (H->f? (IHEAP_KEY *)(&((char *)H->x)[H->v[i]*H->unit]): &H->x[H->v[i]])
231
+
232
+
233
+ /* initialization. allocate memory for H and fill it by +infinity */
234
+ void IHEAP_print (FILE *fp, IHEAP *H);
235
+ void IHEAP_print_ele (FILE *fp, IHEAP *H);
236
+ void IHEAP_alloc (IHEAP *H, int num, int mode, IHEAP_KEY *x);
237
+ void IHEAP_end (IHEAP *H);
238
+
239
+ /* change the value of i-th node to w, return the position to which the cell moved */
240
+ IHEAP_ID IHEAP_dec (IHEAP *H, IHEAP_ID i, IHEAP_ID j);
241
+ IHEAP_ID IHEAP_inc (IHEAP *H, IHEAP_ID i, IHEAP_ID j);
242
+ IHEAP_ID IHEAP_chg (IHEAP *H, IHEAP_ID i, IHEAP_ID j);
243
+
244
+ /* insert/delete an element */
245
+ IHEAP_ID IHEAP_ins (IHEAP *H, IHEAP_ID j);
246
+ void IHEAP_rm (IHEAP *H, IHEAP_ID i);
247
+
248
+ /* extract the minimum element from H */
249
+ IHEAP_ID IHEAP_ext_min (IHEAP *H);
250
+
251
+ #endif
@@ -0,0 +1,92 @@
1
+ /*
2
+ blocked memory allocation library
3
+ 12/Mar/2002 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, please
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
+
13
+ #ifndef _base_c_
14
+ #define _base_c_
15
+
16
+ #include"base.h"
17
+
18
+ BASE INIT_BASE = {TYPE_BASE,NULL,0,0,0,0,-1,NULL};
19
+
20
+ /* initialization, and allocate memory for header */
21
+ void BASE_alloc (BASE *B, int unit, int block_siz){
22
+ *B = INIT_BASE;
23
+ B->dellist = B;
24
+ B->unit = unit;
25
+ B->block_siz = block_siz;
26
+ B->num = block_siz;
27
+ B->block_num = -1;
28
+ calloc2 (B->base, 20, EXIT);
29
+ B->block_end = 20;
30
+ }
31
+
32
+ /* termination */
33
+ void BASE_end (BASE *B){
34
+ int i;
35
+ FLOOP (i, 0, B->block_end) free2 (B->base[i]);
36
+ free2 (B->base);
37
+ *B = INIT_BASE;
38
+ }
39
+
40
+ /* return pointer to the cell corresponding to the given index */
41
+ void *BASE_pnt (BASE *B, size_t i){
42
+ return ( B->base[i/BASE_BLOCK] + (i%BASE_BLOCK)*B->unit);
43
+ }
44
+ /* return index corresponding to the given pointer */
45
+ size_t BASE_index (BASE *B, void *x){
46
+ size_t i;
47
+ FLOOP (i, 0, (size_t)(B->block_end+1)){
48
+ if ( ((char*)x)>= B->base[i] && ((char*)x)<=B->base[i]+B->unit*BASE_BLOCK )
49
+ return ( i*BASE_BLOCK + ((size_t)(((char *)x) - B->base[i])) / B->unit);
50
+ }
51
+ return (0);
52
+ }
53
+
54
+ /* increment the current memory block pointer and (re)allcate memory if necessary */
55
+ void *BASE_get_memory (BASE *B, int i){
56
+ B->num += i;
57
+ if ( B->num >= B->block_siz ){ /* if reach to the end of base array */
58
+ B->num = i; /* allocate one more base array, and increment the counter */
59
+ B->block_num++;
60
+ reallocx(B->base, B->block_end, B->block_num, NULL, EXIT0);
61
+ if ( B->base[B->block_num] == NULL )
62
+ malloc2 (B->base[B->block_num], B->block_siz*B->unit, EXIT0);
63
+ return (B->base[B->block_num]);
64
+ }
65
+ return (B->base[B->block_num] + (B->num-i)*B->unit);
66
+ }
67
+
68
+
69
+ /* allocate new cell */
70
+ void *BASE_new (BASE *B){
71
+ char *x;
72
+
73
+ /* use deleted cell if it exists */
74
+ if ( B->dellist != ((void *)B) ){
75
+ x = (char *)B->dellist; /* return the deleted cell */
76
+ B->dellist = (void *)(*((char **)x)); /* increment the head of the list */
77
+ } else {
78
+ /* take a new cell from the base array if no deleted one exists */
79
+ x = (char *)BASE_get_memory (B, 1);
80
+ }
81
+ return (x);
82
+ }
83
+
84
+ /* delete one cell. (add to the deleted list) */
85
+ void BASE_del (BASE *B, void *x){
86
+ *((void **)x) = B->dellist;
87
+ B->dellist = x;
88
+ }
89
+
90
+ #endif
91
+
92
+
@@ -0,0 +1,59 @@
1
+ /*
2
+ blocked memory allocation library
3
+ 12/Mar/2002 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, please
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
+
13
+
14
+ #ifndef _base_h_
15
+ #define _base_h_
16
+
17
+ #include"stdlib2.h"
18
+
19
+ /* structure for base array */
20
+ #define BASE_UNIT 16
21
+ #define BASE_BLOCK 65536
22
+
23
+ typedef struct {
24
+ unsigned char type;
25
+ char **base;
26
+ int block_siz; // size of one block of memory
27
+ int block_num; // currently using block
28
+ int unit; // size of one unit memory
29
+ int num; // current position in a block
30
+ int block_end; // current end of the block
31
+ void *dellist;
32
+ } BASE;
33
+
34
+ extern BASE INIT_BASE;
35
+
36
+ /* initialization, and allocate memory for header */
37
+ void BASE_alloc (BASE *B, int unit, int block_siz);
38
+
39
+ /* termination */
40
+ void BASE_end (BASE *B);
41
+
42
+ /* return pointer to the cell corresponding to the given index */
43
+ void *BASE_pnt (BASE *B, size_t i);
44
+
45
+ /* return index corresponding to the given pointer */
46
+ size_t BASE_index (BASE *B, void *x);
47
+
48
+ /* increment the current memory block pointer and (re)allcate memory if necessary */
49
+ void *BASE_get_memory (BASE *B, int i);
50
+
51
+ /* allocate new cell */
52
+ void *BASE_new (BASE *B);
53
+
54
+ /* delete one cell. (add to the deleted list) */
55
+ void BASE_del (BASE *B, void *x);
56
+
57
+
58
+ #endif
59
+