|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Comprehensive example demonstrating Aleph-w's AHMapping class. More...
#include <iostream>#include <iomanip>#include <string>#include <ah-mapping.H>#include <tpl_dynArray.H>Go to the source code of this file.
Functions | |
| void | print_header (const string &title) |
| void | print_subheader (const string &subtitle) |
| void | demo_department_codes () |
| void | demo_variadic_constructor () |
| void | demo_numeric_mapping () |
| void | demo_encoding_decoding () |
| void | demo_modifiable_mapping () |
| void | demo_city_coordinates () |
| int | main () |
Comprehensive example demonstrating Aleph-w's AHMapping class.
This example demonstrates AHMapping, a bidirectional key-value mapping container that provides efficient lookups in both directions. Unlike standard maps that only support forward lookup (key → value), AHMapping enables efficient reverse lookup (value → key) as well.
AHMapping is a specialized container for bidirectional mappings:
for_each and other functional opsmapping[key] → returns valuemapping.inverse()[value] → returns keyExamples use Colombian data for cultural relevance:
| Feature | std::map | AHMapping |
|---|---|---|
| Forward lookup | O(log n) | O(log n) |
| Reverse lookup | O(n) | O(log n) |
| Memory | O(n) | O(n) |
| Bidirectional | No | Yes |
Advantage: AHMapping provides efficient reverse lookup without maintaining a separate reverse map manually.
| Operation | Complexity | Notes |
|---|---|---|
| Insert | O(log n) | Updates both mappings |
| Forward lookup | O(log n) | Key → value |
| Reverse lookup | O(log n) | Value → key |
| Iteration | O(n) | All pairs |
| Size | O(1) | Number of pairs |
Definition in file mapping_example.C.
| void demo_city_coordinates | ( | ) |
Definition at line 447 of file mapping_example.C.
References Aleph::DynList< T >::append(), cos(), FunctionalMethods< Container, T >::for_each(), Aleph::DynList< T >::insert(), Aleph::maps(), print_header(), print_subheader(), Aleph::HTList::size(), and sqrt().
Referenced by main().
| void demo_department_codes | ( | ) |
Definition at line 173 of file mapping_example.C.
References Aleph::DynList< T >::append(), Aleph::code(), Aleph::DynList< T >::insert(), Aleph::maps(), print_header(), print_subheader(), and Aleph::HTList::size().
Referenced by main().
| void demo_encoding_decoding | ( | ) |
Definition at line 336 of file mapping_example.C.
References Aleph::DynList< T >::append(), Aleph::code(), Aleph::DynList< T >::insert(), Aleph::maps(), print_header(), print_subheader(), and Aleph::HTList::size().
Referenced by main().
| void demo_modifiable_mapping | ( | ) |
Definition at line 393 of file mapping_example.C.
References FunctionalMethods< Container, T >::for_each(), Aleph::maps(), print_header(), print_subheader(), Aleph::DynList< T >::remove(), and Aleph::HTList::size().
Referenced by main().
| void demo_numeric_mapping | ( | ) |
Definition at line 289 of file mapping_example.C.
References Aleph::AHMapping< Key, ValueType >::contains_value(), Aleph::AHMapping< Key, ValueType >::for_each(), Aleph::AHMapping< Key, ValueType >::insert(), Aleph::maps(), print_header(), print_subheader(), and Aleph::AHMapping< Key, ValueType >::values().
Referenced by main().
| void demo_variadic_constructor | ( | ) |
Definition at line 250 of file mapping_example.C.
References FunctionalMethods< Container, T >::for_each(), GenericItems< Container, T >::keys(), Aleph::maps(), print_header(), print_subheader(), and Aleph::HTList::size().
Referenced by main().
| int main | ( | ) |
Definition at line 509 of file mapping_example.C.
References demo_city_coordinates(), demo_department_codes(), demo_encoding_decoding(), demo_modifiable_mapping(), demo_numeric_mapping(), demo_variadic_constructor(), and Aleph::maps().
| void print_header | ( | const string & | title | ) |
Definition at line 155 of file mapping_example.C.
References Aleph::maps().
| void print_subheader | ( | const string & | subtitle | ) |
Definition at line 163 of file mapping_example.C.
References FunctionalMethods< Container, T >::length(), and Aleph::maps().
Referenced by demo_city_coordinates(), demo_department_codes(), demo_encoding_decoding(), demo_modifiable_mapping(), demo_numeric_mapping(), and demo_variadic_constructor().