473,385 Members | 1,427 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,385 software developers and data experts.

Storing Intervals or Ranges

Hi,

some time ago I've read a paper that advised to store intervals on discrete
values in the format [a;b[. One starts with the first element and finishes
with one past the last one.

However I do not remember the author, title or link of the paper. Does
anyone remember it?

Greetings
Christoph Bartoschek
Apr 25 '07 #1
9 2578
Christoph Bartoschek wrote:
Hi,

some time ago I've read a paper that advised to store intervals on discrete
values in the format [a;b[. One starts with the first element and finishes
with one past the last one.

However I do not remember the author, title or link of the paper. Does
anyone remember it?
This is exactly how C++ standard algorithms work.
Apr 25 '07 #2
red floyd wrote:
This is exactly how C++ standard algorithms work.
Yes, but the paper gave some rationale why this is better than using [a;b]
or other schemes.

Christoph
Apr 25 '07 #3
Christoph Bartoschek wrote:
Hi,

some time ago I've read a paper that advised to store intervals on discrete
values in the format [a;b[. One starts with the first element and finishes
with one past the last one.
Such an interval is known as a "half-open" interval. Notational
nitpick, the general format for such a range is [a, b).

Not sure of the location of the paper, but the rationale is that
one-past-the-end provides a not present indicator, much like a NULL
pointer would.

Apr 25 '07 #4
Christoph Bartoschek wrote:
Hi,

some time ago I've read a paper that advised to store intervals on discrete
values in the format [a;b[. One starts with the first element and finishes
with one past the last one.

However I do not remember the author, title or link of the paper. Does
anyone remember it?
Google came up with this: http://www.siliconbrain.com/ranges.htm
Apr 25 '07 #5
red floyd wrote:
Such an interval is known as a "half-open" interval. Notational
nitpick, the general format for such a range is [a, b).
I used [a; b[ because this is the format we used in school (Germany). Forgot
to use the more international format.
Google came up with this: http://www.siliconbrain.com/ranges.htm
This is not the paper I remember. But thanks for the link.

Christoph
Apr 25 '07 #6
* Christoph Bartoschek:
red floyd wrote:
>This is exactly how C++ standard algorithms work.

Yes, but the paper gave some rationale why this is better than using [a;b]
or other schemes.
The number of elements in the range is onePastLast-first. With zero
elements, an empty range, onePastLast == first. Which is very
convenient for pointers or more general iterators.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Apr 25 '07 #7
On Apr 25, 5:40 pm, red floyd <no.s...@here.dudewrote:
Christoph Bartoschek wrote:
some time ago I've read a paper that advised to store intervals on discrete
values in the format [a;b[. One starts with the first element and finishes
with one past the last one.
Such an interval is known as a "half-open" interval. Notational
nitpick, the general format for such a range is [a, b).
Which doesn't work for decimal numbers, in localities where the
decimal separator is a comma. I'll use "[a,b)" if I know that
I'm only addressing the Anglo-Saxon world, "[a;b[" for the rest
of the world. (Note that where I live, a complex is represented
as "(r;i)", and not "(r,i)", as well.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Apr 26 '07 #8
"Christoph Bartoschek" <ba********@gmx.dewrote in message
news:a8************@barney.wesseling.pontohonk.de. ..
some time ago I've read a paper that advised to store intervals on
discrete
values in the format [a;b[. One starts with the first element and finishes
with one past the last one.
There are lots of reasons. Here is one that I personally consider to be
conclusive.

If you represent a range by its first and last elements (symmetric ranges),
then an empty range is an anomaly: You need to find way to represent not
just one but two distinct positions that do not correspond to any element.

If you represent a range by its first and one past its last elements
(asymmetric), then you always need a way to represent a position that
doesn't correspond to any element, but the difficulty in doing so is the
same regardless of the number of elements.

Moreover, assymetric ranges have the nice property that begin<=end at all
times, and begin==end if and only if the range is empty. With symmetric
ranges, begin==end if and only if the range has precisely one element, and
begin>end if the range is empty. This latter behavior is much less useful
if you are using iterators that support only == and != comparisons.

If this argument doesn't convince you, here are some others:

If you are using integer indices, you can use unsigned values to represent
an asymmetric range. You need signed values to represent a symmetric
range--to cater to the specific case of [0,-1] which is needed to represent
an empty range.

If you are using pointers to array elements, you have a problem in C or C++
representing an empty symmetric range because you are not generally allowed
to compute the address that precedes an array.
Apr 27 '07 #9
I am already convinced that one should represent ranges as it is done in the
standard library. However this is my concrete case:

How to store rectangles in the integer plane?

A rectangle can be represented with the following struct:

static const int XDIM = 0;
static const int YDIM = 1;

struct Rectangle {
int min[2];
int max[2];
};

The question is how to interpret the ranges in x-dimension and y-dimension.
Everyone I asked assumed that the point (max[XDIM], max{YDIM]) is included
in the rectangle. But this has the same drawbacks as with one dimensional
ranges. For example the rectangles

{{0, 0}, {3, 3}}
{{4, 0}, {6, 3]]

cover the whole area from (0, 0) to (6, 3), although there seems to be a
hole from (3, 0) to (4, 3). Several algorithms (union, removing
overlaps, ...) are harder to implement with this scheme.

But should one use half-open ranges against the intuition?

Christoph
Apr 28 '07 #10

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

Similar topics

3
by: Matt Saunders | last post by:
There's lots of ways of representing a hierarchical data structure in a relational database. These range from the trivially easy to implement in PHP (adjacency list; each node has an ID and a...
2
by: Ben O'Steen | last post by:
Scenario: ========= Using PyGame in particular, I am trying to write an application that will run a scripted timeline of events, eg at 5.5 seconds, play xxx.mp3 and put the image of a ball on...
1
by: Mark Smith | last post by:
Hi Group, Are there any examples of class for storing fixed width number strings such as phone number and social security numbers. This class would do thing like valid that the number is all...
67
by: PC Datasheet | last post by:
Transaction data is given with date ranges: Beginning End 4/1/06 4/4/06 4/7/06 4/11/06 4/14/06 4/17/06 4/18/06 4/21/06 426/06 ...
5
by: toton | last post by:
Hi, I have a deque of Point class,. Point class have two fields x, and y. Now I want another class Character should point to a portion of the deque, and allow iteration only on the portion. Thus...
6
by: Lint Radley | last post by:
Hi Everyone, I need an opinion here on storing data for a program I am working on the processes DICOM images. Essentially, my program stores 25-45 (it varies depending on the user) ranges of...
3
by: Snedker | last post by:
Hi there, I really need some input of how to approach my little assignment. A customer wants to exclude all US IP-ranges from accessing part of his website. From...
1
by: lenygold via DBMonster.com | last post by:
I found this query on older thread and i can not uderstand output interval pairs: How to find min and max values in date intervals: -------------------------------------------------- Input:...
7
by: guido | last post by:
Hi, I'm looking for a container class that can map whole ranges of keys to objects - something like std::map, but not only for individual values for the key, but for whole ranges. Example: I...
1
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
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.