100 cout <<
"============================================================\n";
101 cout <<
" SCENARIO 1: Sales Analytics (Sum_Disjoint_Sparse_Table)\n";
102 cout <<
"============================================================\n\n";
106 {120, 95, 140, 88, 175, 63, 210, 155, 102, 180,
107 135, 90, 200, 110, 165};
111 cout <<
"Daily revenue ($ thousands):\n\n";
112 cout <<
" Day Revenue\n";
113 cout <<
" --- -------\n";
119 <<
sales.num_levels() <<
" levels\n";
121 cout <<
"\nRange sum queries:\n\n";
122 cout <<
" Range Total Description\n";
123 cout <<
" ---------- -------- ----------------------------\n";
125 struct Query {
size_t l, r;
const char *
desc; };
127 {0, 4,
"Week 1 (Mon-Fri)"},
128 {5, 9,
"Week 2 (Mon-Fri)"},
129 {10, 14,
"Week 3 (Mon-Fri)"},
130 {0, 14,
"Entire period"},
131 {3, 7,
"Mid-period slice"},
132 {6, 6,
"Day 6 alone"},
138 cout <<
" [" <<
setw(2) << q.l <<
", " <<
setw(2) << q.r <<
"]"
139 <<
" $" <<
setw(4) <<
total <<
"K " << q.desc <<
"\n";
144 for (
size_t i = 0; i <= 14; ++i)
bf +=
revenue[i];
146 cout <<
"\n ✓ Brute-force verification passed for full range\n";
156 cout <<
"============================================================\n";
157 cout <<
" SCENARIO 2: Reliability Analysis (Product_Disjoint_Sparse_Table)\n";
158 cout <<
"============================================================\n\n";
162 {0.99, 0.95, 0.98, 0.97, 0.93, 0.96, 0.99, 0.94, 0.98, 0.97};
165 {
"Power",
"CPU",
"Memory",
"Disk",
"Network",
166 "Cooling",
"PSU",
"GPU",
"SSD",
"Bus"};
170 cout <<
"Component reliabilities:\n\n";
171 cout <<
" # Component Reliability\n";
172 cout <<
" -- ---------- -----------\n";
178 cout <<
"\nSubsystem reliability queries (product of individual):\n\n";
179 cout <<
" Range Reliability Description\n";
180 cout <<
" ---------- ----------- ----------------------\n";
182 struct Query {
size_t l, r;
const char *
desc; };
184 {0, 2,
"Core compute (Power-Memory)"},
185 {3, 5,
"Storage+Net (Disk-Cooling)"},
186 {6, 9,
"Expansion (PSU-Bus)"},
187 {0, 9,
"Full system"},
188 {1, 4,
"CPU through Network"},
195 cout <<
" [" <<
setw(2) << q.l <<
", " <<
setw(2) << q.r <<
"]"
197 <<
" " << q.desc <<
"\n";
216 constexpr unsigned operator()(
unsigned a,
unsigned b)
const noexcept
224 cout <<
"============================================================\n";
225 cout <<
" SCENARIO 3: XOR Checksums (Gen_Disjoint_Sparse_Table)\n";
226 cout <<
"============================================================\n\n";
229 {0xA3, 0x5F, 0x12, 0xB7, 0x8C, 0xE1, 0x3D, 0x74, 0x9A, 0x06};
233 cout <<
"Data blocks (hex):\n\n";
234 cout <<
" Index Value\n";
235 cout <<
" ----- -----\n";
236 for (
size_t i = 0; i < data.size(); ++i)
242 <<
xor_tbl.num_levels() <<
" levels\n";
244 cout <<
"\nRange XOR queries:\n\n";
245 cout <<
" Range XOR Values\n";
246 cout <<
" -------- ------ ------\n";
248 struct Query {
size_t l, r; };
249 Query queries[] = {{0, 2}, {0, 9}, {3, 5}, {1, 4}, {6, 9}, {4, 4}, {0, 5}};
253 unsigned result =
xor_tbl.query(q.l, q.r);
255 cout <<
" [" << q.l <<
", " << q.r <<
"] 0x"
259 for (
size_t i = q.l; i <= q.r; ++i)
261 if (i > q.l)
cout <<
", ";
273 for (
size_t i = q.l; i <= q.r; ++i)
bf ^= data[i];
278 cout <<
"\n ✓ All XOR queries verified against brute-force\n";
288 cout <<
"============================================================\n";
289 cout <<
" SCENARIO 5: Construction from different containers\n";
290 cout <<
"============================================================\n\n";
292 const vector<int>
raw = {5, 3, 7, 1, 9, 2, 8, 4, 6};
296 for (
size_t i = 0; i <
raw.
size(); ++i)
305 for (
size_t i = 0; i <
raw.
size(); ++i)
315 cout <<
"From Array<int>: sum[0,8] = " <<
from_arr.query(0, 8) <<
"\n";
316 cout <<
"From vector<int>: sum[0,8] = " <<
from_vec.query(0, 8) <<
"\n";
317 cout <<
"From DynList<int>: sum[0,8] = " <<
from_dl.query(0, 8) <<
"\n";
318 cout <<
"From init-list: sum[0,8] = " <<
from_il.query(0, 8) <<
"\n";
327 cout <<
"\nReconstructed values: ";
328 for (
size_t i = 0; i <
vals.
size(); ++i)
330 if (i > 0)
cout <<
", ";
337 for (
size_t r =
l; r <
raw.
size(); ++r)
340 cout <<
"\n ✓ All construction methods produce identical results\n";
350 cout <<
"============================================================\n";
351 cout <<
" SCENARIO 4: Parlay Betting (Product_Disjoint_Sparse_Table)\n";
352 cout <<
"============================================================\n\n";
358 {
"Arsenal vs Chelsea", 1.85},
359 {
"Real Madrid vs Barcelona", 2.10},
360 {
"Bayern vs Dortmund", 1.55},
361 {
"PSG vs Lyon", 1.40},
362 {
"Juventus vs Inter", 2.25},
363 {
"Liverpool vs Man City", 3.10},
364 {
"Ajax vs Feyenoord", 1.90},
365 {
"Benfica vs Porto", 2.05},
366 {
"Milan vs Napoli", 1.75},
367 {
"Atletico vs Sevilla", 1.60},
368 {
"Tottenham vs Man United", 2.40},
369 {
"Celtic vs Rangers", 1.95},
372 const size_t N =
sizeof(
card) /
sizeof(
card[0]);
374 vector<double>
odds(
N);
375 for (
size_t i = 0; i <
N; ++i)
380 cout <<
"Saturday Match Card:\n\n";
381 cout <<
" # Match Odds\n";
382 cout <<
" -- --------------------------- ----\n";
383 for (
size_t i = 0; i <
N; ++i)
386 <<
card[i].odds <<
"\n";
389 <<
parlay.num_levels() <<
" levels\n";
392 cout <<
"\nParlay (accumulator) queries — combined payout multiplier:\n\n";
393 cout <<
" Parlay Combined $10 Bet\n";
394 cout <<
" Range Legs Multiplier Payout\n";
395 cout <<
" ------ ------ ---------- --------\n";
411 size_t legs = q.r - q.l + 1;
414 cout <<
" [" <<
setw(2) << q.l <<
"," <<
setw(2) << q.r <<
"]"
415 <<
" " <<
setw(2) <<
legs <<
"-fold"
427 cout <<
"\n Full-card 12-fold parlay: $10 bet pays $"
432 cout <<
"\n Note: product is NOT idempotent (odds × odds ≠ odds),\n"
433 <<
" so a classical Sparse Table cannot handle parlay queries.\n"
434 <<
" The Disjoint Sparse Table handles them in O(1).\n";
436 cout <<
"\n ✓ Full-card parlay verified against brute-force\n";
Simple dynamic array with automatic resizing and functional operations.
T & append(const T &data)
Append a copy of data
Dynamic singly linked list with functional programming support.
T & append(const T &item)
Append a new item by copy.
Disjoint Sparse Table over an arbitrary associative binary operation.
size_t size() const noexcept
Count the number of elements of the list.
void scenario_parlay_betting()
void scenario_construction()
void scenario_sales_analytics()
void scenario_probability()
void scenario_xor_checksum()
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_abs_function > > abs(const __gmp_expr< T, U > &expr)
Main namespace for Aleph-w library functions.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Disjoint Sparse Table for range product queries.
Disjoint Sparse Table for range sum queries.
constexpr unsigned operator()(unsigned a, unsigned b) const noexcept
Disjoint Sparse Table for static range queries in O(1).