21

我需要标准 GCC STL 地图容器的订单统计树。

我查了一下,有一种叫做 PBDS 的东西。基于策略的数据结构。我也不清楚这种用法。

谁能告诉我如何将 STL 地图容器用于订单统计树?即使它只在 GNU G++ 上就足够了吗?

4

1 回答 1

23

这是作为订单统计树实现的基于 GNU 策略的 STL MAP 的示例(在 Linux gcc 4.6.1 上测试):

#include <iostream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef
tree<
  int,
  int,
  less<int>,
  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;
}

这是GNU Policy-Based Data Structures 概述的链接。这是其他tree_order_statistics 示例。我找不到关于基于策略的数据结构的良好参考,但您可以使用这些链接以及 PBDS 源。

于 2012-06-27T17:10:19.277 回答