File: btree.cc

package info (click to toggle)
parallel-hashmap 1.4.1%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,872 kB
  • sloc: cpp: 20,492; ansic: 1,114; python: 492; makefile: 85; haskell: 56; perl: 43; sh: 23
file content (49 lines) | stat: -rw-r--r-- 1,344 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include "btree_fwd.h"
#include <parallel_hashmap/btree.h>

int main()
{ 
    // initialise map with some values using an initializer_list
    phmap::btree_map<std::string, int> map = 
        { { "John", 35 },
          { "Jane", 32 },
          { "Joe",  30 },
        };

    // add a couple more values using operator[]()
    map["lucy"]  = 18;
    map["Andre"] = 20;

    auto it = map.find("Joe");
    map.erase(it);

    map.insert(std::make_pair("Alex", 16));
    map.emplace("Emily", 18); // emplace uses pair template constructor
    
    for (auto& p: map)
        std::cout << p.first <<  ", " << p.second << '\n';

    IntString map2; // IntString is declared in btree_fwd.h

    map2.emplace(std::piecewise_construct, std::forward_as_tuple(0), std::forward_as_tuple(10, 'c'));
    map2.try_emplace(1, 10, 'a'); // phmap::btree_map supports c++17 API

    for (auto& p: map2)
        std::cout << p.first <<  ", " << p.second << '\n';

    // create a btree_set of tuples
    using X = std::tuple<float, std::string>;
    phmap::btree_set<X> set;
 
    for (int i=0; i<10; ++i)
        set.insert(X((float)i, std::to_string(i)));
    set.emplace(15.0f, "15");

    set.erase(X(1.0f, "1"));
    
    for (auto& e: set)
        std::cout << std::get<0>(e) << ", \"" << std::get<1>(e) << "\" \n";

    return 0;
}