BitMagic-C++: xsample02.cpp File Reference

BitMagic-C++

Typedefs | Functions | Variables
xsample02.cpp File Reference

Example: sparse_vector<> used for counting sort / historgam construction. More...

`#include <iostream>`
`#include <memory>`
`#include <map>`
`#include <vector>`
`#include <chrono>`
`#include <algorithm>`
`#include <random>`
`#include <stdexcept>`
`#include <future>`
`#include <thread>`
`#include "bm.h"`
`#include "bmtimer.h"`
`#include "bmsparsevec.h"`
Include dependency graph for xsample02.cpp:

Go to the source code of this file.

## Typedefs
typedef bm::sparse_vector< unsigned, bm::bvector<> > | sparse_vector_u32
typedef std::map< unsigned, unsigned > | map_u32

## Functions
std::mt19937 | gen (rand_dev())
std::uniform_int_distribution | rand_dis (1, value_max)
static void | sort_map (map_u32 &hmap, const std::vector< unsigned > &vin)
static void | counting_sort_naive (sparse_vector_u32 &sv_out, const std::vector< unsigned > &vin)
static void | counting_sort (sparse_vector_u32 &sv_out, const std::vector< unsigned > &vin)
unsigned | counting_sort_subbatch (sparse_vector_u32 *sv_out, const std::vector< unsigned > *vin)
static void | counting_sort_parallel (sparse_vector_u32 &sv_out, const std::vector< unsigned > &vin)
static void | print_sorted (const sparse_vector_u32 &sv)
static void | print_sorted (const map_u32 &hmap)
static void | build_histogram (sparse_vector_u32 &sv_out, const std::vector< unsigned > &vin)
int | main (void)

## Variables
const unsigned | value_max = 1250000
const unsigned | test_size = 250000000
std::random_device | rand_dev
bm::chrono_taker::duration_map_type | timing_map

## Detailed Description

Example: sparse_vector<> used for counting sort / historgam construction.

Definition in file xsample02.cpp.

## Typedef Documentation

## ◆ map_u32

typedef std::map<unsigned, unsigned> map_u32

Examples
  xsample02.cpp.

Definition at line 67 of file xsample02.cpp.

## ◆ sparse_vector_u32

typedef bm::sparse_vector<unsigned, bm::bvector<> > sparse_vector_u32

Examples
  xsample02.cpp.

Definition at line 66 of file xsample02.cpp.

## Function Documentation

## ◆ build_histogram()

static void build_histogram | ( | sparse_vector_u32 & | sv_out,
|  | const std::vector< unsigned > & | vin
| ) |  |
| static

Examples
  xsample02.cpp.

Definition at line 211 of file xsample02.cpp.

References bm::sparse_vector< Val, BV >::set().

Referenced by main().

## ◆ counting_sort()

static void counting_sort | ( | sparse_vector_u32 & | sv_out,
|  | const std::vector< unsigned > & | vin
| ) |  |
| static

Examples
  xsample02.cpp.

Definition at line 116 of file xsample02.cpp.

References bm::sparse_vector< Val, BV >::inc().

Referenced by main().

## ◆ counting_sort_naive()

static void counting_sort_naive | ( | sparse_vector_u32 & | sv_out,
|  | const std::vector< unsigned > & | vin
| ) |  |
| static

Examples
  xsample02.cpp.

Definition at line 96 of file xsample02.cpp.

References bm::sparse_vector< Val, BV >::get(), and bm::sparse_vector< Val, BV >::set().

Referenced by main().

## ◆ counting_sort_parallel()

static void counting_sort_parallel | ( | sparse_vector_u32 & | sv_out,
|  | const std::vector< unsigned > & | vin
| ) |  |
| static

Examples
  xsample02.cpp.

Definition at line 145 of file xsample02.cpp.

References counting_sort_subbatch(), bm::sparse_vector< Val, BV >::inc(), bm::sparse_vector< Val, BV >::merge(), and bm::use_null.

Referenced by main().

## ◆ counting_sort_subbatch()

unsigned counting_sort_subbatch | ( | sparse_vector_u32 * | sv_out,
|  | const std::vector< unsigned > * | vin
| ) |  |
| inline

Examples
  xsample02.cpp.

Definition at line 128 of file xsample02.cpp.

References bm::sparse_vector< Val, BV >::inc().

Referenced by counting_sort_parallel().

## ◆ gen()

std::mt19937 gen | ( | rand_dev() |  | ) |

Examples
  xsample02.cpp.

Referenced by main().

## ◆ main()

int main | ( | void |  | ) |

Examples
  xsample02.cpp.

Definition at line 238 of file xsample02.cpp.

References BM_DECLARE_TEMP_BLOCK, build_histogram(), counting_sort(), counting_sort_naive(), counting_sort_parallel(), bm::chrono_taker::ct_ops_per_sec, bm::sparse_vector< Val, BV >::equal(), gen(), bm::bvector<>::opt_compress, bm::sparse_vector< Val, BV >::optimize(), bm::chrono_taker::print_duration_map(), print_sorted(), rand_dis(), sort_map(), test_size, timing_map, and bm::use_null.

## ◆ print_sorted() [1/2]

static void print_sorted | ( | const map_u32 & | hmap | ) |
| static

Definition at line 190 of file xsample02.cpp.

## ◆ print_sorted() [2/2]

static void print_sorted | ( | const sparse_vector_u32 & | sv | ) |
| static

Examples
  xsample02.cpp.

Definition at line 170 of file xsample02.cpp.

References bm::bvector<>::enumerator, bm::bvector< Alloc >::first(), bm::sparse_vector< Val, BV >::get(), and bm::base_sparse_vector< Val, BV, MAX_SIZE >::get_null_bvector().

Referenced by main().

## ◆ rand_dis()

std::uniform_int_distribution rand_dis | ( | 1 | ,
|  | value_max |
| ) |  |

Examples
  xsample02.cpp.

Referenced by main().

## ◆ sort_map()

static void sort_map | ( | map_u32 & | hmap,
|  | const std::vector< unsigned > & | vin
| ) |  |
| static

Examples
  xsample02.cpp.

Definition at line 79 of file xsample02.cpp.

Referenced by main().

## Variable Documentation

## ◆ rand_dev

std::random_device rand_dev

Examples
  xsample02.cpp.

Definition at line 61 of file xsample02.cpp.

## ◆ test_size

const unsigned test_size = 250000000

Examples
  xsample02.cpp.

Definition at line 55 of file xsample02.cpp.

Referenced by main().

## ◆ timing_map

bm::chrono_taker::duration_map_type timing_map

Examples
  xsample02.cpp.

Definition at line 71 of file xsample02.cpp.

Referenced by main().

## ◆ value_max

const unsigned value_max = 1250000

Examples
  xsample02.cpp.

Definition at line 54 of file xsample02.cpp.