aboutsummaryrefslogtreecommitdiff
path: root/src/pruning.c
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano.tronto@gmail.com>2021-12-23 19:01:33 +0100
committerSebastiano Tronto <sebastiano.tronto@gmail.com>2021-12-23 19:01:33 +0100
commit4fb970ad4e7d0558f7bf32dbad2333dbf3cb3ab4 (patch)
treef8cf70973ed3fb78816e89bd9034c983b68b6062 /src/pruning.c
parent4dddac9e257433a8e2f5f763d91470a7e05ff680 (diff)
downloadnissy-4fb970ad4e7d0558f7bf32dbad2333dbf3cb3ab4.tar.gz
nissy-4fb970ad4e7d0558f7bf32dbad2333dbf3cb3ab4.zip
Fixes for yesterday's commit
Diffstat (limited to 'src/pruning.c')
-rw-r--r--src/pruning.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/pruning.c b/src/pruning.c
index 9fdc32e..5c74e1e 100644
--- a/src/pruning.c
+++ b/src/pruning.c
@@ -127,19 +127,25 @@ findchunk(PruneData *pd, int nchunks, uint64_t i)
127void 127void
128genptable(PruneData *pd, int nthreads) 128genptable(PruneData *pd, int nthreads)
129{ 129{
130 bool compact;
130 int d, nchunks; 131 int d, nchunks;
131 uint64_t oldn; 132 uint64_t oldn, sz;
132 133
133 if (pd->generated) 134 if (pd->generated)
134 return; 135 return;
135 136
136 /* TODO: check if memory is enough, otherwise maybe exit gracefully? */ 137 /* TODO: check if memory is enough, otherwise maybe exit gracefully? */
137 pd->ptable = malloc(ptablesize(pd) * sizeof(entry_group_t)); 138 sz = ptablesize(pd) * (pd->compact ? 2 : 1);
139 pd->ptable = malloc(sz * sizeof(entry_group_t));
138 140
139 if (read_ptable_file(pd)) { 141 if (read_ptable_file(pd)) {
140 pd->generated = true; 142 pd->generated = true;
141 return; 143 return;
142 } 144 }
145
146 /* For the first steps we proceed the same way for compact and not */
147 compact = pd->compact;
148 pd->compact = false;
143 pd->generated = true; 149 pd->generated = true;
144 150
145 nchunks = MIN(ptablesize(pd), 100000); 151 nchunks = MIN(ptablesize(pd), 100000);
@@ -169,7 +175,7 @@ genptable(PruneData *pd, int nthreads)
169 fprintf(stderr, "Pruning table generated!\n"); 175 fprintf(stderr, "Pruning table generated!\n");
170 176
171 genptable_setbase(pd); 177 genptable_setbase(pd);
172 if (pd->compact) 178 if (compact)
173 genptable_compress(pd); 179 genptable_compress(pd);
174 180
175 if (!write_ptable_file(pd)) 181 if (!write_ptable_file(pd))
@@ -217,18 +223,22 @@ genptable_compress(PruneData *pd)
217 uint64_t i, j; 223 uint64_t i, j;
218 entry_group_t mask, v; 224 entry_group_t mask, v;
219 225
220 pd->compact = false; 226 fprintf(stderr, "Compressing table to 2 bits per entry\n");
227
221 for (i = 0; i < pd->coord->max; i += ENTRIES_PER_GROUP_COMPACT) { 228 for (i = 0; i < pd->coord->max; i += ENTRIES_PER_GROUP_COMPACT) {
222 mask = 0; 229 mask = (entry_group_t)0;
223 for (j = 0; j < ENTRIES_PER_GROUP_COMPACT; j++) { 230 for (j = 0; j < ENTRIES_PER_GROUP_COMPACT; j++) {
231 if (i+j >= pd->coord->max)
232 break;
224 val = ptableval_index(pd, i+j) - pd->base; 233 val = ptableval_index(pd, i+j) - pd->base;
225 v = MIN(3, MAX(0, val)); 234 v = (entry_group_t)MIN(3, MAX(0, val));
226 mask |= v << (2*j); 235 mask |= v << (2*j);
227 } 236 }
228 pd->ptable[i/ENTRIES_PER_GROUP_COMPACT] = mask; 237 pd->ptable[i/ENTRIES_PER_GROUP_COMPACT] = mask;
229 } 238 }
239
230 pd->compact = true; 240 pd->compact = true;
231 realloc(pd->ptable, sizeof(entry_group_t) * ptablesize(pd)); 241 pd->ptable = realloc(pd->ptable, sizeof(entry_group_t)*ptablesize(pd));
232} 242}
233 243
234static void 244static void
@@ -390,9 +400,9 @@ ptableval_index(PruneData *pd, uint64_t ind)
390 } 400 }
391 401
392 e = pd->compact ? ENTRIES_PER_GROUP_COMPACT : ENTRIES_PER_GROUP; 402 e = pd->compact ? ENTRIES_PER_GROUP_COMPACT : ENTRIES_PER_GROUP;
393 m = pd->compact ? 3 : 15; 403 m = (entry_group_t)(pd->compact ? 3 : 15);
394 404
395 sh = 4 * (ind % e); 405 sh = (ind % e) * (pd->compact ? 2 : 4);
396 mask = m << sh; 406 mask = m << sh;
397 i = ind/e; 407 i = ind/e;
398 408
@@ -402,7 +412,7 @@ ptableval_index(PruneData *pd, uint64_t ind)
402 if (ret) 412 if (ret)
403 ret += pd->base; 413 ret += pd->base;
404 else 414 else
405 ret = ptableval_index(pd->fallback, ind % pd->fbmod); 415 ret = ptableval_index(pd->fallback, ind / pd->fbmod);
406 } 416 }
407 417
408 return ret; 418 return ret;

Generated with cgit - Back to sebastiano.tronto.net