File: rmq-example.cpp

package info (click to toggle)
libsdsl 2.1.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 3,980 kB
  • sloc: cpp: 42,286; makefile: 1,171; ansic: 318; sh: 201; python: 27
file content (37 lines) | stat: -rw-r--r-- 1,064 bytes parent folder | download | duplicates (18)
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
#include <iostream>
#include <sdsl/rmq_support.hpp>

using namespace sdsl;
using namespace std;


int main()
{
    rmq_succinct_sct<> rmq;
    {
        // initilaize int_vector object A
        int_vector<> A = {6,7,3,2,4,2,1,5,8,2};
        // output a
        cout << "A = " << A << endl;

        // generate range-minimum structure by passing
        // pointer to ordered array
        rmq = rmq_succinct_sct<>(&A);

        // calculate index of minimal element in a[0..a.size()-1]
        auto min_idx = rmq(0, A.size()-1);

        cout << "A[" << min_idx << "]=" << A[min_idx];
        cout << " is the samllest element in A[0.." << A.size()-1 << "]" << endl;

        // calculate index of minimal element in a[2..5]
        min_idx = rmq(2,5);

        cout << "A[" << min_idx << "]=" << A[min_idx];
        cout << " is the smallest element in A[2..5]" << endl;
    }
    // no A does not exist any more, queries can still be answered
    auto min_idx = rmq(1,5);
    cout << "A[" << min_idx << "] is the smallest in A[1..5]" << endl;
    return 0;
}