Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
dynmap_example.C File Reference

DynMapTree (ordered map) with multiple tree backends + demo suite and benchmark. More...

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <chrono>
#include <random>
#include <tpl_dynMapTree.H>
#include <tclap/CmdLine.h>
Include dependency graph for dynmap_example.C:

Go to the source code of this file.

Functions

void demo_basic_operations ()
 Demonstrate basic map operations.
 
void demo_tree_backends ()
 Demonstrate different tree backends.
 
void demo_word_frequency ()
 Practical example: Word frequency counter.
 
void demo_config_store ()
 Practical example: Configuration store.
 
void demo_functional ()
 Functional programming with maps.
 
void demo_performance (int n)
 Performance comparison of backends.
 
int main (int argc, char *argv[])
 

Detailed Description

DynMapTree (ordered map) with multiple tree backends + demo suite and benchmark.

Overview

This example demonstrates Aleph-w's DynMapTree, an ordered key→value map implemented on top of a configurable tree backend.

The program is organized as a set of small demos:

  • basic map operations (insert, operator[], search, remove, iteration)
  • comparing several tree backends
  • word-frequency map example
  • config-store example
  • functional-style helpers
  • a performance comparison (controlled by --count)

Data model used by this example

  • Typical demo types: DynMapTree<string, int> and DynMapTree<int, int, Backend>
  • Keys are ordered by Aleph::less<Key> by default.

Usage / CLI

This example uses TCLAP. Options:

  • --count / -n <int>: number of elements used by the performance demo (default: 10000).
  • --basic / -b: run only the basic-operations demo.
  • --trees / -t: run only the tree-backends demo.
  • --words / -w: run only the word-frequency demo.
  • --config / -c: run only the configuration-store demo.
  • --functional / -f: run only the functional-programming demo.
  • --performance / -p: run only the performance demo.
  • --all / -a: run all demos.
  • --help: show help.

Behavior:

  • If you pass no demo-selection flags, the program defaults to running all demos.
# Run all demos (default)
./dynmap_example
# Run a subset
./dynmap_example --basic --trees
# Performance demo with custom size
./dynmap_example --performance --count 200000
# Show help
./dynmap_example --help

Complexity

Let n be the number of stored keys.

  • insert/search/remove: O(log n) expected/typical for balanced backends.
  • ordered iteration: O(n).

Pitfalls and edge cases

  • operator[] inserts a default value if the key does not exist.
  • Backend choice matters for workloads with strong locality (splay) vs predictable worst-case bounds (AVL/RB).

References / see also

Author
Leandro Rabindranath León

Definition in file dynmap_example.C.

Function Documentation

◆ demo_basic_operations()

void demo_basic_operations ( )

◆ demo_config_store()

void demo_config_store ( )

Practical example: Configuration store.

Definition at line 282 of file dynmap_example.C.

References LocateFunctions< Container, Type >::get_it(), Aleph::maps(), and Aleph::DynMapTree< Key, Data, Tree, Compare >::search().

Referenced by main().

◆ demo_functional()

◆ demo_performance()

void demo_performance ( int  n)

Performance comparison of backends.

Definition at line 383 of file dynmap_example.C.

References Aleph::maps().

◆ demo_tree_backends()

void demo_tree_backends ( )

Demonstrate different tree backends.

Definition at line 187 of file dynmap_example.C.

References Aleph::maps(), and Aleph::HTList::size().

Referenced by main().

◆ demo_word_frequency()

void demo_word_frequency ( )

Practical example: Word frequency counter.

Definition at line 244 of file dynmap_example.C.

References LocateFunctions< Container, Type >::get_it(), Aleph::maps(), and Aleph::HTList::size().

Referenced by main().

◆ main()

int main ( int  argc,
char *  argv[] 
)