remove duplicate range of threshold

Hi all.

I have these points
t1 - t2 = say 0 to 13
t3 - t4 = say 20 to 30
t5 - t6 = say 0 to 13
t7 - t8 s= say 20 to 30
t9 - t10 = say 70 to 80

these are threshold points
i want to remove duplication and even if null points like 0 - 0 appear then ignore it.
like i should get ponlt 0 to 13, 20 to 30 , 70 to 80

How can i do it in easy way with less computation?
One way is each threshold range with the next threshold range.
and it would require so many if test conditions,.
Please lead me to easy way. thanks
It is interesting what about such points

0 - 13
and
0 - 17

?
ah no .. i have 5 threshold ranges .

say Threshold one is : 0 to 13
threshold two range is: 20 to 25
threshold three range is : 0 to 13
threshold four range is: 20 to 25
threshold five is : 170 to 179

Now, i want to remove those threshold range if it is duplicated,.
after that i should get only three threshold ranges

0 to 13
20 to 25
170 to 179

This time .. i changed values .
Please help me to make it easy in less computation. thanks
I think that the simplest way is to sort thresholds and apply algorithm std::unique.
Last edited on
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
#include <vector>
#include <utility>
#include <algorithm>
#include <iostream>
 
int main()
{
    std::vector<std::pair<int, int>> v = 
    { 
        std::pair<int, int>( 0, 13 ),
        std::pair<int, int>( 20, 25 ),
        std::pair<int, int>( 0, 13 ),
        std::pair<int, int>( 20, 25 ),
        std::pair<int, int>( 170, 179 )
    };
    
    for ( std::pair<int, int> p : v )
    {
        std::cout << '<' << p.first << ',' << p.second << ">\n";
    }
    std::cout << std::endl;
    
    std::sort( v.begin(), v.end() );
    v.erase( std::unique( v.begin(), v.end() ), v.end() );
    
    for ( std::pair<int, int> p : v )
    {
        std::cout << '<' << p.first << ',' << p.second << ">\n";
    }
    std::cout << std::endl;
}



The output is

<0,13>
<20,25>
<0,13>
<20,25>
<170,179>

<0,13>
<20,25>
<170,179>

ahhan i see. thanks ,.
how about if i would have threshold range <0 , 0>
then i have to remove that threshold range from the list.
Yes, you should at first remove all such pairs with using standard algorithm std::remove_if (if also you need to remove such pairs as <1,1}, <25,25> and so on) or std::remove if you need to remove only pairs <0,0>
Last edited on
For example

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 <vector>
#include <utility>
#include <algorithm>
#include <iostream>
 
int main()
{
    std::vector<std::pair<int, int>> v = 
    { 
        std::pair<int, int>( 0, 13 ),
        std::pair<int, int>( 20, 25 ),
        std::pair<int, int>( 0, 13 ),
        std::pair<int, int>( 20, 25 ),
        std::pair<int, int>( 30, 30 ),
        std::pair<int, int>( 170, 179 )
    };
    
    for ( std::pair<int, int> p : v )
    {
        std::cout << '<' << p.first << ',' << p.second << ">\n";
    }
    std::cout << std::endl;
    
    auto it = std::remove_if( v.begin(), v.end(), 
                              []( const std::pair<int, int> &p ) 
                              { 
                                  return ( p.first == p.second ); 
                              } );
    std::sort( v.begin(), it );
    v.erase( std::unique( v.begin(), it ), v.end() );
    
    for ( std::pair<int, int> p : v )
    {
        std::cout << '<' << p.first << ',' << p.second << ">\n";
    }
    std::cout << std::endl;
}
Topic archived. No new replies allowed.