pb_ds learning

  pb_ds commonly known as flat-panel TVs (bushi) is a GNU-C ++ comes with c ++ extension library that implements a number of data structures.

Because it is a separate extension library to write 

using namespace __gnu_pbds;

 

Here are three main data structures.

1. hash table


head File

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds

Two definitions of way

cc_hash_table < String , int > MP1; // fastener method 
gp_hash_table < String , int > MP2; // identify the process (on a faster)

PS: two kinds of hash functions more efficiently than the map, and the map method and using the same

2. heap

head File:

As with normal priority queue usage

#include<ext/pb_ds/priority_queue.hpp>
using namespace __gnu_pbds;
__gnu_pbds::priority_queue<int>q;
__gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag>pq;//最快
__gnu_pbds::priority_queue<int,greater<int>,binary_heap_tag>pq;
__gnu_pbds::priority_queue<int,greater<int>,binomial_heap_tag>pq;
__gnu_pbds::priority_queue<int,greater<int>,rc_binomial_heap_tag>pq;
__gnu_pbds::priority_queue<int,greater<int>,thin_heap_tag>pq;
__gnu_pbds::priority_queue<int,greater<int>>pq;

Heap pb_ds library offers five tag, are  pairing_heap_tag ,  binary_heap_tag , binomial_heap_tag , rc_binomial_heap_tag , thin_heap_tag . Because of the same name to add  __gnu_pbds ::  

Basic operation:

the Push ()   // returns an iterator 
Top ()   // with STL 
size ()   // with STL 
empty () // with STL 
the Clear ()   // with STL 
POP ()   // with STL 
the Join (priority_queue & OTHER)   // merge the two stacks, other will be cleared 
Split (Pred Forte PRD, & OTHER the priority_queue)   // separating two stacks 
modify (point_iterator IT, const Key)   // modify the value of a node

Priority queue iterator:

__gnu_pbd::priority_queue<int>::point_iterator it;

 

Guess you like

Origin www.cnblogs.com/jiqimin/p/11226809.html
Recommended