473,320 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

set_intersection of two interval sets

Hi,

I have the following definition for a closed-open interval (see
http://mathworld.wolfram.com/Interval.html). I have two sets of
intervals, say A and B. Any two intervals in A (or B) have no overlap,
and they are sorted.

std::vector<closed_open_interval<double A;
std::vector<closed_open_interval<double B;

'set_intersection' is the standard algorithm to compute the set
intersection. I'm wondering if there is any easy way to compute the
intersection of A and B using that function.

Thanks,
Peng

#ifndef ANALYTICAL_CLOSED_OPEN_INTERVAL_H
#define ANALYTICAL_CLOSED_OPEN_INTERVAL_H

#include <cassert>

namespace analytical
{

template <typename T>
class closed_open_interval {
public:
closed_open_interval(T a, T b) : _a(a),_b(b) { // _a is in the
interval, but _b is not.
assert(a < b);
}
T the_a() const { return _a; }
T the_b() const { return _b; }
bool operator<(closed_open_interval &that) const {
return _b <= that._a;
}
private:
T _a, _b;
};

}

#endif

Jul 7 '07 #1
1 2482
On 7 Jul, 21:25, "PengYu...@gmail.com" <PengYu...@gmail.comwrote:
Hi,

I have the following definition for a closed-open interval (seehttp://mathworld.wolfram.com/Interval.html). I have two sets of
intervals, say A and B. Any two intervals in A (or B) have no overlap,
and they are sorted.

std::vector<closed_open_interval<double A;
std::vector<closed_open_interval<double B;

'set_intersection' is the standard algorithm to compute the set
intersection. I'm wondering if there is any easy way to compute the
intersection of A and B using that function.
there is not a standard algorithm for that.
Thanks,
Peng

#ifndef ANALYTICAL_CLOSED_OPEN_INTERVAL_H
#define ANALYTICAL_CLOSED_OPEN_INTERVAL_H

#include <cassert>

namespace analytical
{

template <typename T>
instances of T are obviously some iterators, but what do
they iterate over. are intervals in A iterators in one
container and intervals in B iterators in other container
or do they belong to the same container?
class closed_open_interval {
public:
closed_open_interval(T a, T b) : _a(a),_b(b) { // _a is in the
interval, but _b is not.
I presume that all elements [_a, _b) are sorted
as well.
assert(a < b);
}
bool operator<(closed_open_interval &that) const {
return _b <= that._a;
if the intervals are not overlapped than surely comparing
the inclusive iterators is sufficient, like
return _a<that._a;
}
private:
T _a, _b;
};

}

#endif
I suppose you can make union of all elements that intervals
in A point to and another one of the same for elements in B
and make intersection of the two. Is that what you want?

regards

DS

Jul 9 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Kiteman \(Canada\) | last post by:
I have a Reminder feature that I am building into a VB 6.0 program that will (when enabled) remind the user to perform some action. I have a slider where the person can select for the reminder...
27
by: Steven T. Hatton | last post by:
I've finally gotten around to reading Accelerated C++ by Andrew Koenig and Barbara Moo. There's a lot of good stuff in what I've read so far. Even though it is _very_ basic, they present some...
7
by: Davy | last post by:
Hi all, I want to use set_intersection, and the compiler passed with a warning. But the program hang on when it enter set_intersection(), why? And how can I insert element to set by insert();...
2
by: harris.pc | last post by:
Hi, Can someone please explain to me WHY the standard does not allow the input range and the output range to overlap for set_intersection? I can't see why I can't do this (note sorted vectors,...
4
by: Giulio Veronesi | last post by:
Hi, set<int> s1, s2, s3; .... set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(), ???); What do I put at place of ??? to get in s3 the intersection between s1 and s2? Thanks in...
3
by: Generic Usenet Account | last post by:
Hi, I have some questions regarding STL set intersection. As per the STL reference manual (http://www.hpl.hp.com/techreports/95/HPL-95-11.pdf), the signatures of the set_intersection...
1
by: Ed Smith | last post by:
The Postgres INTERVAL literal is not compliant with the ANSI 2003 SQL Spec. Here's the Postgres way: # select INTERVAL '45 DAY'; interval ---------- 45 days (1 row) The spec. says
0
by: Ian E. Morgan | last post by:
After being frustrated with the inflexible output of intervals, I've written a pl/pgsql function to do what I want, and hopefully some other people might find it useful. Output is a string that...
10
by: hazz | last post by:
Is it possible to have the timer interval in a window's service be derived from an app.config setting? When I implemented one a while back I was forced to hard code the value because it wasn't...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.