Order Statistic Tree in C++

后端 未结 1 1836
无人及你
无人及你 2020-11-30 10:24

I need an order statistic tree for standard GCC STL map containers.

I checked and there is something known as PBDS. Policy based data structures. That usage is also

1条回答
  •  北海茫月
    2020-11-30 10:38

    Here is the example of GNU Policy-Based STL MAP implemented as order statistic tree (tested on Linux gcc 4.6.1):

    #include 
    #include 
    #include 
    
    using namespace std;
    using namespace __gnu_pbds;
    
    typedef
    tree<
      int,
      int,
      less,
      rb_tree_tag,
      tree_order_statistics_node_update>
    map_t;
    
    int main()
    {
      map_t s;
      s.insert(make_pair(12, 1012));
      s.insert(make_pair(505, 1505));
      s.insert(make_pair(30, 1030));
      cout << s.find_by_order(1)->second << '\n';
      return 0;
    }
    

    Here is a link to the overview of GNU Policy-Based Data Structures. Here is other tree_order_statistics example. I cannot find a good reference for Policy-Based Data Structures, but you can use these links as well as PBDS sources.

    0 讨论(0)
提交回复
热议问题