Re: "two time periods with only an endpoint in common do not overlap" ???

From: Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>
To: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: "two time periods with only an endpoint in common do not overlap" ???
Date: 2021-10-16 08:31:56
Message-ID: 853c22fa-ab54-901f-d535-314965229c85@archidevsys.co.nz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 16/10/21 18:41, David G. Johnston wrote:
> On Friday, October 15, 2021, Ron <ronljohnsonjr(at)gmail(dot)com> wrote:
>
>
> Prima facie, if you were told "numbers in the range 0-10", would
> you really think, "ah, they *really* mean 0 through 9"?
>
>
> I would indeed default to both endpoints of the range being
> inclusive.  I also begin counting at one, not zero.  I’ve long gotten
> past being surprised when computer science and my defaults don’t
> agree.  Choices are made and documented and that works for me.
>
> As for this, documentation I never really gave the wording a second
> thought before, though I can definitely understand the complaint and
> like the somewhat wordier, but less linguistically challenging,
> phrasing the OP suggested (Boundary point, especially by itself, is
> not an improvement).
>
> David J.
>
The reason arrays generally start at zero and not one, is efficiency.

When indexes are zero based then the displacement in bytes from the
start address of x[n] is simply:
    startAddress + n * sizeOfElement

If the start of an array had the index of one, then you have subtract
one each time, so the displacement from the start address of x[n] now
becomes
    startAddress + (n - 1) * sizeOfElement

Half open intervals make life a lot simpler so it is the natural
default, to prevent intervals from having any numbers in common.

If you have 3 intervals spanning the range [0, 30), and you are only
dealing with integers then you can split the range as:
[0, 9]           0 <= x <= 9
[10, 19]      10 <= x <= 19
[20, 29]      10 <= x <= 29

But what if you are dealing with floats? The above arrangement would not
work, as 9.78 would not be in any interval, so you need half open
intervals, such as:
[0, 10)          0 <= x < 10
[10, 20)      10 <= x < 20
[20, 30)      10 <= x < 30
So you know what number each interval starts at, and every number in the
range is covered.

-Gavin

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Oleksandr Voytsekhovskyy 2021-10-16 10:50:31 Wrong sorting on docker image
Previous Message David G. Johnston 2021-10-16 05:41:58 Re: "two time periods with only an endpoint in common do not overlap" ???