176using namespace Aleph;
177namespace fs = std::filesystem;
186 cout <<
"+" << string(70,
'-') <<
"+" <<
endl;
187 cout <<
"| " << left << setw(68) << title <<
" |" <<
endl;
188 cout <<
"+" << string(70,
'-') <<
"+" <<
endl;
199 cout <<
" " << label <<
":" <<
endl;
200 cout <<
" Size (committed): " << arena.size() <<
" bytes" <<
endl;
201 cout <<
" Capacity (mapped): " << arena.capacity() <<
" bytes" <<
endl;
202 cout <<
" Available: " << arena.avail() <<
" bytes" <<
endl;
203 cout <<
" Is empty: " << (arena.empty() ?
"yes" :
"no") <<
endl;
214 const string arena_file =
"/tmp/aleph_arena_basic.dat";
227 const char*
message =
"Hola desde Colombia!";
230 char* ptr = arena.reserve(
msg_len);
238 const char*
cities[] = {
"Bogota",
"Medellin",
"Cali",
"Barranquilla"};
241 char* p = arena.reserve(len);
252 cout <<
" Stored strings:" <<
endl;
261 cout <<
"\n Data synced to disk" <<
endl;
282 const string arena_file =
"/tmp/aleph_arena_struct.dat";
291 {
"Bogota", 8281, 1775.98, 2640},
292 {
"Medellin", 2569, 380.64, 1495},
293 {
"Cali", 2228, 564.33, 1018},
294 {
"Barranquilla", 1274, 154.00, 18},
295 {
"Cartagena", 1047, 609.10, 2}
301 char* ptr = arena.reserve(
sizeof(
size_t));
303 arena.commit(
sizeof(
size_t));
323 cout <<
" " << string(60,
'-') <<
endl;
324 cout <<
" " << left << setw(15) <<
"City"
325 << right << setw(10) <<
"Pop (k)"
326 << setw(12) <<
"Area (km2)"
327 << setw(12) <<
"Alt (m)" <<
endl;
328 cout <<
" " << string(60,
'-') <<
endl;
335 cout <<
" " << left << setw(15) <<
rec.name
336 << right << setw(10) <<
rec.population
337 << setw(12) << fixed << setprecision(2) <<
rec.area
338 << setw(12) <<
rec.altitude <<
endl;
350 print_header(
"Example 3: Arena Growth (Automatic Remapping)");
352 const string arena_file =
"/tmp/aleph_arena_growth.dat";
357 cout <<
"\n Initial capacity: " << arena.capacity() <<
" bytes" <<
endl;
358 cout <<
" (Initial region size: " << MapArena::initial_rgn_size <<
" bytes)" <<
endl;
367 const size_t chunk_size = 1000;
369 for (
int i = 0; i < 20; ++i) {
370 char* ptr = arena.reserve(chunk_size);
373 memset(ptr,
'A' + (i % 26), chunk_size);
374 arena.commit(chunk_size);
380 <<
" bytes (after " << arena.size() <<
" allocated)" <<
endl;
390 cout <<
"\n Verifying data integrity..." <<
endl;
391 char* ptr = arena.begin();
393 for (
int i = 0; i < 20 && valid; ++i) {
395 for (
size_t j = 0; j < chunk_size && valid; ++j) {
398 cout <<
" ERROR: Data corruption at chunk " << i <<
endl;
404 cout <<
" All data verified successfully!" <<
endl;
417 const string arena_file =
"/tmp/aleph_arena_log.dat";
426 "[2024-01-15 08:00:00] Sistema iniciado en Bogota",
427 "[2024-01-15 08:00:01] Conexion con servidor Medellin",
428 "[2024-01-15 08:00:02] Usuario: Juan Perez",
429 "[2024-01-15 08:00:05] Transaccion #1001: $150,000 COP",
430 "[2024-01-15 08:00:07] Sincronizacion con Cali",
431 "[2024-01-15 08:00:10] Backup iniciado",
432 "[2024-01-15 08:00:15] Backup completado",
433 "[2024-01-15 08:00:20] Alerta: Memoria al 75%"
439 size_t len =
strlen(entry) + 1;
440 char* ptr = arena.reserve(len);
452 cout <<
"\n Log contents:" <<
endl;
453 cout <<
" " << string(55,
'-') <<
endl;
455 char* ptr = arena.begin();
457 while (ptr < arena.end()) {
458 cout <<
" " << ptr <<
endl;
463 cout <<
" " << string(55,
'-') <<
endl;
464 cout <<
" Total entries: " <<
count <<
endl;
477 const string arena_file =
"/tmp/aleph_arena_move.dat";
484 const char* data =
"Datos importantes de Colombia";
489 cout <<
" arena1 size: " <<
arena1.size() <<
endl;
490 cout <<
" arena1 is_initialized: " <<
arena1.is_initialized() <<
endl;
496 cout <<
" After move construction:" <<
endl;
497 cout <<
" arena1 is_initialized: " <<
arena1.is_initialized() <<
endl;
498 cout <<
" arena2 is_initialized: " <<
arena2.is_initialized() <<
endl;
499 cout <<
" arena2 size: " <<
arena2.size() <<
endl;
500 cout <<
" arena2 data: \"" <<
arena2.begin() <<
"\"" <<
endl;
505 cout <<
" arena3 (before): is_initialized = " <<
arena3.is_initialized() <<
endl;
509 cout <<
" After move assignment:" <<
endl;
510 cout <<
" arena2 is_initialized: " <<
arena2.is_initialized() <<
endl;
511 cout <<
" arena3 is_initialized: " <<
arena3.is_initialized() <<
endl;
512 cout <<
" arena3 data: \"" <<
arena3.begin() <<
"\"" <<
endl;
523 print_header(
"Example 6: Memory Statistics and Efficiency");
525 const string arena_file =
"/tmp/aleph_arena_stats.dat";
533 int allocations[] = {10, 50, 100, 500, 1000, 2000};
535 cout <<
"\n Allocation pattern analysis:" <<
endl;
536 cout <<
" " << string(50,
'-') <<
endl;
537 cout <<
" " << setw(10) <<
"Alloc Size"
538 << setw(12) <<
"Committed"
539 << setw(12) <<
"Capacity"
540 << setw(15) <<
"Utilization" <<
endl;
541 cout <<
" " << string(50,
'-') <<
endl;
544 char* ptr = arena.reserve(
size);
549 double utilization = 100.0 * arena.size() / arena.capacity();
551 cout <<
" " << setw(10) <<
size
552 << setw(12) << arena.size()
553 << setw(12) << arena.capacity()
554 << setw(14) << fixed << setprecision(1) << utilization <<
"%" <<
endl;
559 cout << arena <<
endl;
571 cout <<
"========================================================================" <<
endl;
572 cout <<
" ALEPH-W MAP ARENA EXAMPLE" <<
endl;
573 cout <<
" Memory-Mapped File Arena Allocator" <<
endl;
574 cout <<
"========================================================================" <<
endl;
584 cout <<
"========================================================================" <<
endl;
585 cout <<
" Example completed successfully!" <<
endl;
586 cout <<
"========================================================================" <<
endl;
Memory-mapped file arena allocator.
Minimal std::expected-style result type for C++20.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
void print_arena_status(const MapArena &arena, const string &label)
void demo_basic_operations()
void demo_structured_data()
void print_subheader(const string &subtitle)
void demo_move_semantics()
Main namespace for Aleph-w library functions.
void message(const char *file, int line, const char *format,...)
Print an informational message with file and line info.
size_t size(Node *root) noexcept
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.