149using namespace Aleph;
158 cout <<
"+" << string(70,
'-') <<
"+" << endl;
159 cout <<
"| " << left << setw(68) << title <<
" |" << endl;
160 cout <<
"+" << string(70,
'-') <<
"+" << endl;
165 cout <<
"\n " << subtitle << endl;
166 cout <<
" " << string(subtitle.length(),
'-') << endl;
181 dept_codes.
insert(
"05",
"Antioquia");
182 dept_codes.
insert(
"08",
"Atlantico");
183 dept_codes.
insert(
"11",
"Bogota D.C.");
184 dept_codes.
insert(
"13",
"Bolivar");
185 dept_codes.
insert(
"15",
"Boyaca");
186 dept_codes.
insert(
"17",
"Caldas");
187 dept_codes.
insert(
"19",
"Cauca");
188 dept_codes.
insert(
"20",
"Cesar");
189 dept_codes.
insert(
"23",
"Cordoba");
190 dept_codes.
insert(
"25",
"Cundinamarca");
191 dept_codes.
insert(
"27",
"Choco");
192 dept_codes.
insert(
"41",
"Huila");
193 dept_codes.
insert(
"44",
"La Guajira");
194 dept_codes.
insert(
"47",
"Magdalena");
195 dept_codes.
insert(
"50",
"Meta");
196 dept_codes.
insert(
"52",
"Narino");
197 dept_codes.
insert(
"54",
"Norte de Santander");
198 dept_codes.
insert(
"63",
"Quindio");
199 dept_codes.
insert(
"66",
"Risaralda");
200 dept_codes.
insert(
"68",
"Santander");
201 dept_codes.
insert(
"70",
"Sucre");
202 dept_codes.
insert(
"73",
"Tolima");
203 dept_codes.
insert(
"76",
"Valle del Cauca");
204 dept_codes.
insert(
"91",
"Amazonas");
206 cout <<
"\n Total departments registered: " << dept_codes.
size() << endl;
211 codes_to_lookup.
append(
"11");
212 codes_to_lookup.
append(
"05");
213 codes_to_lookup.
append(
"76");
214 codes_to_lookup.
append(
"91");
216 for (
size_t i = 0; i < codes_to_lookup.
size(); ++i)
218 const string&
code = codes_to_lookup(i);
219 cout <<
" Code " <<
code <<
" -> " << dept_codes[
code] << endl;
228 names_to_lookup.
append(
"Bogota D.C.");
229 names_to_lookup.
append(
"Antioquia");
230 names_to_lookup.
append(
"Valle del Cauca");
231 names_to_lookup.
append(
"Amazonas");
233 for (
size_t i = 0; i < names_to_lookup.
size(); ++i)
235 const string& name = names_to_lookup(i);
236 cout <<
" " << left << setw(20) << name <<
" -> Code "
237 << name_to_code[name] << endl;
242 cout <<
" Has code '11'? " << (dept_codes.
valid_key(
"11") ?
"Yes" :
"No") << endl;
243 cout <<
" Has code '99'? " << (dept_codes.
valid_key(
"99") ?
"Yes" :
"No") << endl;
252 print_header(
"Example 2: Variadic Constructor - Coffee Regions");
256 "Huila",
"Sur del pais, cafe con notas citricos",
257 "Narino",
"Alta montania, cafe suave y frutal",
258 "Cauca",
"Region volcanica, cafe de acidez brillante",
259 "Tolima",
"Clima templado, cafe balanceado",
260 "Antioquia",
"Tradicion cafetera, cafe con cuerpo",
261 "Caldas",
"Eje Cafetero, cafe clasico colombiano",
262 "Quindio",
"Paisaje Cultural Cafetero, cafe aromatico",
263 "Risaralda",
"Eje Cafetero, cafe de montania",
264 "Santander",
"Oriente, cafe organico y especial"
267 cout <<
"\n Coffee regions: " << coffee_regions.
size() << endl;
272 coffee_regions.
for_each([](
const string& region,
const string& profile) {
273 cout <<
" " << left << setw(12) << region <<
": " << profile << endl;
278 cout <<
"\n All regions: ";
280 for (
auto it =
keys.get_it(); it.has_curr(); it.next_ne())
281 cout << it.get_curr() <<
" ";
291 print_header(
"Example 3: Numeric Mappings - City Population");
296 population.
insert(
"Bogota", 8281);
297 population.
insert(
"Medellin", 2569);
298 population.
insert(
"Cali", 2228);
299 population.
insert(
"Barranquilla", 1274);
300 population.
insert(
"Cartagena", 1047);
301 population.
insert(
"Cucuta", 711);
302 population.
insert(
"Bucaramanga", 609);
303 population.
insert(
"Pereira", 488);
304 population.
insert(
"Santa Marta", 538);
305 population.
insert(
"Ibague", 580);
309 population.
for_each([](
const string& city,
int pop) {
310 cout <<
" " << left << setw(15) << city <<
": "
311 << right << setw(6) << pop <<
" mil habitantes" << endl;
317 auto values = population.
values();
318 for (
auto it = values.get_it(); it.has_curr(); it.next_ne())
319 total += it.get_curr();
321 cout <<
" Sum of registered cities: " << total <<
" mil habitantes" << endl;
322 cout <<
" (Approx. " << total / 1000.0 <<
" millones)" << endl;
326 cout <<
" Contains city with 2569k? "
327 << (population.
contains_value(2569) ?
"Yes (Medellin)" :
"No") << endl;
328 cout <<
" Contains city with 5000k? "
338 print_header(
"Example 4: Encoding/Decoding - Language Codes");
343 lang_codes.
insert(
"way",
"Wayuunaiki");
344 lang_codes.
insert(
"cag",
"Embera");
345 lang_codes.
insert(
"iku",
"Arhuaco");
346 lang_codes.
insert(
"snn",
"Inga");
347 lang_codes.
insert(
"kwi",
"Awa Pit");
348 lang_codes.
insert(
"guc",
"Guajiro");
349 lang_codes.
insert(
"pbb",
"Nasa Yuwe");
350 lang_codes.
insert(
"mvt",
"Motilon");
351 lang_codes.
insert(
"cub",
"Cubeo");
352 lang_codes.
insert(
"tic",
"Tikuna");
354 cout <<
"\n Indigenous languages registered: " << lang_codes.
size() << endl;
362 languages.
append(
"Wayuunaiki");
363 languages.
append(
"Nasa Yuwe");
364 languages.
append(
"Tikuna");
365 languages.
append(
"Embera");
367 for (
size_t i = 0; i < languages.
size(); ++i)
369 const string& lang = languages(i);
370 cout <<
" " << left << setw(15) << lang <<
" -> code: "
371 << decoder[lang] << endl;
382 for (
size_t i = 0; i < codes.
size(); ++i)
384 const string&
code = codes(i);
385 cout <<
" Code " <<
code <<
" -> " << lang_codes[
code] << endl;
395 print_header(
"Example 5: Modifiable Mapping - Exchange Rates");
400 exchange[
"USD"] = 4150.0;
401 exchange[
"EUR"] = 4520.0;
402 exchange[
"GBP"] = 5280.0;
403 exchange[
"MXN"] = 245.0;
404 exchange[
"BRL"] = 830.0;
405 exchange[
"ARS"] = 4.7;
406 exchange[
"PEN"] = 1120.0;
407 exchange[
"CLP"] = 4.5;
411 exchange.
for_each([](
const string& currency,
double rate) {
412 cout <<
" 1 " << currency <<
" = " << fixed << setprecision(2)
413 << rate <<
" COP" << endl;
419 exchange[
"USD"] = 4200.0;
420 exchange[
"EUR"] = 4480.0;
422 cout <<
" Updated USD: 1 USD = " << exchange[
"USD"] <<
" COP" << endl;
423 cout <<
" Updated EUR: 1 EUR = " << exchange[
"EUR"] <<
" COP" << endl;
427 cout <<
" Removing ARS..." << endl;
429 cout <<
" Has ARS? " << (exchange.
valid_key(
"ARS") ?
"Yes" :
"No") << endl;
430 cout <<
" Total currencies: " << exchange.
size() << endl;
434 double usd_amount = 100.0;
435 double eur_amount = 50.0;
437 cout <<
" $" << usd_amount <<
" USD = $"
438 << fixed << setprecision(0) << (usd_amount * exchange[
"USD"]) <<
" COP" << endl;
439 cout <<
" " << eur_amount <<
" EUR = $"
440 << (eur_amount * exchange[
"EUR"]) <<
" COP" << endl;
460 cities.
insert(
"Bogota", {4.711, -74.072});
461 cities.
insert(
"Medellin", {6.244, -75.574});
462 cities.
insert(
"Cali", {3.451, -76.532});
463 cities.
insert(
"Barranquilla", {10.964, -74.796});
464 cities.
insert(
"Cartagena", {10.391, -75.479});
465 cities.
insert(
"Cucuta", {7.893, -72.508});
466 cities.
insert(
"Santa Marta", {11.241, -74.199});
467 cities.
insert(
"Leticia", {-4.215, -69.940});
468 cities.
insert(
"San Andres", {12.584, -81.701});
473 cout <<
" " << left << setw(15) << city
474 << fixed << setprecision(3)
475 <<
"(" << setw(8) << c.lat <<
", " << setw(8) << c.lon <<
")" << endl;
480 Coord bogota = cities[
"Bogota"];
483 auto approx_distance = [&](
const string& city) {
484 Coord other = cities[city];
485 double dlat = (other.lat - bogota.lat) * 111.0;
486 double dlon = (other.lon - bogota.lon) * 111.0 *
cos(bogota.lat * M_PI / 180);
487 return sqrt(dlat * dlat + dlon * dlon);
491 target_cities.
append(
"Medellin");
492 target_cities.
append(
"Cali");
493 target_cities.
append(
"Barranquilla");
494 target_cities.
append(
"Leticia");
495 target_cities.
append(
"San Andres");
497 for (
size_t i = 0; i < target_cities.
size(); ++i)
499 const string& city = target_cities(i);
500 cout <<
" Bogota -> " << left << setw(15) << city
501 <<
"~" << fixed << setprecision(0) << approx_distance(city) <<
" km" << endl;
512 cout <<
"========================================================================" << endl;
513 cout <<
" ALEPH-W MAPPING EXAMPLE" << endl;
514 cout <<
" Bidirectional Key-Value Mappings" << endl;
515 cout <<
"========================================================================" << endl;
525 cout <<
"========================================================================" << endl;
526 cout <<
" Example completed successfully!" << endl;
527 cout <<
"========================================================================" << endl;
Bidirectional mapping between two types.
A generic key-value mapping container with inverse operation support.
bool remove(const Key &key) noexcept
Removes the key-value pair with the given key.
DynList< ValueType > values() const
Gets all values in the mapping.
size_t size() const noexcept
Gets the number of key-value pairs in the mapping.
bool valid_key(const Key &key) const noexcept
Checks if a key exists in the mapping.
AHMapping< ValueType, Key > inverse() const
Creates a new mapping with keys and values swapped.
bool contains_value(const ValueType &value) const
Checks if the mapping contains a specific value.
void insert(const Key &key, const ValueType &value)
Inserts or updates a key-value pair in the mapping.
void for_each(F f) const
Applies a function to each key-value pair.
DynList< Key > keys() const
Gets all keys in the mapping.
size_t size() const noexcept
Return the current dimension of array.
T & append()
Allocate a new entry to the end of array.
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_cos_function > > cos(const __gmp_expr< T, U > &expr)
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_sqrt_function > > sqrt(const __gmp_expr< T, U > &expr)
void demo_city_coordinates()
void demo_variadic_constructor()
void demo_department_codes()
void print_subheader(const string &subtitle)
void demo_encoding_decoding()
void demo_modifiable_mapping()
void demo_numeric_mapping()
Main namespace for Aleph-w library functions.
std::string code(Node *root)
Compute a string with the Lukasiewicz`s word of a tree.
Lazy and scalable dynamic array implementation.