@@ -219,20 +219,25 @@ int main() {
219219 am_Solver *S;
220220
221221 // demo how to use a memory pool across solvers.
222- am_MemPool mempool;
223- am_initpool (&mempool, sizeof (am_Constraint));
224- auto alloc = [&mempool](void *ptr, size_t ns, am_AllocType ty) {
222+ am_MemPool conspool; am_initpool (&conspool, sizeof (am_Constraint));
223+ const size_t hash_size = (sizeof (am_Num) + sizeof (am_Key)) * 8 ;
224+ am_MemPool hashpool; am_initpool (&hashpool, hash_size);
225+ auto alloc = [&](void *ptr, size_t ns, size_t os, am_AllocType ty) {
225226 if (ty == am_AllocConstraint) {
226- if (ns) return am_poolalloc (&mempool);
227- return am_poolfree (&mempool, ptr), (void *)0 ;
227+ if (ns) return am_poolalloc (&conspool);
228+ return am_poolfree (&conspool, ptr), (void *)0 ;
229+ }
230+ if (ty == am_AllocHash) {
231+ if (ns == hash_size && os == 0 ) return am_poolalloc (&hashpool);
232+ if (os == hash_size && ns == 0 ) return am_poolfree (&hashpool, ptr), (void *)0 ;
228233 }
229234 if (ns) return realloc (ptr, ns);
230235 return free (ptr), (void *)0 ;
231236 };
232- auto alloc_func = [](void ** pud, void *ptr, size_t ns, size_t , am_AllocType ty) {
237+ auto alloc_func = [](void ** pud, void *ptr, size_t ns, size_t os , am_AllocType ty) {
233238 const auto func = &decltype (alloc)::operator ();
234239 auto alloc_ptr = *(decltype (alloc)**)(pud);
235- return (alloc_ptr->*func)(ptr, ns, ty);
240+ return (alloc_ptr->*func)(ptr, ns, os, ty);
236241 };
237242
238243#if !DISABLE_BUILD
@@ -276,7 +281,7 @@ int main() {
276281 am_delsolver (S);
277282 }
278283
279- ankerl::nanobench::Bench ().minEpochIterations (2000 ).run (" load solver" , [&] {
284+ ankerl::nanobench::Bench ().minEpochIterations (10000 ).run (" load solver" , [&] {
280285 struct MyLoader {
281286 am_Loader base;
282287 am_Num values[37 ];
@@ -302,7 +307,6 @@ int main() {
302307 am_Solver *S = am_newsolver (alloc_func, &alloc);
303308 int ret = am_load (S, &l.base );
304309 assert (ret == AM_OK), (void )ret;
305- ankerl::nanobench::doNotOptimizeAway (S); // < prevent the compiler to optimize away the S
306310 am_delsolver (S);
307311 });
308312#endif /* !DISABLE_LOAD */
@@ -329,8 +333,8 @@ int main() {
329333 build_solver (S, widthVar, heightVar, values);
330334
331335 for (const Size& size : sizes) {
332- am_Num width = size.width ;
333- am_Num height = size.height ;
336+ am_Num width = (am_Num) size.width ;
337+ am_Num height = (am_Num) size.height ;
334338
335339 ankerl::nanobench::Bench ().minEpochIterations (100000 ).run (" suggest value " + std::to_string (size.width ) + " x" + std::to_string (size.height ), [&] {
336340 am_suggest (S, widthVar, width);
@@ -339,10 +343,14 @@ int main() {
339343 });
340344 }
341345
346+ ankerl::nanobench::doNotOptimizeAway (width);
347+ ankerl::nanobench::doNotOptimizeAway (height);
348+
342349 am_delsolver (S);
343350#endif /* !DISABLE_SUGGEST */
344351
345- am_freepool (&mempool);
352+ am_freepool (&conspool);
353+ am_freepool (&hashpool);
346354 return 0 ;
347355}
348356
0 commit comments