Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Uncompensated overtime? Just Say No.


devel / comp.theory / Re: Implementing a two-way Turing Machine tape as an improvement to std::deque

SubjectAuthor
* Implementing a two-way Turing Machine tape as an improvement toolcott
+* Implementing a two-way Turing Machine tape as an improvement toMr Flibble
|`* Implementing a two-way Turing Machine tape as an improvement toolcott
| `* Implementing a two-way Turing Machine tape as an improvement toMr Flibble
|  `* Implementing a two-way Turing Machine tape as an improvement toolcott
|   `* Implementing a two-way Turing Machine tape as an improvement toMr Flibble
|    `* Implementing a two-way Turing Machine tape as an improvement toolcott
|     `* Implementing a two-way Turing Machine tape as an improvement toMr Flibble
|      `* Implementing a two-way Turing Machine tape as an improvement toolcott
|       `* Implementing a two-way Turing Machine tape as an improvement toMr Flibble
|        `* Implementing a two-way Turing Machine tape as an improvement toolcott
|         `* Implementing a two-way Turing Machine tape as an improvement to std::dequeMr Flibble
|          +- Implementing a two-way Turing Machine tape as an improvement totth
|          `* Implementing a two-way Turing Machine tape as an improvement toolcott
|           `* Implementing a two-way Turing Machine tape as an improvement toMr Flibble
|            `- Implementing a two-way Turing Machine tape as an improvement toChris M. Thomasson
+* Implementing a two-way Turing Machine tape as an improvement to std::dequeRichard Damon
|`- Implementing a two-way Turing Machine tape as an improvement toolcott
`* Implementing a two-way Turing Machine tape as an improvement to std::dequeBen
 `* Implementing a two-way Turing Machine tape as an improvement toolcott
  +* Implementing a two-way Turing Machine tape as an improvement toMr Flibble
  |`* Implementing a two-way Turing Machine tape as an improvement toolcott
  | `* Implementing a two-way Turing Machine tape as an improvement to std::dequeMr Flibble
  |  `* Implementing a two-way Turing Machine tape as an improvement toolcott
  |   `* Implementing a two-way Turing Machine tape as an improvement toMr Flibble
  |    `- Implementing a two-way Turing Machine tape as an improvement toolcott
  `* Implementing a two-way Turing Machine tape as an improvement to std::dequeBen
   `* Implementing a two-way Turing Machine tape as an improvement toolcott
    +- Implementing a two-way Turing Machine tape as an improvement toPython
    `* Implementing a two-way Turing Machine tape as an improvement to std::dequeBen
     `* Implementing a two-way Turing Machine tape as an improvement toolcott
      +- Implementing a two-way Turing Machine tape as an improvement to std::dequeRichard Damon
      `* Implementing a two-way Turing Machine tape as an improvement to std::dequeBen
       `* Implementing a two-way Turing Machine tape as an improvement toolcott
        `* Implementing a two-way Turing Machine tape as an improvement to std::dequeBen
         `- Implementing a two-way Turing Machine tape as an improvement toolcott

Pages:12
Implementing a two-way Turing Machine tape as an improvement to std::deque

<cNWdnXqV1cXzEuD_nZ2dnUU7_8zNnZ2d@giganews.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=32222&group=comp.theory#32222

  copy link   Newsgroups: comp.theory comp.ai.philosophy comp.lang.c comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!2.eu.feeder.erje.net!feeder.erje.net!border1.nntp.dca1.giganews.com!nntp.giganews.com!buffer1.nntp.dca1.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Thu, 12 May 2022 17:51:26 -0500
Date: Thu, 12 May 2022 17:51:25 -0500
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Newsgroups: comp.theory,comp.ai.philosophy,comp.lang.c,comp.lang.c++
Content-Language: en-US
From: NoO...@NoWhere.com (olcott)
Subject: Implementing a two-way Turing Machine tape as an improvement to
std::deque
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <cNWdnXqV1cXzEuD_nZ2dnUU7_8zNnZ2d@giganews.com>
Lines: 73
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-AIJS7dEXgZRLmh/gp8WXPQkzpku47w4dclkYOqwMxc5biHF6VLIHTP01dVtctQ2BJpR4PrW2e2fhG+K!VvO74/p1LFPxAWFEAquTzqUyd02r963BbT1o9iel0e32ZO9OZUGNRFfT9hn54lvIRzLTjRXbons=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 3123
 by: olcott - Thu, 12 May 2022 22:51 UTC

C/C++ people please critique this as the basis for an improvement to
std::deque. It seems to have the key functionality of std::deque and
does it much more simply while saving time and space.
https://www.cplusplus.com/reference/deque/deque/

#define tape_element unsigned char

class Tape_Type
{ private:
int Tape_Head = 0; // Can be negative
std::vector<tape_element> Left; // Stores left expansion
std::vector<tape_element> Right; // Stores right expansion
tape_element & operator[](int index);

public:
void move_left(); // Tape_Head--; Left.push_back(0); as needed
void move_right(); // Tape_Head++; Left.push_back(0); as needed
void Write(tape_element Y){ this->operator[](Tape_Head) = Y; };
tape_element Read() { return this->operator[](Tape_Head); };
Tape_Type(){ Right.push_back('_'); } // constructor
void Output();
};

tape_element& Tape_Type::operator[](int index)
{ if (index > 0)
return Right[index];
int Left_Index = ((index * -1) -1);
return Left[Left_Index];
}

void Tape_Type::Output()
{ printf("Tape_Type::Output()\n");

if (Left.size())
{
int Last_One = Left.size() - 1;
for (int N = Last_One; N >= 0; N--)
{
int TH = (N + 1) * -1; // determine Tape_Head from N
printf("[%04d]:%c Left[%02d]\n", TH, Left[N], N);
}
}
if (Right.size())
for (int N = 0; N < Right.size(); N++)
printf("[%04d]:%c Right[%02d]\n", N, Right[N], N);
}

void Tape_Type::move_left()
{ Tape_Head--;
int Left_Index = ((Tape_Head * -1) -1);
if (Left_Index == Left.size())
Left.push_back('_');
}

void Tape_Type::move_right()
{ Tape_Head++;
if (Tape_Head == Right.size())
Right.push_back('_');
}

--
Copyright 2022 Pete Olcott

"Talent hits a target no one else can hit;
Genius hits a target no one else can see."
Arthur Schopenhauer

Re: Implementing a two-way Turing Machine tape as an improvement to std::deque

<20220512235610.00004914@reddwarf.jmc>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=32224&group=comp.theory#32224

  copy link   Newsgroups: comp.theory comp.ai.philosophy comp.lang.c comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.roellig-ltd.de!open-news-network.org!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx01.ams4.POSTED!not-for-mail
From: flib...@reddwarf.jmc (Mr Flibble)
Newsgroups: comp.theory,comp.ai.philosophy,comp.lang.c,comp.lang.c++
Subject: Re: Implementing a two-way Turing Machine tape as an improvement to
std::deque
Message-ID: <20220512235610.00004914@reddwarf.jmc>
References: <cNWdnXqV1cXzEuD_nZ2dnUU7_8zNnZ2d@giganews.com>
Organization: Jupiter Mining Corp
X-Newsreader: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-w64-mingw32)
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Lines: 74
X-Complaints-To: abuse@eweka.nl
NNTP-Posting-Date: Thu, 12 May 2022 22:56:09 UTC
Date: Thu, 12 May 2022 23:56:10 +0100
X-Received-Bytes: 2929
 by: Mr Flibble - Thu, 12 May 2022 22:56 UTC

On Thu, 12 May 2022 17:51:25 -0500
olcott <NoOne@NoWhere.com> wrote:

> C/C++ people please critique this as the basis for an improvement to
> std::deque. It seems to have the key functionality of std::deque and
> does it much more simply while saving time and space.
> https://www.cplusplus.com/reference/deque/deque/
>
> #define tape_element unsigned char
>
> class Tape_Type
> {
> private:
> int Tape_Head = 0; // Can be negative
> std::vector<tape_element> Left; // Stores left expansion
> std::vector<tape_element> Right; // Stores right expansion
> tape_element & operator[](int index);
>
> public:
> void move_left(); // Tape_Head--; Left.push_back(0); as needed
> void move_right(); // Tape_Head++; Left.push_back(0); as needed
> void Write(tape_element Y){ this->operator[](Tape_Head) = Y; };
> tape_element Read() { return this->operator[](Tape_Head); };
> Tape_Type(){ Right.push_back('_'); } // constructor
> void Output();
> };
>
> tape_element& Tape_Type::operator[](int index)
> {
> if (index > 0)
> return Right[index];
> int Left_Index = ((index * -1) -1);
> return Left[Left_Index];
> }
>
> void Tape_Type::Output()
> {
> printf("Tape_Type::Output()\n");
>
> if (Left.size())
> {
> int Last_One = Left.size() - 1;
> for (int N = Last_One; N >= 0; N--)
> {
> int TH = (N + 1) * -1; // determine Tape_Head from N
> printf("[%04d]:%c Left[%02d]\n", TH, Left[N], N);
> }
> }
> if (Right.size())
> for (int N = 0; N < Right.size(); N++)
> printf("[%04d]:%c Right[%02d]\n", N, Right[N], N);
> }
>
> void Tape_Type::move_left()
> {
> Tape_Head--;
> int Left_Index = ((Tape_Head * -1) -1);
> if (Left_Index == Left.size())
> Left.push_back('_');
> }
>
> void Tape_Type::move_right()
> {
> Tape_Head++;
> if (Tape_Head == Right.size())
> Right.push_back('_');
> }

It might be a more appropriate solution than std::deque for your
specific use-case however it is NOT an improvement to std::deque for
the general case -- see my reply in the other thread for why.

/Flibble

Re: Implementing a two-way Turing Machine tape as an improvement to std::deque

<Vf2dnR9fAewpDuD_nZ2dnUU7_8xh4p2d@giganews.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=32227&group=comp.theory#32227

  copy link   Newsgroups: comp.theory comp.ai.philosophy comp.lang.c comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!buffer2.nntp.dca1.giganews.com!buffer1.nntp.dca1.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Thu, 12 May 2022 18:09:40 -0500
Date: Thu, 12 May 2022 18:09:39 -0500
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Subject: Re: Implementing a two-way Turing Machine tape as an improvement to
std::deque
Content-Language: en-US
Newsgroups: comp.theory,comp.ai.philosophy,comp.lang.c,comp.lang.c++
References: <cNWdnXqV1cXzEuD_nZ2dnUU7_8zNnZ2d@giganews.com>
<20220512235610.00004914@reddwarf.jmc>
From: NoO...@NoWhere.com (olcott)
In-Reply-To: <20220512235610.00004914@reddwarf.jmc>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <Vf2dnR9fAewpDuD_nZ2dnUU7_8xh4p2d@giganews.com>
Lines: 84
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-JqqL1dgkOmMhV4Fvo4aLYDD4OGXZ1bYgQJ3ghFUK6hiprUdCbFKEpY16hWKJETwOI5hVgwJfemjIfJk!+0aGHCdnFp5pbztBphW8U4+OD5ugPLdfZdpyRuIYi9wMylfwWxEjbOS6ALvpO35KQG0gwMjjL/U=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 3914
 by: olcott - Thu, 12 May 2022 23:09 UTC

On 5/12/2022 5:56 PM, Mr Flibble wrote:
> On Thu, 12 May 2022 17:51:25 -0500
> olcott <NoOne@NoWhere.com> wrote:
>
>> C/C++ people please critique this as the basis for an improvement to
>> std::deque. It seems to have the key functionality of std::deque and
>> does it much more simply while saving time and space.
>> https://www.cplusplus.com/reference/deque/deque/
>>
>> #define tape_element unsigned char
>>
>> class Tape_Type
>> {
>> private:
>> int Tape_Head = 0; // Can be negative
>> std::vector<tape_element> Left; // Stores left expansion
>> std::vector<tape_element> Right; // Stores right expansion
>> tape_element & operator[](int index);
>>
>> public:
>> void move_left(); // Tape_Head--; Left.push_back(0); as needed
>> void move_right(); // Tape_Head++; Left.push_back(0); as needed
>> void Write(tape_element Y){ this->operator[](Tape_Head) = Y; };
>> tape_element Read() { return this->operator[](Tape_Head); };
>> Tape_Type(){ Right.push_back('_'); } // constructor
>> void Output();
>> };
>>
>> tape_element& Tape_Type::operator[](int index)
>> {
>> if (index > 0)
>> return Right[index];
>> int Left_Index = ((index * -1) -1);
>> return Left[Left_Index];
>> }
>>
>> void Tape_Type::Output()
>> {
>> printf("Tape_Type::Output()\n");
>>
>> if (Left.size())
>> {
>> int Last_One = Left.size() - 1;
>> for (int N = Last_One; N >= 0; N--)
>> {
>> int TH = (N + 1) * -1; // determine Tape_Head from N
>> printf("[%04d]:%c Left[%02d]\n", TH, Left[N], N);
>> }
>> }
>> if (Right.size())
>> for (int N = 0; N < Right.size(); N++)
>> printf("[%04d]:%c Right[%02d]\n", N, Right[N], N);
>> }
>>
>> void Tape_Type::move_left()
>> {
>> Tape_Head--;
>> int Left_Index = ((Tape_Head * -1) -1);
>> if (Left_Index == Left.size())
>> Left.push_back('_');
>> }
>>
>> void Tape_Type::move_right()
>> {
>> Tape_Head++;
>> if (Tape_Head == Right.size())
>> Right.push_back('_');
>> }
>
> It might be a more appropriate solution than std::deque for your
> specific use-case however it is NOT an improvement to std::deque for
> the general case -- see my reply in the other thread for why.
>
> /Flibble
>

I didn't see any reason why it would not make a better std::deque.

--
Copyright 2022 Pete Olcott

"Talent hits a target no one else can hit;
Genius hits a target no one else can see."
Arthur Schopenhauer

Re: Implementing a two-way Turing Machine tape as an improvement to std::deque

<20220513002218.00003fa0@reddwarf.jmc>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=32231&group=comp.theory#32231

  copy link   Newsgroups: comp.theory comp.ai.philosophy comp.lang.c comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeder1.feed.usenet.farm!feed.usenet.farm!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx01.ams4.POSTED!not-for-mail
From: flib...@reddwarf.jmc (Mr Flibble)
Newsgroups: comp.theory,comp.ai.philosophy,comp.lang.c,comp.lang.c++
Subject: Re: Implementing a two-way Turing Machine tape as an improvement to
std::deque
Message-ID: <20220513002218.00003fa0@reddwarf.jmc>
References: <cNWdnXqV1cXzEuD_nZ2dnUU7_8zNnZ2d@giganews.com>
<20220512235610.00004914@reddwarf.jmc>
<Vf2dnR9fAewpDuD_nZ2dnUU7_8xh4p2d@giganews.com>
Organization: Jupiter Mining Corp
X-Newsreader: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-w64-mingw32)
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Lines: 86
X-Complaints-To: abuse@eweka.nl
NNTP-Posting-Date: Thu, 12 May 2022 23:22:17 UTC
Date: Fri, 13 May 2022 00:22:18 +0100
X-Received-Bytes: 3565
 by: Mr Flibble - Thu, 12 May 2022 23:22 UTC

On Thu, 12 May 2022 18:09:39 -0500
olcott <NoOne@NoWhere.com> wrote:

> On 5/12/2022 5:56 PM, Mr Flibble wrote:
> > On Thu, 12 May 2022 17:51:25 -0500
> > olcott <NoOne@NoWhere.com> wrote:
> >
> >> C/C++ people please critique this as the basis for an improvement
> >> to std::deque. It seems to have the key functionality of
> >> std::deque and does it much more simply while saving time and
> >> space. https://www.cplusplus.com/reference/deque/deque/
> >>
> >> #define tape_element unsigned char
> >>
> >> class Tape_Type
> >> {
> >> private:
> >> int Tape_Head = 0; // Can be negative
> >> std::vector<tape_element> Left; // Stores left expansion
> >> std::vector<tape_element> Right; // Stores right expansion
> >> tape_element & operator[](int index);
> >>
> >> public:
> >> void move_left(); // Tape_Head--; Left.push_back(0); as
> >> needed void move_right(); // Tape_Head++; Left.push_back(0);
> >> as needed void Write(tape_element Y){ this->operator[](Tape_Head)
> >> = Y; }; tape_element Read() { return
> >> this->operator[](Tape_Head); }; Tape_Type(){ Right.push_back('_');
> >> } // constructor void Output();
> >> };
> >>
> >> tape_element& Tape_Type::operator[](int index)
> >> {
> >> if (index > 0)
> >> return Right[index];
> >> int Left_Index = ((index * -1) -1);
> >> return Left[Left_Index];
> >> }
> >>
> >> void Tape_Type::Output()
> >> {
> >> printf("Tape_Type::Output()\n");
> >>
> >> if (Left.size())
> >> {
> >> int Last_One = Left.size() - 1;
> >> for (int N = Last_One; N >= 0; N--)
> >> {
> >> int TH = (N + 1) * -1; // determine Tape_Head from N
> >> printf("[%04d]:%c Left[%02d]\n", TH, Left[N], N);
> >> }
> >> }
> >> if (Right.size())
> >> for (int N = 0; N < Right.size(); N++)
> >> printf("[%04d]:%c Right[%02d]\n", N, Right[N], N);
> >> }
> >>
> >> void Tape_Type::move_left()
> >> {
> >> Tape_Head--;
> >> int Left_Index = ((Tape_Head * -1) -1);
> >> if (Left_Index == Left.size())
> >> Left.push_back('_');
> >> }
> >>
> >> void Tape_Type::move_right()
> >> {
> >> Tape_Head++;
> >> if (Tape_Head == Right.size())
> >> Right.push_back('_');
> >> }
> >
> > It might be a more appropriate solution than std::deque for your
> > specific use-case however it is NOT an improvement to std::deque for
> > the general case -- see my reply in the other thread for why.
> >
> > /Flibble
> >
>
> I didn't see any reason why it would not make a better std::deque.
Because it doesn't meet the complexity and referential integrity
requirements of std::deque.

/Flibble

Re: Implementing a two-way Turing Machine tape as an improvement to std::deque

<5GgfK.2451$R6W6.1148@fx45.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=32233&group=comp.theory#32233

  copy link   Newsgroups: comp.theory comp.ai.philosophy comp.lang.c comp.lang.c++
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!feeder.usenetexpress.com!tr2.eu1.usenetexpress.com!feeder1.feed.usenet.farm!feed.usenet.farm!peer02.ams4!peer.am4.highwinds-media.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx45.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.9.0
Subject: Re: Implementing a two-way Turing Machine tape as an improvement to std::deque
Content-Language: en-US
Newsgroups: comp.theory,comp.ai.philosophy,comp.lang.c,comp.lang.c++
References: <cNWdnXqV1cXzEuD_nZ2dnUU7_8zNnZ2d@giganews.com>
From: Rich...@Damon-Family.org (Richard Damon)
In-Reply-To: <cNWdnXqV1cXzEuD_nZ2dnUU7_8zNnZ2d@giganews.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 72
Message-ID: <5GgfK.2451$R6W6.1148@fx45.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Thu, 12 May 2022 19:23:47 -0400
X-Received-Bytes: 3201
 by: Richard Damon - Thu, 12 May 2022 23:23 UTC

On 5/12/22 6:51 PM, olcott wrote:
> C/C++ people please critique this as the basis for an improvement to
> std::deque. It seems to have the key functionality of std::deque and
> does it much more simply while saving time and space.
> https://www.cplusplus.com/reference/deque/deque/
>
> #define tape_element unsigned char
>
> class Tape_Type
> {
> private:
>   int Tape_Head = 0;               // Can be negative
>   std::vector<tape_element> Left;  // Stores left expansion
>   std::vector<tape_element> Right; // Stores right expansion
>   tape_element & operator[](int index);
>
> public:
>   void move_left();      // Tape_Head--; Left.push_back(0); as needed
>   void move_right();     // Tape_Head++; Left.push_back(0); as needed
>   void Write(tape_element Y){ this->operator[](Tape_Head) = Y; };
>   tape_element Read()       { return this->operator[](Tape_Head); };
>   Tape_Type(){ Right.push_back('_'); } // constructor
>   void Output();
> };
>
> tape_element& Tape_Type::operator[](int index)
> {
>   if (index > 0)
>     return Right[index];
>   int Left_Index = ((index * -1) -1);
>   return Left[Left_Index];
> }
>
> void Tape_Type::Output()
> {
>   printf("Tape_Type::Output()\n");
>
>   if (Left.size())
>   {
>     int Last_One = Left.size() - 1;
>     for (int N = Last_One; N >= 0; N--)
>     {
>       int TH = (N + 1) * -1; // determine Tape_Head from N
>       printf("[%04d]:%c   Left[%02d]\n", TH, Left[N], N);
>     }
>   }
>   if (Right.size())
>     for (int N = 0; N < Right.size(); N++)
>       printf("[%04d]:%c  Right[%02d]\n", N, Right[N], N);
> }
>
> void Tape_Type::move_left()
> {
>   Tape_Head--;
>   int Left_Index = ((Tape_Head * -1) -1);
>   if (Left_Index == Left.size())
>     Left.push_back('_');
> }
>
> void Tape_Type::move_right()
> {
>   Tape_Head++;
>   if (Tape_Head == Right.size())
>     Right.push_back('_');
> }
>
>
>

Looks at what indexing with an index value of 0 does.

Operator [] want to test index >= 0, not > 0

Re: Implementing a two-way Turing Machine tape as an improvement to std::deque

<Up-dnYjT5e-2BOD_nZ2dnUU7_8zNnZ2d@giganews.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=32236&group=comp.theory#32236

  copy link   Newsgroups: comp.theory comp.ai.philosophy comp.lang.c comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!buffer2.nntp.dca1.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Thu, 12 May 2022 18:32:59 -0500
Date: Thu, 12 May 2022 18:32:58 -0500
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Subject: Re: Implementing a two-way Turing Machine tape as an improvement to
std::deque
Content-Language: en-US
Newsgroups: comp.theory,comp.ai.philosophy,comp.lang.c,comp.lang.c++
References: <cNWdnXqV1cXzEuD_nZ2dnUU7_8zNnZ2d@giganews.com>
<5GgfK.2451$R6W6.1148@fx45.iad>
From: NoO...@NoWhere.com (olcott)
In-Reply-To: <5GgfK.2451$R6W6.1148@fx45.iad>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Message-ID: <Up-dnYjT5e-2BOD_nZ2dnUU7_8zNnZ2d@giganews.com>
Lines: 82
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-vGrpRxzUoae2RSj+SoUHDuCXDZHmB19EajhhnyWoN3QqGezEAliZBTT33ijz+dJmkDzmk/B5FvMUQhm!waVqGgvxOiV4jcsL8buzvM026Tkmj13jrJZY98yZGoSXSi3yTJaV3hpQw1m14uJlidhdc/VOIII=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 3846
 by: olcott - Thu, 12 May 2022 23:32 UTC

On 5/12/2022 6:23 PM, Richard Damon wrote:
> On 5/12/22 6:51 PM, olcott wrote:
>> C/C++ people please critique this as the basis for an improvement to
>> std::deque. It seems to have the key functionality of std::deque and
>> does it much more simply while saving time and space.
>> https://www.cplusplus.com/reference/deque/deque/
>>
>> #define tape_element unsigned char
>>
>> class Tape_Type
>> {
>> private:
>>    int Tape_Head = 0;               // Can be negative
>>    std::vector<tape_element> Left;  // Stores left expansion
>>    std::vector<tape_element> Right; // Stores right expansion
>>    tape_element & operator[](int index);
>>
>> public:
>>    void move_left();      // Tape_Head--; Left.push_back(0); as needed
>>    void move_right();     // Tape_Head++; Left.push_back(0); as needed
>>    void Write(tape_element Y){ this->operator[](Tape_Head) = Y; };
>>    tape_element Read()       { return this->operator[](Tape_Head); };
>>    Tape_Type(){ Right.push_back('_'); } // constructor
>>    void Output();
>> };
>>
>> tape_element& Tape_Type::operator[](int index)
>> {
>>    if (index > 0)
>>      return Right[index];
>>    int Left_Index = ((index * -1) -1);
>>    return Left[Left_Index];
>> }
>>
>> void Tape_Type::Output()
>> {
>>    printf("Tape_Type::Output()\n");
>>
>>    if (Left.size())
>>    {
>>      int Last_One = Left.size() - 1;
>>      for (int N = Last_One; N >= 0; N--)
>>      {
>>        int TH = (N + 1) * -1; // determine Tape_Head from N
>>        printf("[%04d]:%c   Left[%02d]\n", TH, Left[N], N);
>>      }
>>    }
>>    if (Right.size())
>>      for (int N = 0; N < Right.size(); N++)
>>        printf("[%04d]:%c  Right[%02d]\n", N, Right[N], N);
>> }
>>
>> void Tape_Type::move_left()
>> {
>>    Tape_Head--;
>>    int Left_Index = ((Tape_Head * -1) -1);
>>    if (Left_Index == Left.size())
>>      Left.push_back('_');
>> }
>>
>> void Tape_Type::move_right()
>> {
>>    Tape_Head++;
>>    if (Tape_Head == Right.size())
>>      Right.push_back('_');
>> }
>>
>>
>>
>
> Looks at what indexing with an index value of 0 does.
>
> Operator [] want to test index >= 0, not > 0

Good catch. I just wrote that function as a simplification.

--
Copyright 2022 Pete Olcott

"Talent hits a target no one else can hit;
Genius hits a target no one else can see."
Arthur Schopenhauer

Re: Implementing a two-way Turing Machine tape as an improvement to std::deque

<-s-dncjVifoXB-D_nZ2dnUU7_83NnZ2d@giganews.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=32237&group=comp.theory#32237

  copy link   Newsgroups: comp.theory comp.ai.philosophy comp.lang.c comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!buffer2.nntp.dca1.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Thu, 12 May 2022 18:38:50 -0500
Date: Thu, 12 May 2022 18:38:49 -0500
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Subject: Re: Implementing a two-way Turing Machine tape as an improvement to
std::deque
Content-Language: en-US
Newsgroups: comp.theory,comp.ai.philosophy,comp.lang.c,comp.lang.c++
References: <cNWdnXqV1cXzEuD_nZ2dnUU7_8zNnZ2d@giganews.com>
<20220512235610.00004914@reddwarf.jmc>
<Vf2dnR9fAewpDuD_nZ2dnUU7_8xh4p2d@giganews.com>
<20220513002218.00003fa0@reddwarf.jmc>
From: NoO...@NoWhere.com (olcott)
In-Reply-To: <20220513002218.00003fa0@reddwarf.jmc>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <-s-dncjVifoXB-D_nZ2dnUU7_83NnZ2d@giganews.com>
Lines: 99
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-ujsi0yPI96ki8sVBwjfA6IRq5Ws3UwFvv6e4I/qE+9YXAiv7nU9DDwsLqC6LXub66Epm7ia7WRGwW7c!sWBBDa6IxMO5RMnRNy4tOXn88bnS487apUJFW7wrKDr0tPrEZhtoAA4hy+5ZYK6mrcSnUmuVShw=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 4624
 by: olcott - Thu, 12 May 2022 23:38 UTC

On 5/12/2022 6:22 PM, Mr Flibble wrote:
> On Thu, 12 May 2022 18:09:39 -0500
> olcott <NoOne@NoWhere.com> wrote:
>
>> On 5/12/2022 5:56 PM, Mr Flibble wrote:
>>> On Thu, 12 May 2022 17:51:25 -0500
>>> olcott <NoOne@NoWhere.com> wrote:
>>>
>>>> C/C++ people please critique this as the basis for an improvement
>>>> to std::deque. It seems to have the key functionality of
>>>> std::deque and does it much more simply while saving time and
>>>> space. https://www.cplusplus.com/reference/deque/deque/
>>>>
>>>> #define tape_element unsigned char
>>>>
>>>> class Tape_Type
>>>> {
>>>> private:
>>>> int Tape_Head = 0; // Can be negative
>>>> std::vector<tape_element> Left; // Stores left expansion
>>>> std::vector<tape_element> Right; // Stores right expansion
>>>> tape_element & operator[](int index);
>>>>
>>>> public:
>>>> void move_left(); // Tape_Head--; Left.push_back(0); as
>>>> needed void move_right(); // Tape_Head++; Left.push_back(0);
>>>> as needed void Write(tape_element Y){ this->operator[](Tape_Head)
>>>> = Y; }; tape_element Read() { return
>>>> this->operator[](Tape_Head); }; Tape_Type(){ Right.push_back('_');
>>>> } // constructor void Output();
>>>> };
>>>>
>>>> tape_element& Tape_Type::operator[](int index)
>>>> {
>>>> if (index > 0)
>>>> return Right[index];
>>>> int Left_Index = ((index * -1) -1);
>>>> return Left[Left_Index];
>>>> }
>>>>
>>>> void Tape_Type::Output()
>>>> {
>>>> printf("Tape_Type::Output()\n");
>>>>
>>>> if (Left.size())
>>>> {
>>>> int Last_One = Left.size() - 1;
>>>> for (int N = Last_One; N >= 0; N--)
>>>> {
>>>> int TH = (N + 1) * -1; // determine Tape_Head from N
>>>> printf("[%04d]:%c Left[%02d]\n", TH, Left[N], N);
>>>> }
>>>> }
>>>> if (Right.size())
>>>> for (int N = 0; N < Right.size(); N++)
>>>> printf("[%04d]:%c Right[%02d]\n", N, Right[N], N);
>>>> }
>>>>
>>>> void Tape_Type::move_left()
>>>> {
>>>> Tape_Head--;
>>>> int Left_Index = ((Tape_Head * -1) -1);
>>>> if (Left_Index == Left.size())
>>>> Left.push_back('_');
>>>> }
>>>>
>>>> void Tape_Type::move_right()
>>>> {
>>>> Tape_Head++;
>>>> if (Tape_Head == Right.size())
>>>> Right.push_back('_');
>>>> }
>>>
>>> It might be a more appropriate solution than std::deque for your
>>> specific use-case however it is NOT an improvement to std::deque for
>>> the general case -- see my reply in the other thread for why.
>>>
>>> /Flibble
>>>
>>
>> I didn't see any reason why it would not make a better std::deque.
>
> Because it doesn't meet the complexity and referential integrity
> requirements of std::deque.
>
> /Flibble
>

It is faster then std::deque.
I couldn't find what you mean by referential integrity it has too many
different meanings. invalidating iterators seemed to be what you mean
otherwise I have no idea.

--
Copyright 2022 Pete Olcott

"Talent hits a target no one else can hit;
Genius hits a target no one else can see."
Arthur Schopenhauer

Re: Implementing a two-way Turing Machine tape as an improvement to std::deque

<20220513004049.00000d64@reddwarf.jmc>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=32238&group=comp.theory#32238

  copy link   Newsgroups: comp.theory comp.ai.philosophy comp.lang.c comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.roellig-ltd.de!open-news-network.org!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx04.ams4.POSTED!not-for-mail
From: flib...@reddwarf.jmc (Mr Flibble)
Newsgroups: comp.theory,comp.ai.philosophy,comp.lang.c,comp.lang.c++
Subject: Re: Implementing a two-way Turing Machine tape as an improvement to
std::deque
Message-ID: <20220513004049.00000d64@reddwarf.jmc>
References: <cNWdnXqV1cXzEuD_nZ2dnUU7_8zNnZ2d@giganews.com>
<20220512235610.00004914@reddwarf.jmc>
<Vf2dnR9fAewpDuD_nZ2dnUU7_8xh4p2d@giganews.com>
<20220513002218.00003fa0@reddwarf.jmc>
<-s-dncjVifoXB-D_nZ2dnUU7_83NnZ2d@giganews.com>
Organization: Jupiter Mining Corp
X-Newsreader: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-w64-mingw32)
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Lines: 111
X-Complaints-To: abuse@eweka.nl
NNTP-Posting-Date: Thu, 12 May 2022 23:40:48 UTC
Date: Fri, 13 May 2022 00:40:49 +0100
X-Received-Bytes: 4838
 by: Mr Flibble - Thu, 12 May 2022 23:40 UTC

On Thu, 12 May 2022 18:38:49 -0500
olcott <NoOne@NoWhere.com> wrote:

> On 5/12/2022 6:22 PM, Mr Flibble wrote:
> > On Thu, 12 May 2022 18:09:39 -0500
> > olcott <NoOne@NoWhere.com> wrote:
> >
> >> On 5/12/2022 5:56 PM, Mr Flibble wrote:
> >>> On Thu, 12 May 2022 17:51:25 -0500
> >>> olcott <NoOne@NoWhere.com> wrote:
> >>>
> >>>> C/C++ people please critique this as the basis for an improvement
> >>>> to std::deque. It seems to have the key functionality of
> >>>> std::deque and does it much more simply while saving time and
> >>>> space. https://www.cplusplus.com/reference/deque/deque/
> >>>>
> >>>> #define tape_element unsigned char
> >>>>
> >>>> class Tape_Type
> >>>> {
> >>>> private:
> >>>> int Tape_Head = 0; // Can be negative
> >>>> std::vector<tape_element> Left; // Stores left expansion
> >>>> std::vector<tape_element> Right; // Stores right expansion
> >>>> tape_element & operator[](int index);
> >>>>
> >>>> public:
> >>>> void move_left(); // Tape_Head--; Left.push_back(0); as
> >>>> needed void move_right(); // Tape_Head++; Left.push_back(0);
> >>>> as needed void Write(tape_element Y){ this->operator[](Tape_Head)
> >>>> = Y; }; tape_element Read() { return
> >>>> this->operator[](Tape_Head); }; Tape_Type(){
> >>>> Right.push_back('_'); } // constructor void Output();
> >>>> };
> >>>>
> >>>> tape_element& Tape_Type::operator[](int index)
> >>>> {
> >>>> if (index > 0)
> >>>> return Right[index];
> >>>> int Left_Index = ((index * -1) -1);
> >>>> return Left[Left_Index];
> >>>> }
> >>>>
> >>>> void Tape_Type::Output()
> >>>> {
> >>>> printf("Tape_Type::Output()\n");
> >>>>
> >>>> if (Left.size())
> >>>> {
> >>>> int Last_One = Left.size() - 1;
> >>>> for (int N = Last_One; N >= 0; N--)
> >>>> {
> >>>> int TH = (N + 1) * -1; // determine Tape_Head from N
> >>>> printf("[%04d]:%c Left[%02d]\n", TH, Left[N], N);
> >>>> }
> >>>> }
> >>>> if (Right.size())
> >>>> for (int N = 0; N < Right.size(); N++)
> >>>> printf("[%04d]:%c Right[%02d]\n", N, Right[N], N);
> >>>> }
> >>>>
> >>>> void Tape_Type::move_left()
> >>>> {
> >>>> Tape_Head--;
> >>>> int Left_Index = ((Tape_Head * -1) -1);
> >>>> if (Left_Index == Left.size())
> >>>> Left.push_back('_');
> >>>> }
> >>>>
> >>>> void Tape_Type::move_right()
> >>>> {
> >>>> Tape_Head++;
> >>>> if (Tape_Head == Right.size())
> >>>> Right.push_back('_');
> >>>> }
> >>>
> >>> It might be a more appropriate solution than std::deque for your
> >>> specific use-case however it is NOT an improvement to std::deque
> >>> for the general case -- see my reply in the other thread for why.
> >>>
> >>> /Flibble
> >>>
> >>
> >> I didn't see any reason why it would not make a better std::deque.
> >>
> >
> > Because it doesn't meet the complexity and referential integrity
> > requirements of std::deque.
> >
> > /Flibble
> >
>
> It is faster then std::deque.
> I couldn't find what you mean by referential integrity it has too
> many different meanings. invalidating iterators seemed to be what you
> mean otherwise I have no idea.
I see you are choosing to ignore my reply in the other thread. OK, I
will repost why you are wrong here:

* referential integrity and iterator invalidation are different
things: when you add or remove elements to either end of a
std::deque iterators are indeed invalidated however references to
existing elements remain valid
* If you do 1000 push_fronts followed by 1000 push_backs followed by
1000 pop_fronts all is good however your next pop_front will have
linear complexity, O(n), as it will necessitate removal of the first
element of the right std::vector.

/Flibble

Re: Implementing a two-way Turing Machine tape as an improvement to std::deque

<HYudneQqVdKFAOD_nZ2dnUU7_83NnZ2d@giganews.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=32240&group=comp.theory#32240

  copy link   Newsgroups: comp.theory comp.ai.philosophy comp.lang.c comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!buffer2.nntp.dca1.giganews.com!buffer1.nntp.dca1.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Thu, 12 May 2022 18:49:44 -0500
Date: Thu, 12 May 2022 18:49:43 -0500
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Subject: Re: Implementing a two-way Turing Machine tape as an improvement to
std::deque
Content-Language: en-US
Newsgroups: comp.theory,comp.ai.philosophy,comp.lang.c,comp.lang.c++
References: <cNWdnXqV1cXzEuD_nZ2dnUU7_8zNnZ2d@giganews.com>
<20220512235610.00004914@reddwarf.jmc>
<Vf2dnR9fAewpDuD_nZ2dnUU7_8xh4p2d@giganews.com>
<20220513002218.00003fa0@reddwarf.jmc>
<-s-dncjVifoXB-D_nZ2dnUU7_83NnZ2d@giganews.com>
<20220513004049.00000d64@reddwarf.jmc>
From: NoO...@NoWhere.com (olcott)
In-Reply-To: <20220513004049.00000d64@reddwarf.jmc>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <HYudneQqVdKFAOD_nZ2dnUU7_83NnZ2d@giganews.com>
Lines: 123
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-mDMgyaSrZTEDJyPQuXiWSxEGypvSWqVf0rqRfJ4UhLslr+O8rFUjZD6PkU+3HDhNORFCI8JGC2j2pn2!zfJifi5+AQgNYUJxTaVtJ+KEy4PMik4AJZLly/sNQnb2xtu9zfFgUmf1MxYpNmyRNd4RX/VZeR0=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 5996
 by: olcott - Thu, 12 May 2022 23:49 UTC

On 5/12/2022 6:40 PM, Mr Flibble wrote:
> On Thu, 12 May 2022 18:38:49 -0500
> olcott <NoOne@NoWhere.com> wrote:
>
>> On 5/12/2022 6:22 PM, Mr Flibble wrote:
>>> On Thu, 12 May 2022 18:09:39 -0500
>>> olcott <NoOne@NoWhere.com> wrote:
>>>
>>>> On 5/12/2022 5:56 PM, Mr Flibble wrote:
>>>>> On Thu, 12 May 2022 17:51:25 -0500
>>>>> olcott <NoOne@NoWhere.com> wrote:
>>>>>
>>>>>> C/C++ people please critique this as the basis for an improvement
>>>>>> to std::deque. It seems to have the key functionality of
>>>>>> std::deque and does it much more simply while saving time and
>>>>>> space. https://www.cplusplus.com/reference/deque/deque/
>>>>>>
>>>>>> #define tape_element unsigned char
>>>>>>
>>>>>> class Tape_Type
>>>>>> {
>>>>>> private:
>>>>>> int Tape_Head = 0; // Can be negative
>>>>>> std::vector<tape_element> Left; // Stores left expansion
>>>>>> std::vector<tape_element> Right; // Stores right expansion
>>>>>> tape_element & operator[](int index);
>>>>>>
>>>>>> public:
>>>>>> void move_left(); // Tape_Head--; Left.push_back(0); as
>>>>>> needed void move_right(); // Tape_Head++; Left.push_back(0);
>>>>>> as needed void Write(tape_element Y){ this->operator[](Tape_Head)
>>>>>> = Y; }; tape_element Read() { return
>>>>>> this->operator[](Tape_Head); }; Tape_Type(){
>>>>>> Right.push_back('_'); } // constructor void Output();
>>>>>> };
>>>>>>
>>>>>> tape_element& Tape_Type::operator[](int index)
>>>>>> {
>>>>>> if (index > 0)
>>>>>> return Right[index];
>>>>>> int Left_Index = ((index * -1) -1);
>>>>>> return Left[Left_Index];
>>>>>> }
>>>>>>
>>>>>> void Tape_Type::Output()
>>>>>> {
>>>>>> printf("Tape_Type::Output()\n");
>>>>>>
>>>>>> if (Left.size())
>>>>>> {
>>>>>> int Last_One = Left.size() - 1;
>>>>>> for (int N = Last_One; N >= 0; N--)
>>>>>> {
>>>>>> int TH = (N + 1) * -1; // determine Tape_Head from N
>>>>>> printf("[%04d]:%c Left[%02d]\n", TH, Left[N], N);
>>>>>> }
>>>>>> }
>>>>>> if (Right.size())
>>>>>> for (int N = 0; N < Right.size(); N++)
>>>>>> printf("[%04d]:%c Right[%02d]\n", N, Right[N], N);
>>>>>> }
>>>>>>
>>>>>> void Tape_Type::move_left()
>>>>>> {
>>>>>> Tape_Head--;
>>>>>> int Left_Index = ((Tape_Head * -1) -1);
>>>>>> if (Left_Index == Left.size())
>>>>>> Left.push_back('_');
>>>>>> }
>>>>>>
>>>>>> void Tape_Type::move_right()
>>>>>> {
>>>>>> Tape_Head++;
>>>>>> if (Tape_Head == Right.size())
>>>>>> Right.push_back('_');
>>>>>> }
>>>>>
>>>>> It might be a more appropriate solution than std::deque for your
>>>>> specific use-case however it is NOT an improvement to std::deque
>>>>> for the general case -- see my reply in the other thread for why.
>>>>>
>>>>> /Flibble
>>>>>
>>>>
>>>> I didn't see any reason why it would not make a better std::deque.
>>>>
>>>
>>> Because it doesn't meet the complexity and referential integrity
>>> requirements of std::deque.
>>>
>>> /Flibble
>>>
>>
>> It is faster then std::deque.
>> I couldn't find what you mean by referential integrity it has too
>> many different meanings. invalidating iterators seemed to be what you
>> mean otherwise I have no idea.
>
> I see you are choosing to ignore my reply in the other thread. OK, I
> will repost why you are wrong here:
>
> * referential integrity and iterator invalidation are different
> things: when you add or remove elements to either end of a
> std::deque iterators are indeed invalidated however references to
> existing elements remain valid

Mine words the same way and has the added benefit of contiguous storage.

> * If you do 1000 push_fronts followed by 1000 push_backs followed by
> 1000 pop_fronts all is good however your next pop_front will have
> linear complexity, O(n), as it will necessitate removal of the first
> element of the right std::vector.

I don't think that this applies to the way that I implemented it.
pop_front pops from the end of Left. pop_back pops from the end of
Right. This is the key aspect that I used from David's two-stack approach.

--
Copyright 2022 Pete Olcott

"Talent hits a target no one else can hit;
Genius hits a target no one else can see."
Arthur Schopenhauer

Re: Implementing a two-way Turing Machine tape as an improvement to std::deque

<20220513005340.00001694@reddwarf.jmc>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=32241&group=comp.theory#32241

  copy link   Newsgroups: comp.theory comp.ai.philosophy comp.lang.c comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!ecngs!feeder2.ecngs.de!178.20.174.213.MISMATCH!feeder1.feed.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx04.ams4.POSTED!not-for-mail
From: flib...@reddwarf.jmc (Mr Flibble)
Newsgroups: comp.theory,comp.ai.philosophy,comp.lang.c,comp.lang.c++
Subject: Re: Implementing a two-way Turing Machine tape as an improvement to
std::deque
Message-ID: <20220513005340.00001694@reddwarf.jmc>
References: <cNWdnXqV1cXzEuD_nZ2dnUU7_8zNnZ2d@giganews.com>
<20220512235610.00004914@reddwarf.jmc>
<Vf2dnR9fAewpDuD_nZ2dnUU7_8xh4p2d@giganews.com>
<20220513002218.00003fa0@reddwarf.jmc>
<-s-dncjVifoXB-D_nZ2dnUU7_83NnZ2d@giganews.com>
<20220513004049.00000d64@reddwarf.jmc>
<HYudneQqVdKFAOD_nZ2dnUU7_83NnZ2d@giganews.com>
Organization: Jupiter Mining Corp
X-Newsreader: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-w64-mingw32)
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Lines: 130
X-Complaints-To: abuse@eweka.nl
NNTP-Posting-Date: Thu, 12 May 2022 23:53:39 UTC
Date: Fri, 13 May 2022 00:53:40 +0100
X-Received-Bytes: 5834
 by: Mr Flibble - Thu, 12 May 2022 23:53 UTC

On Thu, 12 May 2022 18:49:43 -0500
olcott <NoOne@NoWhere.com> wrote:

> On 5/12/2022 6:40 PM, Mr Flibble wrote:
> > On Thu, 12 May 2022 18:38:49 -0500
> > olcott <NoOne@NoWhere.com> wrote:
> >
> >> On 5/12/2022 6:22 PM, Mr Flibble wrote:
> >>> On Thu, 12 May 2022 18:09:39 -0500
> >>> olcott <NoOne@NoWhere.com> wrote:
> >>>
> >>>> On 5/12/2022 5:56 PM, Mr Flibble wrote:
> >>>>> On Thu, 12 May 2022 17:51:25 -0500
> >>>>> olcott <NoOne@NoWhere.com> wrote:
> >>>>>
> >>>>>> C/C++ people please critique this as the basis for an
> >>>>>> improvement to std::deque. It seems to have the key
> >>>>>> functionality of std::deque and does it much more simply while
> >>>>>> saving time and space.
> >>>>>> https://www.cplusplus.com/reference/deque/deque/
> >>>>>>
> >>>>>> #define tape_element unsigned char
> >>>>>>
> >>>>>> class Tape_Type
> >>>>>> {
> >>>>>> private:
> >>>>>> int Tape_Head = 0; // Can be negative
> >>>>>> std::vector<tape_element> Left; // Stores left expansion
> >>>>>> std::vector<tape_element> Right; // Stores right
> >>>>>> expansion tape_element & operator[](int index);
> >>>>>>
> >>>>>> public:
> >>>>>> void move_left(); // Tape_Head--;
> >>>>>> Left.push_back(0); as needed void move_right(); //
> >>>>>> Tape_Head++; Left.push_back(0); as needed void
> >>>>>> Write(tape_element Y){ this->operator[](Tape_Head) = Y; };
> >>>>>> tape_element Read() { return
> >>>>>> this->operator[](Tape_Head); }; Tape_Type(){
> >>>>>> Right.push_back('_'); } // constructor void Output(); };
> >>>>>>
> >>>>>> tape_element& Tape_Type::operator[](int index)
> >>>>>> {
> >>>>>> if (index > 0)
> >>>>>> return Right[index];
> >>>>>> int Left_Index = ((index * -1) -1);
> >>>>>> return Left[Left_Index];
> >>>>>> }
> >>>>>>
> >>>>>> void Tape_Type::Output()
> >>>>>> {
> >>>>>> printf("Tape_Type::Output()\n");
> >>>>>>
> >>>>>> if (Left.size())
> >>>>>> {
> >>>>>> int Last_One = Left.size() - 1;
> >>>>>> for (int N = Last_One; N >= 0; N--)
> >>>>>> {
> >>>>>> int TH = (N + 1) * -1; // determine Tape_Head from N
> >>>>>> printf("[%04d]:%c Left[%02d]\n", TH, Left[N], N);
> >>>>>> }
> >>>>>> }
> >>>>>> if (Right.size())
> >>>>>> for (int N = 0; N < Right.size(); N++)
> >>>>>> printf("[%04d]:%c Right[%02d]\n", N, Right[N], N);
> >>>>>> }
> >>>>>>
> >>>>>> void Tape_Type::move_left()
> >>>>>> {
> >>>>>> Tape_Head--;
> >>>>>> int Left_Index = ((Tape_Head * -1) -1);
> >>>>>> if (Left_Index == Left.size())
> >>>>>> Left.push_back('_');
> >>>>>> }
> >>>>>>
> >>>>>> void Tape_Type::move_right()
> >>>>>> {
> >>>>>> Tape_Head++;
> >>>>>> if (Tape_Head == Right.size())
> >>>>>> Right.push_back('_');
> >>>>>> }
> >>>>>
> >>>>> It might be a more appropriate solution than std::deque for your
> >>>>> specific use-case however it is NOT an improvement to std::deque
> >>>>> for the general case -- see my reply in the other thread for
> >>>>> why.
> >>>>>
> >>>>> /Flibble
> >>>>>
> >>>>
> >>>> I didn't see any reason why it would not make a better
> >>>> std::deque.
> >>>
> >>> Because it doesn't meet the complexity and referential integrity
> >>> requirements of std::deque.
> >>>
> >>> /Flibble
> >>>
> >>
> >> It is faster then std::deque.
> >> I couldn't find what you mean by referential integrity it has too
> >> many different meanings. invalidating iterators seemed to be what
> >> you mean otherwise I have no idea.
> >
> > I see you are choosing to ignore my reply in the other thread. OK, I
> > will repost why you are wrong here:
> >
> > * referential integrity and iterator invalidation are different
> > things: when you add or remove elements to either end of a
> > std::deque iterators are indeed invalidated however references
> > to existing elements remain valid
>
> Mine words the same way and has the added benefit of contiguous
> storage.
>
> > * If you do 1000 push_fronts followed by 1000 push_backs followed
> > by 1000 pop_fronts all is good however your next pop_front will have
> > linear complexity, O(n), as it will necessitate removal of the
> > first element of the right std::vector.
>
> I don't think that this applies to the way that I implemented it.
> pop_front pops from the end of Left. pop_back pops from the end of
> Right. This is the key aspect that I used from David's two-stack
> approach.
Then it is totally different to what std::deque offers: std::deque
allows ALL elements to be either popped from the front or back. Try
reading AND UNDERSTANDING what I wrote again.

/Flibble

Re: Implementing a two-way Turing Machine tape as an improvement to std::deque

<87wneq1ejm.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=32243&group=comp.theory#32243

  copy link   Newsgroups: comp.theory comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben)
Newsgroups: comp.theory,comp.lang.c++
Subject: Re: Implementing a two-way Turing Machine tape as an improvement to std::deque
Date: Fri, 13 May 2022 01:06:53 +0100
Organization: A noiseless patient Spider
Lines: 115
Message-ID: <87wneq1ejm.fsf@bsb.me.uk>
References: <cNWdnXqV1cXzEuD_nZ2dnUU7_8zNnZ2d@giganews.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="9d7070da1378146bf8b2ebf4ad06ac0b";
logging-data="29118"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18qrHUhVztvi54GqrXMLyVU96FcjnScjZU="
Cancel-Lock: sha1:dHqachASZ6ATNMr7faXt2SfP154=
sha1:AyDCbxVvdo311ZX+xnzkiI/zOgY=
X-BSB-Auth: 1.28422383a4e16260d3e8.20220513010653BST.87wneq1ejm.fsf@bsb.me.uk
 by: Ben - Fri, 13 May 2022 00:06 UTC

olcott <NoOne@NoWhere.com> writes:

I've removed the philosophy group and comp.lang.c as this is C++.

> C/C++ people please critique this as the basis for an improvement to
> std::deque.

You will get critiques of the code on whatever basis people feel
inclined to comment! You can't limit the comments to some particular
context.

> It seems to have the key functionality of std::deque and
> does it much more simply while saving time and space.

It does not have any of the functionality of std::deque. There is a
commonly used (though not particularly efficient) way to implement a
deque using two arrays, but this is not it.

> #define tape_element unsigned char

Use a typedef or using declaration. Also, I'd put the typedef in the
class as the type belongs to the class (as least that appears to be the
case from the name you've chosen).

> class Tape_Type
> {
> private:
> int Tape_Head = 0; // Can be negative
> std::vector<tape_element> Left; // Stores left expansion
> std::vector<tape_element> Right; // Stores right expansion
> tape_element & operator[](int index);
>
> public:
> void move_left(); // Tape_Head--; Left.push_back(0); as needed
> void move_right(); // Tape_Head++; Left.push_back(0); as needed

The comments are wrong since you push_back('_').

> void Write(tape_element Y){ this->operator[](Tape_Head) = Y; };
> tape_element Read() { return this->operator[](Tape_Head); };

I'd write (*this)[Tape_Head] but I suppose that's just a matter of style.

> Tape_Type(){ Right.push_back('_'); } // constructor

The constructor leaves a Tape_Type object in an unusable state, but
that's due to a bug in operator[]. Did you test?

> void Output();
> };
>
> tape_element& Tape_Type::operator[](int index)
> {
> if (index > 0)
> return Right[index];

Bug. You meant index >= 0 I think.

> int Left_Index = ((index * -1) -1);

Why not -index - 1?

> return Left[Left_Index];

Do you think introducing a new variable really make the code clearer
that simply writing

return Left[-index - 1];

? Personally, I'd write the whole thing as

return index >= 0 ? Right[index] : Left[-index - 1];

> }
>
> void Tape_Type::Output()
> {
> printf("Tape_Type::Output()\n");
>
> if (Left.size())
> {
> int Last_One = Left.size() - 1;
> for (int N = Last_One; N >= 0; N--)
> {
> int TH = (N + 1) * -1; // determine Tape_Head from N
> printf("[%04d]:%c Left[%02d]\n", TH, Left[N], N);
> }
> }
> if (Right.size())
> for (int N = 0; N < Right.size(); N++)
> printf("[%04d]:%c Right[%02d]\n", N, Right[N], N);
> }
>
> void Tape_Type::move_left()
> {
> Tape_Head--;
> int Left_Index = ((Tape_Head * -1) -1);
> if (Left_Index == Left.size())
> Left.push_back('_');
> }
>
> void Tape_Type::move_right()
> {
> Tape_Head++;
> if (Tape_Head == Right.size())
> Right.push_back('_');
> }

I find the capitalisation odd and unhelpful as there does not seem to be
any consistency about it.

--
Ben.
"le génie humain a des limites, quand la bêtise humaine n’en a pas"
Alexandre Dumas (fils)

Re: Implementing a two-way Turing Machine tape as an improvement to std::deque

<Bo-dnemL1eT6P-D_nZ2dnUU7_81g4p2d@giganews.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=32245&group=comp.theory#32245

  copy link   Newsgroups: comp.theory comp.ai.philosophy comp.lang.c comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!buffer2.nntp.dca1.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Thu, 12 May 2022 19:12:23 -0500
Date: Thu, 12 May 2022 19:12:22 -0500
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Subject: Re: Implementing a two-way Turing Machine tape as an improvement to
std::deque
Content-Language: en-US
Newsgroups: comp.theory,comp.ai.philosophy,comp.lang.c,comp.lang.c++
References: <cNWdnXqV1cXzEuD_nZ2dnUU7_8zNnZ2d@giganews.com>
<20220512235610.00004914@reddwarf.jmc>
<Vf2dnR9fAewpDuD_nZ2dnUU7_8xh4p2d@giganews.com>
<20220513002218.00003fa0@reddwarf.jmc>
<-s-dncjVifoXB-D_nZ2dnUU7_83NnZ2d@giganews.com>
<20220513004049.00000d64@reddwarf.jmc>
<HYudneQqVdKFAOD_nZ2dnUU7_83NnZ2d@giganews.com>
<20220513005340.00001694@reddwarf.jmc>
From: NoO...@NoWhere.com (olcott)
In-Reply-To: <20220513005340.00001694@reddwarf.jmc>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <Bo-dnemL1eT6P-D_nZ2dnUU7_81g4p2d@giganews.com>
Lines: 141
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-OoPTKurhr50QG0qUGDMJ9rahN6Bfnlcfm74cV4CQR2Xq3LB4zCeYoEEqr7AGOavLPZQHvaPajp83XVk!/LjTsVYcGwpma91K+swR6GF7voIWU+EmbqzcYwgD8FsKqH/yDSUvfTrU58jWcyP6Ly7YjJXVOFw=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 6841
 by: olcott - Fri, 13 May 2022 00:12 UTC

On 5/12/2022 6:53 PM, Mr Flibble wrote:
> On Thu, 12 May 2022 18:49:43 -0500
> olcott <NoOne@NoWhere.com> wrote:
>
>> On 5/12/2022 6:40 PM, Mr Flibble wrote:
>>> On Thu, 12 May 2022 18:38:49 -0500
>>> olcott <NoOne@NoWhere.com> wrote:
>>>
>>>> On 5/12/2022 6:22 PM, Mr Flibble wrote:
>>>>> On Thu, 12 May 2022 18:09:39 -0500
>>>>> olcott <NoOne@NoWhere.com> wrote:
>>>>>
>>>>>> On 5/12/2022 5:56 PM, Mr Flibble wrote:
>>>>>>> On Thu, 12 May 2022 17:51:25 -0500
>>>>>>> olcott <NoOne@NoWhere.com> wrote:
>>>>>>>
>>>>>>>> C/C++ people please critique this as the basis for an
>>>>>>>> improvement to std::deque. It seems to have the key
>>>>>>>> functionality of std::deque and does it much more simply while
>>>>>>>> saving time and space.
>>>>>>>> https://www.cplusplus.com/reference/deque/deque/
>>>>>>>>
>>>>>>>> #define tape_element unsigned char
>>>>>>>>
>>>>>>>> class Tape_Type
>>>>>>>> {
>>>>>>>> private:
>>>>>>>> int Tape_Head = 0; // Can be negative
>>>>>>>> std::vector<tape_element> Left; // Stores left expansion
>>>>>>>> std::vector<tape_element> Right; // Stores right
>>>>>>>> expansion tape_element & operator[](int index);
>>>>>>>>
>>>>>>>> public:
>>>>>>>> void move_left(); // Tape_Head--;
>>>>>>>> Left.push_back(0); as needed void move_right(); //
>>>>>>>> Tape_Head++; Left.push_back(0); as needed void
>>>>>>>> Write(tape_element Y){ this->operator[](Tape_Head) = Y; };
>>>>>>>> tape_element Read() { return
>>>>>>>> this->operator[](Tape_Head); }; Tape_Type(){
>>>>>>>> Right.push_back('_'); } // constructor void Output(); };
>>>>>>>>
>>>>>>>> tape_element& Tape_Type::operator[](int index)
>>>>>>>> {
>>>>>>>> if (index > 0)
>>>>>>>> return Right[index];
>>>>>>>> int Left_Index = ((index * -1) -1);
>>>>>>>> return Left[Left_Index];
>>>>>>>> }
>>>>>>>>
>>>>>>>> void Tape_Type::Output()
>>>>>>>> {
>>>>>>>> printf("Tape_Type::Output()\n");
>>>>>>>>
>>>>>>>> if (Left.size())
>>>>>>>> {
>>>>>>>> int Last_One = Left.size() - 1;
>>>>>>>> for (int N = Last_One; N >= 0; N--)
>>>>>>>> {
>>>>>>>> int TH = (N + 1) * -1; // determine Tape_Head from N
>>>>>>>> printf("[%04d]:%c Left[%02d]\n", TH, Left[N], N);
>>>>>>>> }
>>>>>>>> }
>>>>>>>> if (Right.size())
>>>>>>>> for (int N = 0; N < Right.size(); N++)
>>>>>>>> printf("[%04d]:%c Right[%02d]\n", N, Right[N], N);
>>>>>>>> }
>>>>>>>>
>>>>>>>> void Tape_Type::move_left()
>>>>>>>> {
>>>>>>>> Tape_Head--;
>>>>>>>> int Left_Index = ((Tape_Head * -1) -1);
>>>>>>>> if (Left_Index == Left.size())
>>>>>>>> Left.push_back('_');
>>>>>>>> }
>>>>>>>>
>>>>>>>> void Tape_Type::move_right()
>>>>>>>> {
>>>>>>>> Tape_Head++;
>>>>>>>> if (Tape_Head == Right.size())
>>>>>>>> Right.push_back('_');
>>>>>>>> }
>>>>>>>
>>>>>>> It might be a more appropriate solution than std::deque for your
>>>>>>> specific use-case however it is NOT an improvement to std::deque
>>>>>>> for the general case -- see my reply in the other thread for
>>>>>>> why.
>>>>>>>
>>>>>>> /Flibble
>>>>>>>
>>>>>>
>>>>>> I didn't see any reason why it would not make a better
>>>>>> std::deque.
>>>>>
>>>>> Because it doesn't meet the complexity and referential integrity
>>>>> requirements of std::deque.
>>>>>
>>>>> /Flibble
>>>>>
>>>>
>>>> It is faster then std::deque.
>>>> I couldn't find what you mean by referential integrity it has too
>>>> many different meanings. invalidating iterators seemed to be what
>>>> you mean otherwise I have no idea.
>>>
>>> I see you are choosing to ignore my reply in the other thread. OK, I
>>> will repost why you are wrong here:
>>>
>>> * referential integrity and iterator invalidation are different
>>> things: when you add or remove elements to either end of a
>>> std::deque iterators are indeed invalidated however references
>>> to existing elements remain valid
>>
>> Mine words the same way and has the added benefit of contiguous
>> storage.
>>
>>> * If you do 1000 push_fronts followed by 1000 push_backs followed
>>> by 1000 pop_fronts all is good however your next pop_front will have
>>> linear complexity, O(n), as it will necessitate removal of the
>>> first element of the right std::vector.
>>
>> I don't think that this applies to the way that I implemented it.
>> pop_front pops from the end of Left. pop_back pops from the end of
>> Right. This is the key aspect that I used from David's two-stack
>> approach.
>
> Then it is totally different to what std::deque offers: std::deque
> allows ALL elements to be either popped from the front or back. Try
> reading AND UNDERSTANDING what I wrote again.
>
> /Flibble
>

I could allow all elements to be popped from the front or the back too.
Mine is much faster when you need far less than all elements.

--
Copyright 2022 Pete Olcott

"Talent hits a target no one else can hit;
Genius hits a target no one else can see."
Arthur Schopenhauer

Re: Implementing a two-way Turing Machine tape as an improvement to std::deque

<MeOdncpeZacPMeD_nZ2dnUU7_8zNnZ2d@giganews.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=32248&group=comp.theory#32248

  copy link   Newsgroups: comp.theory comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!buffer2.nntp.dca1.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Thu, 12 May 2022 19:55:46 -0500
Date: Thu, 12 May 2022 19:55:44 -0500
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Subject: Re: Implementing a two-way Turing Machine tape as an improvement to
std::deque
Content-Language: en-US
Newsgroups: comp.theory,comp.lang.c++
References: <cNWdnXqV1cXzEuD_nZ2dnUU7_8zNnZ2d@giganews.com>
<87wneq1ejm.fsf@bsb.me.uk>
From: NoO...@NoWhere.com (olcott)
In-Reply-To: <87wneq1ejm.fsf@bsb.me.uk>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <MeOdncpeZacPMeD_nZ2dnUU7_8zNnZ2d@giganews.com>
Lines: 207
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-33PPXmpJumOxwSAXhkoJOVWRrQ8Xje1HZUVUJ3zCjW7hosJJwSEaoY6C0DFa2oOgmbVCYZkP9lgS1N/!93/x0+Ux5D9Vxi13hJCK/V+cxbFmNPDUUWh3dfdGjg0fcPx894o/YeGc5Qj9U5kkZwC0UWlB308=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 7175
 by: olcott - Fri, 13 May 2022 00:55 UTC

On 5/12/2022 7:06 PM, Ben wrote:
> olcott <NoOne@NoWhere.com> writes:
>
> I've removed the philosophy group and comp.lang.c as this is C++.
>
>> C/C++ people please critique this as the basis for an improvement to
>> std::deque.
>
> You will get critiques of the code on whatever basis people feel
> inclined to comment! You can't limit the comments to some particular
> context.
>
>> It seems to have the key functionality of std::deque and
>> does it much more simply while saving time and space.
>
> It does not have any of the functionality of std::deque.

That is a ridiculously stupid thing to say. It has the key most
important functionality of a std:deque

Double ended queue
deque (usually pronounced like "deck") is an irregular acronym of
double-ended queue. Double-ended queues are sequence containers with
dynamic sizes that can be expanded or contracted on both ends (either
its front or its back).

All of the rest of the functionality of std::deque can be added as needed.

> There is a
> commonly used (though not particularly efficient) way to implement a
> deque using two arrays, but this is not it.
>
>> #define tape_element unsigned char
>
> Use a typedef or using declaration. Also, I'd put the typedef in the
> class as the type belongs to the class (as least that appears to be the
> case from the name you've chosen).
>
>> class Tape_Type
>> {
>> private:
>> int Tape_Head = 0; // Can be negative
>> std::vector<tape_element> Left; // Stores left expansion
>> std::vector<tape_element> Right; // Stores right expansion
>> tape_element & operator[](int index);
>>
>> public:
>> void move_left(); // Tape_Head--; Left.push_back(0); as needed
>> void move_right(); // Tape_Head++; Left.push_back(0); as needed
>
> The comments are wrong since you push_back('_').
>
>> void Write(tape_element Y){ this->operator[](Tape_Head) = Y; };
>> tape_element Read() { return this->operator[](Tape_Head); };
>
> I'd write (*this)[Tape_Head] but I suppose that's just a matter of style.
>
>> Tape_Type(){ Right.push_back('_'); } // constructor
>
> The constructor leaves a Tape_Type object in an unusable state, but
> that's due to a bug in operator[]. Did you test?
>

Yes I tested so I don't see what you mean.

>> void Output();
>> };
>>
>> tape_element& Tape_Type::operator[](int index)
>> {
>> if (index > 0)
>> return Right[index];
>
> Bug. You meant index >= 0 I think.

Yes Richard caught that. That was a new refactoring.

>
>> int Left_Index = ((index * -1) -1);
>
> Why not -index - 1?
>
>> return Left[Left_Index];
>
> Do you think introducing a new variable really make the code clearer
> that simply writing
>
> return Left[-index - 1];
>
> ? Personally, I'd write the whole thing as
>
> return index >= 0 ? Right[index] : Left[-index - 1];
>
>> }
>>
>> void Tape_Type::Output()
>> {
>> printf("Tape_Type::Output()\n");
>>
>> if (Left.size())
>> {
>> int Last_One = Left.size() - 1;
>> for (int N = Last_One; N >= 0; N--)
>> {
>> int TH = (N + 1) * -1; // determine Tape_Head from N
>> printf("[%04d]:%c Left[%02d]\n", TH, Left[N], N);
>> }
>> }
>> if (Right.size())
>> for (int N = 0; N < Right.size(); N++)
>> printf("[%04d]:%c Right[%02d]\n", N, Right[N], N);
>> }
>>
>> void Tape_Type::move_left()
>> {
>> Tape_Head--;
>> int Left_Index = ((Tape_Head * -1) -1);
>> if (Left_Index == Left.size())
>> Left.push_back('_');
>> }
>>
>> void Tape_Type::move_right()
>> {
>> Tape_Head++;
>> if (Tape_Head == Right.size())
>> Right.push_back('_');
>> }
>
> I find the capitalisation odd and unhelpful as there does not seem to be
> any consistency about it.
>

I found all of your suggestions very helpful.
I don't see the bug in the constructor.
I like mixed case because it is easier to read, mine not be consistent.

Here they are implemented.

//
// Tape_Type implements a two-way Turing machine tape.
// Right contains Tape_Head >= 0 values (right expansion)
// Left contains Tape_Head < 0 values (left expansion)
//
// Tape_Type has functionality very similar to std::deque
// yet implements this functionality much more simply.
// This saves time and space.
//
class Tape_Type
{ typedef unsigned char tape_element;
private:
int Tape_Head = 0; // Can be negative
std::vector<tape_element> Left; // Stores left expansion
std::vector<tape_element> Right; // Stores right expansion

tape_element& operator[](int index)
{
return index >= 0 ? Right[index] : Left[-index - 1];
}

public:
Tape_Type(){ Right.push_back('_'); } // constructor
void Write(tape_element Y){ (*this)[Tape_Head] = Y; };
tape_element Read() { return (*this)[Tape_Head]; };

void move_left()
{
Tape_Head--;
int Left_Index = ((Tape_Head * -1) -1);
if (Left_Index == Left.size())
Left.push_back('_');
}

void move_right()
{
Tape_Head++;
if (Tape_Head == Right.size())
Right.push_back('_');
}

void Output()
{
printf("Tape_Type::Output()\n");
if (Left.size())
{
int Last_One = Left.size() - 1;
for (int N = Last_One; N >= 0; N--)
{
int TH = (N + 1) * -1; // determine Tape_Head from N
printf("[%04d]:%c Left[%02d]\n", TH, Left[N], N);
}
}
if (Right.size())
for (int N = 0; N < Right.size(); N++)
printf("[%04d]:%c Right[%02d]\n", N, Right[N], N);
}
};

--
Copyright 2022 Pete Olcott

"Talent hits a target no one else can hit;
Genius hits a target no one else can see."
Arthur Schopenhauer

Re: Implementing a two-way Turing Machine tape as an improvement to std::deque

<20220513015816.00006f57@reddwarf.jmc>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=32251&group=comp.theory#32251

  copy link   Newsgroups: comp.theory comp.ai.philosophy comp.lang.c comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.roellig-ltd.de!open-news-network.org!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx04.ams4.POSTED!not-for-mail
From: flib...@reddwarf.jmc (Mr Flibble)
Newsgroups: comp.theory,comp.ai.philosophy,comp.lang.c,comp.lang.c++
Subject: Re: Implementing a two-way Turing Machine tape as an improvement to
std::deque
Message-ID: <20220513015816.00006f57@reddwarf.jmc>
References: <cNWdnXqV1cXzEuD_nZ2dnUU7_8zNnZ2d@giganews.com>
<20220512235610.00004914@reddwarf.jmc>
<Vf2dnR9fAewpDuD_nZ2dnUU7_8xh4p2d@giganews.com>
<20220513002218.00003fa0@reddwarf.jmc>
<-s-dncjVifoXB-D_nZ2dnUU7_83NnZ2d@giganews.com>
<20220513004049.00000d64@reddwarf.jmc>
<HYudneQqVdKFAOD_nZ2dnUU7_83NnZ2d@giganews.com>
<20220513005340.00001694@reddwarf.jmc>
<Bo-dnemL1eT6P-D_nZ2dnUU7_81g4p2d@giganews.com>
Organization: Jupiter Mining Corp
X-Newsreader: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-w64-mingw32)
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Lines: 145
X-Complaints-To: abuse@eweka.nl
NNTP-Posting-Date: Fri, 13 May 2022 00:58:15 UTC
Date: Fri, 13 May 2022 01:58:16 +0100
X-Received-Bytes: 6745
 by: Mr Flibble - Fri, 13 May 2022 00:58 UTC

On Thu, 12 May 2022 19:12:22 -0500
olcott <NoOne@NoWhere.com> wrote:

> On 5/12/2022 6:53 PM, Mr Flibble wrote:
> > On Thu, 12 May 2022 18:49:43 -0500
> > olcott <NoOne@NoWhere.com> wrote:
> >
> >> On 5/12/2022 6:40 PM, Mr Flibble wrote:
> >>> On Thu, 12 May 2022 18:38:49 -0500
> >>> olcott <NoOne@NoWhere.com> wrote:
> >>>
> >>>> On 5/12/2022 6:22 PM, Mr Flibble wrote:
> >>>>> On Thu, 12 May 2022 18:09:39 -0500
> >>>>> olcott <NoOne@NoWhere.com> wrote:
> >>>>>
> >>>>>> On 5/12/2022 5:56 PM, Mr Flibble wrote:
> >>>>>>> On Thu, 12 May 2022 17:51:25 -0500
> >>>>>>> olcott <NoOne@NoWhere.com> wrote:
> >>>>>>>
> >>>>>>>> C/C++ people please critique this as the basis for an
> >>>>>>>> improvement to std::deque. It seems to have the key
> >>>>>>>> functionality of std::deque and does it much more simply
> >>>>>>>> while saving time and space.
> >>>>>>>> https://www.cplusplus.com/reference/deque/deque/
> >>>>>>>>
> >>>>>>>> #define tape_element unsigned char
> >>>>>>>>
> >>>>>>>> class Tape_Type
> >>>>>>>> {
> >>>>>>>> private:
> >>>>>>>> int Tape_Head = 0; // Can be negative
> >>>>>>>> std::vector<tape_element> Left; // Stores left
> >>>>>>>> expansion std::vector<tape_element> Right; // Stores right
> >>>>>>>> expansion tape_element & operator[](int index);
> >>>>>>>>
> >>>>>>>> public:
> >>>>>>>> void move_left(); // Tape_Head--;
> >>>>>>>> Left.push_back(0); as needed void move_right(); //
> >>>>>>>> Tape_Head++; Left.push_back(0); as needed void
> >>>>>>>> Write(tape_element Y){ this->operator[](Tape_Head) = Y; };
> >>>>>>>> tape_element Read() { return
> >>>>>>>> this->operator[](Tape_Head); }; Tape_Type(){
> >>>>>>>> Right.push_back('_'); } // constructor void Output(); };
> >>>>>>>>
> >>>>>>>> tape_element& Tape_Type::operator[](int index)
> >>>>>>>> {
> >>>>>>>> if (index > 0)
> >>>>>>>> return Right[index];
> >>>>>>>> int Left_Index = ((index * -1) -1);
> >>>>>>>> return Left[Left_Index];
> >>>>>>>> }
> >>>>>>>>
> >>>>>>>> void Tape_Type::Output()
> >>>>>>>> {
> >>>>>>>> printf("Tape_Type::Output()\n");
> >>>>>>>>
> >>>>>>>> if (Left.size())
> >>>>>>>> {
> >>>>>>>> int Last_One = Left.size() - 1;
> >>>>>>>> for (int N = Last_One; N >= 0; N--)
> >>>>>>>> {
> >>>>>>>> int TH = (N + 1) * -1; // determine Tape_Head
> >>>>>>>> from N printf("[%04d]:%c Left[%02d]\n", TH, Left[N], N);
> >>>>>>>> }
> >>>>>>>> }
> >>>>>>>> if (Right.size())
> >>>>>>>> for (int N = 0; N < Right.size(); N++)
> >>>>>>>> printf("[%04d]:%c Right[%02d]\n", N, Right[N],
> >>>>>>>> N); }
> >>>>>>>>
> >>>>>>>> void Tape_Type::move_left()
> >>>>>>>> {
> >>>>>>>> Tape_Head--;
> >>>>>>>> int Left_Index = ((Tape_Head * -1) -1);
> >>>>>>>> if (Left_Index == Left.size())
> >>>>>>>> Left.push_back('_');
> >>>>>>>> }
> >>>>>>>>
> >>>>>>>> void Tape_Type::move_right()
> >>>>>>>> {
> >>>>>>>> Tape_Head++;
> >>>>>>>> if (Tape_Head == Right.size())
> >>>>>>>> Right.push_back('_');
> >>>>>>>> }
> >>>>>>>
> >>>>>>> It might be a more appropriate solution than std::deque for
> >>>>>>> your specific use-case however it is NOT an improvement to
> >>>>>>> std::deque for the general case -- see my reply in the other
> >>>>>>> thread for why.
> >>>>>>>
> >>>>>>> /Flibble
> >>>>>>>
> >>>>>>
> >>>>>> I didn't see any reason why it would not make a better
> >>>>>> std::deque.
> >>>>>
> >>>>> Because it doesn't meet the complexity and referential integrity
> >>>>> requirements of std::deque.
> >>>>>
> >>>>> /Flibble
> >>>>>
> >>>>
> >>>> It is faster then std::deque.
> >>>> I couldn't find what you mean by referential integrity it has too
> >>>> many different meanings. invalidating iterators seemed to be what
> >>>> you mean otherwise I have no idea.
> >>>
> >>> I see you are choosing to ignore my reply in the other thread.
> >>> OK, I will repost why you are wrong here:
> >>>
> >>> * referential integrity and iterator invalidation are different
> >>> things: when you add or remove elements to either end of a
> >>> std::deque iterators are indeed invalidated however
> >>> references to existing elements remain valid
> >>
> >> Mine words the same way and has the added benefit of contiguous
> >> storage.
> >>
> >>> * If you do 1000 push_fronts followed by 1000 push_backs
> >>> followed by 1000 pop_fronts all is good however your next
> >>> pop_front will have linear complexity, O(n), as it will
> >>> necessitate removal of the first element of the right
> >>> std::vector.
> >>
> >> I don't think that this applies to the way that I implemented it.
> >> pop_front pops from the end of Left. pop_back pops from the end of
> >> Right. This is the key aspect that I used from David's two-stack
> >> approach.
> >
> > Then it is totally different to what std::deque offers: std::deque
> > allows ALL elements to be either popped from the front or back. Try
> > reading AND UNDERSTANDING what I wrote again.
> >
> > /Flibble
> >
>
> I could allow all elements to be popped from the front or the back
> too. Mine is much faster when you need far less than all elements.
What you have does not offer what std::deque offers so is not
equivalent to std::deque so can't be considered better than std::deque
for the general case (I don't care about your specific use-case).

/Flibble

Re: Implementing a two-way Turing Machine tape as an improvement to std::deque

<20220513020134.00003f42@reddwarf.jmc>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=32252&group=comp.theory#32252

  copy link   Newsgroups: comp.theory comp.lang.c++
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx04.ams4.POSTED!not-for-mail
From: flib...@reddwarf.jmc (Mr Flibble)
Newsgroups: comp.theory,comp.lang.c++
Subject: Re: Implementing a two-way Turing Machine tape as an improvement to
std::deque
Message-ID: <20220513020134.00003f42@reddwarf.jmc>
References: <cNWdnXqV1cXzEuD_nZ2dnUU7_8zNnZ2d@giganews.com>
<87wneq1ejm.fsf@bsb.me.uk>
<MeOdncpeZacPMeD_nZ2dnUU7_8zNnZ2d@giganews.com>
Organization: Jupiter Mining Corp
X-Newsreader: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-w64-mingw32)
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Lines: 39
X-Complaints-To: abuse@eweka.nl
NNTP-Posting-Date: Fri, 13 May 2022 01:01:33 UTC
Date: Fri, 13 May 2022 02:01:34 +0100
X-Received-Bytes: 2218
 by: Mr Flibble - Fri, 13 May 2022 01:01 UTC

On Thu, 12 May 2022 19:55:44 -0500
olcott <NoOne@NoWhere.com> wrote:

> On 5/12/2022 7:06 PM, Ben wrote:
> > olcott <NoOne@NoWhere.com> writes:
> >
> > I've removed the philosophy group and comp.lang.c as this is C++.
> >
> >> C/C++ people please critique this as the basis for an improvement
> >> to std::deque.
> >
> > You will get critiques of the code on whatever basis people feel
> > inclined to comment! You can't limit the comments to some
> > particular context.
> >
> >> It seems to have the key functionality of std::deque and
> >> does it much more simply while saving time and space.
> >
> > It does not have any of the functionality of std::deque.
>
> That is a ridiculously stupid thing to say. It has the key most
> important functionality of a std:deque
>
> Double ended queue
> deque (usually pronounced like "deck") is an irregular acronym of
> double-ended queue. Double-ended queues are sequence containers with
> dynamic sizes that can be expanded or contracted on both ends (either
> its front or its back).
>
> All of the rest of the functionality of std::deque can be added as
> needed.

Not with your chosen data structure of two std::vectors it can't as it
wouldn't meet the complexity and referential integrity
requirements offered by std::deque. I have told you this three times
now.

/Flibble

Re: Implementing a two-way Turing Machine tape as an improvement to std::deque

<D7WdnSjo4swvKOD_nZ2dnUU7_81g4p2d@giganews.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=32256&group=comp.theory#32256

  copy link   Newsgroups: comp.theory comp.ai.philosophy comp.lang.c comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!buffer2.nntp.dca1.giganews.com!buffer1.nntp.dca1.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Thu, 12 May 2022 20:34:42 -0500
Date: Thu, 12 May 2022 20:34:41 -0500
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Subject: Re: Implementing a two-way Turing Machine tape as an improvement to
std::deque
Content-Language: en-US
Newsgroups: comp.theory,comp.ai.philosophy,comp.lang.c,comp.lang.c++
References: <cNWdnXqV1cXzEuD_nZ2dnUU7_8zNnZ2d@giganews.com>
<20220512235610.00004914@reddwarf.jmc>
<Vf2dnR9fAewpDuD_nZ2dnUU7_8xh4p2d@giganews.com>
<20220513002218.00003fa0@reddwarf.jmc>
<-s-dncjVifoXB-D_nZ2dnUU7_83NnZ2d@giganews.com>
<20220513004049.00000d64@reddwarf.jmc>
<HYudneQqVdKFAOD_nZ2dnUU7_83NnZ2d@giganews.com>
<20220513005340.00001694@reddwarf.jmc>
<Bo-dnemL1eT6P-D_nZ2dnUU7_81g4p2d@giganews.com>
<20220513015816.00006f57@reddwarf.jmc>
From: NoO...@NoWhere.com (olcott)
In-Reply-To: <20220513015816.00006f57@reddwarf.jmc>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <D7WdnSjo4swvKOD_nZ2dnUU7_81g4p2d@giganews.com>
Lines: 159
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-iUPOWC+2qIQq3WJ49fnjT5ZzYOzHHnh3LpiU1Ft3OHDbfP0v6kIDeGcodGDAd7qpahYjgnUOJTIJbdB!7cabS8H8GCd2J+Jvs/JvVqi0zvIGwDPnyyOYcAbjO1XW6lLswSEGkvrxLndFmPYI52JTJajFs9Y=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 7802
 by: olcott - Fri, 13 May 2022 01:34 UTC

On 5/12/2022 7:58 PM, Mr Flibble wrote:
> On Thu, 12 May 2022 19:12:22 -0500
> olcott <NoOne@NoWhere.com> wrote:
>
>> On 5/12/2022 6:53 PM, Mr Flibble wrote:
>>> On Thu, 12 May 2022 18:49:43 -0500
>>> olcott <NoOne@NoWhere.com> wrote:
>>>
>>>> On 5/12/2022 6:40 PM, Mr Flibble wrote:
>>>>> On Thu, 12 May 2022 18:38:49 -0500
>>>>> olcott <NoOne@NoWhere.com> wrote:
>>>>>
>>>>>> On 5/12/2022 6:22 PM, Mr Flibble wrote:
>>>>>>> On Thu, 12 May 2022 18:09:39 -0500
>>>>>>> olcott <NoOne@NoWhere.com> wrote:
>>>>>>>
>>>>>>>> On 5/12/2022 5:56 PM, Mr Flibble wrote:
>>>>>>>>> On Thu, 12 May 2022 17:51:25 -0500
>>>>>>>>> olcott <NoOne@NoWhere.com> wrote:
>>>>>>>>>
>>>>>>>>>> C/C++ people please critique this as the basis for an
>>>>>>>>>> improvement to std::deque. It seems to have the key
>>>>>>>>>> functionality of std::deque and does it much more simply
>>>>>>>>>> while saving time and space.
>>>>>>>>>> https://www.cplusplus.com/reference/deque/deque/
>>>>>>>>>>
>>>>>>>>>> #define tape_element unsigned char
>>>>>>>>>>
>>>>>>>>>> class Tape_Type
>>>>>>>>>> {
>>>>>>>>>> private:
>>>>>>>>>> int Tape_Head = 0; // Can be negative
>>>>>>>>>> std::vector<tape_element> Left; // Stores left
>>>>>>>>>> expansion std::vector<tape_element> Right; // Stores right
>>>>>>>>>> expansion tape_element & operator[](int index);
>>>>>>>>>>
>>>>>>>>>> public:
>>>>>>>>>> void move_left(); // Tape_Head--;
>>>>>>>>>> Left.push_back(0); as needed void move_right(); //
>>>>>>>>>> Tape_Head++; Left.push_back(0); as needed void
>>>>>>>>>> Write(tape_element Y){ this->operator[](Tape_Head) = Y; };
>>>>>>>>>> tape_element Read() { return
>>>>>>>>>> this->operator[](Tape_Head); }; Tape_Type(){
>>>>>>>>>> Right.push_back('_'); } // constructor void Output(); };
>>>>>>>>>>
>>>>>>>>>> tape_element& Tape_Type::operator[](int index)
>>>>>>>>>> {
>>>>>>>>>> if (index > 0)
>>>>>>>>>> return Right[index];
>>>>>>>>>> int Left_Index = ((index * -1) -1);
>>>>>>>>>> return Left[Left_Index];
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>> void Tape_Type::Output()
>>>>>>>>>> {
>>>>>>>>>> printf("Tape_Type::Output()\n");
>>>>>>>>>>
>>>>>>>>>> if (Left.size())
>>>>>>>>>> {
>>>>>>>>>> int Last_One = Left.size() - 1;
>>>>>>>>>> for (int N = Last_One; N >= 0; N--)
>>>>>>>>>> {
>>>>>>>>>> int TH = (N + 1) * -1; // determine Tape_Head
>>>>>>>>>> from N printf("[%04d]:%c Left[%02d]\n", TH, Left[N], N);
>>>>>>>>>> }
>>>>>>>>>> }
>>>>>>>>>> if (Right.size())
>>>>>>>>>> for (int N = 0; N < Right.size(); N++)
>>>>>>>>>> printf("[%04d]:%c Right[%02d]\n", N, Right[N],
>>>>>>>>>> N); }
>>>>>>>>>>
>>>>>>>>>> void Tape_Type::move_left()
>>>>>>>>>> {
>>>>>>>>>> Tape_Head--;
>>>>>>>>>> int Left_Index = ((Tape_Head * -1) -1);
>>>>>>>>>> if (Left_Index == Left.size())
>>>>>>>>>> Left.push_back('_');
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>> void Tape_Type::move_right()
>>>>>>>>>> {
>>>>>>>>>> Tape_Head++;
>>>>>>>>>> if (Tape_Head == Right.size())
>>>>>>>>>> Right.push_back('_');
>>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> It might be a more appropriate solution than std::deque for
>>>>>>>>> your specific use-case however it is NOT an improvement to
>>>>>>>>> std::deque for the general case -- see my reply in the other
>>>>>>>>> thread for why.
>>>>>>>>>
>>>>>>>>> /Flibble
>>>>>>>>>
>>>>>>>>
>>>>>>>> I didn't see any reason why it would not make a better
>>>>>>>> std::deque.
>>>>>>>
>>>>>>> Because it doesn't meet the complexity and referential integrity
>>>>>>> requirements of std::deque.
>>>>>>>
>>>>>>> /Flibble
>>>>>>>
>>>>>>
>>>>>> It is faster then std::deque.
>>>>>> I couldn't find what you mean by referential integrity it has too
>>>>>> many different meanings. invalidating iterators seemed to be what
>>>>>> you mean otherwise I have no idea.
>>>>>
>>>>> I see you are choosing to ignore my reply in the other thread.
>>>>> OK, I will repost why you are wrong here:
>>>>>
>>>>> * referential integrity and iterator invalidation are different
>>>>> things: when you add or remove elements to either end of a
>>>>> std::deque iterators are indeed invalidated however
>>>>> references to existing elements remain valid
>>>>
>>>> Mine words the same way and has the added benefit of contiguous
>>>> storage.
>>>>
>>>>> * If you do 1000 push_fronts followed by 1000 push_backs
>>>>> followed by 1000 pop_fronts all is good however your next
>>>>> pop_front will have linear complexity, O(n), as it will
>>>>> necessitate removal of the first element of the right
>>>>> std::vector.
>>>>
>>>> I don't think that this applies to the way that I implemented it.
>>>> pop_front pops from the end of Left. pop_back pops from the end of
>>>> Right. This is the key aspect that I used from David's two-stack
>>>> approach.
>>>
>>> Then it is totally different to what std::deque offers: std::deque
>>> allows ALL elements to be either popped from the front or back. Try
>>> reading AND UNDERSTANDING what I wrote again.
>>>
>>> /Flibble
>>>
>>
>> I could allow all elements to be popped from the front or the back
>> too. Mine is much faster when you need far less than all elements.
>
> What you have does not offer what std::deque offers so is not

All these things can be added and we end up with a simple, faster,
std:deque that has most the conventional overhead and complexity abolished.

> equivalent to std::deque so can't be considered better than std::deque
> for the general case (I don't care about your specific use-case).
>
> /Flibble
>

It just a matter of defining more member functions.

--
Copyright 2022 Pete Olcott

"Talent hits a target no one else can hit;
Genius hits a target no one else can see."
Arthur Schopenhauer


Click here to read the complete article
Re: Implementing a two-way Turing Machine tape as an improvement to std::deque

<D7WdnSvo4syeK-D_nZ2dnUU7_81g4p2d@giganews.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=32257&group=comp.theory#32257

  copy link   Newsgroups: comp.theory comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!buffer2.nntp.dca1.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Thu, 12 May 2022 20:36:03 -0500
Date: Thu, 12 May 2022 20:36:02 -0500
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Subject: Re: Implementing a two-way Turing Machine tape as an improvement to
std::deque
Content-Language: en-US
Newsgroups: comp.theory,comp.lang.c++
References: <cNWdnXqV1cXzEuD_nZ2dnUU7_8zNnZ2d@giganews.com>
<87wneq1ejm.fsf@bsb.me.uk> <MeOdncpeZacPMeD_nZ2dnUU7_8zNnZ2d@giganews.com>
<20220513020134.00003f42@reddwarf.jmc>
From: NoO...@NoWhere.com (olcott)
In-Reply-To: <20220513020134.00003f42@reddwarf.jmc>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <D7WdnSvo4syeK-D_nZ2dnUU7_81g4p2d@giganews.com>
Lines: 55
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-A9Gv6vYqzP+MasjHw0NOT4UXjjS/qr/IWvOWXVirxQ/dg/HhQVGo7CRuRvMFQadW7dkYcRbLa5YkQLo!5o2W9Ljiu8750LFayIudwg/PspKaBwp1vO3se/NpL6tFZaojT2Z6Mdmpum3Th0BsglNqVjKecHk=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 3039
 by: olcott - Fri, 13 May 2022 01:36 UTC

On 5/12/2022 8:01 PM, Mr Flibble wrote:
> On Thu, 12 May 2022 19:55:44 -0500
> olcott <NoOne@NoWhere.com> wrote:
>
>> On 5/12/2022 7:06 PM, Ben wrote:
>>> olcott <NoOne@NoWhere.com> writes:
>>>
>>> I've removed the philosophy group and comp.lang.c as this is C++.
>>>
>>>> C/C++ people please critique this as the basis for an improvement
>>>> to std::deque.
>>>
>>> You will get critiques of the code on whatever basis people feel
>>> inclined to comment! You can't limit the comments to some
>>> particular context.
>>>
>>>> It seems to have the key functionality of std::deque and
>>>> does it much more simply while saving time and space.
>>>
>>> It does not have any of the functionality of std::deque.
>>
>> That is a ridiculously stupid thing to say. It has the key most
>> important functionality of a std:deque
>>
>> Double ended queue
>> deque (usually pronounced like "deck") is an irregular acronym of
>> double-ended queue. Double-ended queues are sequence containers with
>> dynamic sizes that can be expanded or contracted on both ends (either
>> its front or its back).
>>
>> All of the rest of the functionality of std::deque can be added as
>> needed.
>
> Not with your chosen data structure of two std::vectors it can't as it
> wouldn't meet the complexity

It already has the same complexity.

> and referential integrity

and better referential integrity.

> requirements offered by std::deque. I have told you this three times
> now.
>
> /Flibble
>

--
Copyright 2022 Pete Olcott

"Talent hits a target no one else can hit;
Genius hits a target no one else can see."
Arthur Schopenhauer

Re: Implementing a two-way Turing Machine tape as an improvement to std::deque

<8735he1abh.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=32259&group=comp.theory#32259

  copy link   Newsgroups: comp.theory
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben)
Newsgroups: comp.theory
Subject: Re: Implementing a two-way Turing Machine tape as an improvement to std::deque
Date: Fri, 13 May 2022 02:38:10 +0100
Organization: A noiseless patient Spider
Lines: 195
Message-ID: <8735he1abh.fsf@bsb.me.uk>
References: <cNWdnXqV1cXzEuD_nZ2dnUU7_8zNnZ2d@giganews.com>
<87wneq1ejm.fsf@bsb.me.uk>
<MeOdncpeZacPMeD_nZ2dnUU7_8zNnZ2d@giganews.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="9d7070da1378146bf8b2ebf4ad06ac0b";
logging-data="29579"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19T1cHlOodjwX38hEf1gnMoWrEDpFiFDSs="
Cancel-Lock: sha1:+b3tEGuNgF85QBa9hDx/CgE/MU0=
sha1:5tFqZYytOssUVGFVk1uPShtzDtY=
X-BSB-Auth: 1.f4974450f4a78963d14e.20220513023810BST.8735he1abh.fsf@bsb.me.uk
 by: Ben - Fri, 13 May 2022 01:38 UTC

olcott <NoOne@NoWhere.com> writes:

> On 5/12/2022 7:06 PM, Ben wrote:
>> olcott <NoOne@NoWhere.com> writes:
>> I've removed the philosophy group and comp.lang.c as this is C++.
>>
>>> C/C++ people please critique this as the basis for an improvement to
>>> std::deque.
>> You will get critiques of the code on whatever basis people feel
>> inclined to comment! You can't limit the comments to some particular
>> context.
>>
>>> It seems to have the key functionality of std::deque and
>>> does it much more simply while saving time and space.
>> It does not have any of the functionality of std::deque.
>
> That is a ridiculously stupid thing to say. It has the key most
> important functionality of a std:deque

Generally, when you think I am saying something absurd, you should
re-consider.

A deque has (at least) these operations:

front
back
pop_front
push_front
pop_back
push_back

Your Tape_Type has none of these. Even internally it does not maintain
the right data to be able to provide them.

> Double ended queue
> deque (usually pronounced like "deck") is an irregular acronym of
> double-ended queue. Double-ended queues are sequence containers with
> dynamic sizes that can be expanded or contracted on both ends (either
> its front or its back).
>
> All of the rest of the functionality of std::deque can be added as
> needed.

You mean you could implement a deque using two arrays if you chose to?
So what? All I am saying is that you haven't got a deque.

>> There is a
>> commonly used (though not particularly efficient) way to implement a
>> deque using two arrays, but this is not it.
>>
>>> #define tape_element unsigned char
>> Use a typedef or using declaration. Also, I'd put the typedef in the
>> class as the type belongs to the class (as least that appears to be the
>> case from the name you've chosen).
>>
>>> class Tape_Type
>>> {
>>> private:
>>> int Tape_Head = 0; // Can be negative
>>> std::vector<tape_element> Left; // Stores left expansion
>>> std::vector<tape_element> Right; // Stores right expansion
>>> tape_element & operator[](int index);
>>>
>>> public:
>>> void move_left(); // Tape_Head--; Left.push_back(0); as needed
>>> void move_right(); // Tape_Head++; Left.push_back(0); as needed
>> The comments are wrong since you push_back('_').
>>
>>> void Write(tape_element Y){ this->operator[](Tape_Head) = Y; };
>>> tape_element Read() { return this->operator[](Tape_Head); };
>> I'd write (*this)[Tape_Head] but I suppose that's just a matter of style.
>>
>>> Tape_Type(){ Right.push_back('_'); } // constructor
>> The constructor leaves a Tape_Type object in an unusable state, but
>> that's due to a bug in operator[]. Did you test?
>
> Yes I tested so I don't see what you mean.

Testing should have caught the bug in operator[].

>>> void Output();
>>> };
>>>
>>> tape_element& Tape_Type::operator[](int index)
>>> {
>>> if (index > 0)
>>> return Right[index];
>> Bug. You meant index >= 0 I think.
>
> Yes Richard caught that. That was a new refactoring.
>>
>>> int Left_Index = ((index * -1) -1);
>> Why not -index - 1?
>>
>>> return Left[Left_Index];
>> Do you think introducing a new variable really make the code clearer
>> that simply writing
>> return Left[-index - 1];
>> ? Personally, I'd write the whole thing as
>> return index >= 0 ? Right[index] : Left[-index - 1];
>>
>>> }
>>>
>>> void Tape_Type::Output()
>>> {
>>> printf("Tape_Type::Output()\n");
>>>
>>> if (Left.size())
>>> {
>>> int Last_One = Left.size() - 1;
>>> for (int N = Last_One; N >= 0; N--)
>>> {
>>> int TH = (N + 1) * -1; // determine Tape_Head from N
>>> printf("[%04d]:%c Left[%02d]\n", TH, Left[N], N);
>>> }
>>> }
>>> if (Right.size())
>>> for (int N = 0; N < Right.size(); N++)
>>> printf("[%04d]:%c Right[%02d]\n", N, Right[N], N);
>>> }
>>>
>>> void Tape_Type::move_left()
>>> {
>>> Tape_Head--;
>>> int Left_Index = ((Tape_Head * -1) -1);
>>> if (Left_Index == Left.size())
>>> Left.push_back('_');
>>> }
>>>
>>> void Tape_Type::move_right()
>>> {
>>> Tape_Head++;
>>> if (Tape_Head == Right.size())
>>> Right.push_back('_');
>>> }
>>
>> I find the capitalisation odd and unhelpful as there does not seem to be
>> any consistency about it.
>
> I found all of your suggestions very helpful.
> I don't see the bug in the constructor.

There is none. I just said the constructor leaves the tape unusable
because of the bug in operator[].

> I like mixed case because it is easier to read, mine not be consistent.
>
> Here they are implemented.
>
> //
> // Tape_Type implements a two-way Turing machine tape.
> // Right contains Tape_Head >= 0 values (right expansion)
> // Left contains Tape_Head < 0 values (left expansion)
> //
> // Tape_Type has functionality very similar to std::deque

This comment is not correct.

> // yet implements this functionality much more simply.
> // This saves time and space.
> //
> class Tape_Type
> {
> typedef unsigned char tape_element;

You probably want that to be a public typedef. And now that it's in the
class, the name can be sorter. The usual convention is _t for types:

typedef unsigned char element_t;

I plugged your tape class into my C++ TM interpreter and it made it
slightly slower for the "big" BB(5) test compared with my naive tape
that just uses a single string.

Note: this is not a comment on the design of your tape. There's nothing
wrong with it (except a little inconvenience, see below). The speed
will be determined almost entirely by how std::string and std::vector
are implemented. You might see completely different timings just by
linking with a different library.

Mind you, I prefer using a string to all the other methods I've tried
because it's so convenient. You can set up the TM with an input simply
by writing

tape = input

and you can debug by printing the tape any time you like. And I use a
string_view to get the non-blank "result" out of the TM and the end of a
run. All easy to get round with a couple of functions, but still, since
it's fast I see no reason t change.

--
Ben.
"le génie humain a des limites, quand la bêtise humaine n’en a pas"
Alexandre Dumas (fils)

Re: Implementing a two-way Turing Machine tape as an improvement to std::deque

<692dnROYz_PMWeD_nZ2dnUU7_83NnZ2d@giganews.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=32264&group=comp.theory#32264

  copy link   Newsgroups: comp.theory
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!buffer2.nntp.dca1.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Thu, 12 May 2022 21:37:05 -0500
Date: Thu, 12 May 2022 21:37:03 -0500
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Subject: Re: Implementing a two-way Turing Machine tape as an improvement to
std::deque
Content-Language: en-US
Newsgroups: comp.theory
References: <cNWdnXqV1cXzEuD_nZ2dnUU7_8zNnZ2d@giganews.com>
<87wneq1ejm.fsf@bsb.me.uk> <MeOdncpeZacPMeD_nZ2dnUU7_8zNnZ2d@giganews.com>
<8735he1abh.fsf@bsb.me.uk>
From: NoO...@NoWhere.com (olcott)
In-Reply-To: <8735he1abh.fsf@bsb.me.uk>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <692dnROYz_PMWeD_nZ2dnUU7_83NnZ2d@giganews.com>
Lines: 233
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-lihfM50aLlo9robcHLXB8QDI1aJCYDrlg596SU4jVnU8A33ywqSDuEdR7QUzPOtY//3CsYYoNqFaEfo!MQH6Otu96d03NYgRDMDkJKtH8qau/v3SfAe+XH3uji1Cv+KB1NmqEVI0JOecFmdah/w8D1MeOAs=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 9207
 by: olcott - Fri, 13 May 2022 02:37 UTC

On 5/12/2022 8:38 PM, Ben wrote:
> olcott <NoOne@NoWhere.com> writes:
>
>> On 5/12/2022 7:06 PM, Ben wrote:
>>> olcott <NoOne@NoWhere.com> writes:
>>> I've removed the philosophy group and comp.lang.c as this is C++.
>>>
>>>> C/C++ people please critique this as the basis for an improvement to
>>>> std::deque.
>>> You will get critiques of the code on whatever basis people feel
>>> inclined to comment! You can't limit the comments to some particular
>>> context.
>>>
>>>> It seems to have the key functionality of std::deque and
>>>> does it much more simply while saving time and space.
>>> It does not have any of the functionality of std::deque.
>>
>> That is a ridiculously stupid thing to say. It has the key most
>> important functionality of a std:deque
>
> Generally, when you think I am saying something absurd, you should
> re-consider.
>
> A deque has (at least) these operations:
>
> front
> back
> push_front
> push_back
> pop_front
> pop_back
>
> Your Tape_Type has none of these. Even internally it does not maintain
> the right data to be able to provide them.

I also added a reserve so you could do a pre-allocated speed test.

It was easy to add these in terms of the current implementation:

public:
tape_element& front( ) { return Left.back(); }
tape_element& back() { return Right.back(); }
void pop_front() { Left.pop_back(); }
void pop_back() { Right.pop_back(); }
void push_front(tape_element& E) { Left.push_back(E); }
void push_back(tape_element& E) { Right.push_back(E); }

void reserve(unsigned int N)
{ Left.reserve(N); Right.reserve(N); }

>> Double ended queue
>> deque (usually pronounced like "deck") is an irregular acronym of
>> double-ended queue. Double-ended queues are sequence containers with
>> dynamic sizes that can be expanded or contracted on both ends (either
>> its front or its back).
>>
>> All of the rest of the functionality of std::deque can be added as
>> needed.
>
> You mean you could implement a deque using two arrays if you chose to?
> So what? All I am saying is that you haven't got a deque.

If I added these things then I would have a much better deque.

>>> There is a
>>> commonly used (though not particularly efficient) way to implement a
>>> deque using two arrays, but this is not it.
>>>
>>>> #define tape_element unsigned char
>>> Use a typedef or using declaration. Also, I'd put the typedef in the
>>> class as the type belongs to the class (as least that appears to be the
>>> case from the name you've chosen).
>>>
>>>> class Tape_Type
>>>> {
>>>> private:
>>>> int Tape_Head = 0; // Can be negative
>>>> std::vector<tape_element> Left; // Stores left expansion
>>>> std::vector<tape_element> Right; // Stores right expansion
>>>> tape_element & operator[](int index);
>>>>
>>>> public:
>>>> void move_left(); // Tape_Head--; Left.push_back(0); as needed
>>>> void move_right(); // Tape_Head++; Left.push_back(0); as needed
>>> The comments are wrong since you push_back('_').
>>>
>>>> void Write(tape_element Y){ this->operator[](Tape_Head) = Y; };
>>>> tape_element Read() { return this->operator[](Tape_Head); };
>>> I'd write (*this)[Tape_Head] but I suppose that's just a matter of style.
>>>
>>>> Tape_Type(){ Right.push_back('_'); } // constructor
>>> The constructor leaves a Tape_Type object in an unusable state, but
>>> that's due to a bug in operator[]. Did you test?
>>
>> Yes I tested so I don't see what you mean.
>
> Testing should have caught the bug in operator[].

It is was a new refactoring of existing working code.

>>>> void Output();
>>>> };
>>>>
>>>> tape_element& Tape_Type::operator[](int index)
>>>> {
>>>> if (index > 0)
>>>> return Right[index];
>>> Bug. You meant index >= 0 I think.
>>
>> Yes Richard caught that. That was a new refactoring.
>>>
>>>> int Left_Index = ((index * -1) -1);
>>> Why not -index - 1?
>>>
>>>> return Left[Left_Index];
>>> Do you think introducing a new variable really make the code clearer
>>> that simply writing
>>> return Left[-index - 1];
>>> ? Personally, I'd write the whole thing as
>>> return index >= 0 ? Right[index] : Left[-index - 1];
>>>
>>>> }
>>>>
>>>> void Tape_Type::Output()
>>>> {
>>>> printf("Tape_Type::Output()\n");
>>>>
>>>> if (Left.size())
>>>> {
>>>> int Last_One = Left.size() - 1;
>>>> for (int N = Last_One; N >= 0; N--)
>>>> {
>>>> int TH = (N + 1) * -1; // determine Tape_Head from N
>>>> printf("[%04d]:%c Left[%02d]\n", TH, Left[N], N);
>>>> }
>>>> }
>>>> if (Right.size())
>>>> for (int N = 0; N < Right.size(); N++)
>>>> printf("[%04d]:%c Right[%02d]\n", N, Right[N], N);
>>>> }
>>>>
>>>> void Tape_Type::move_left()
>>>> {
>>>> Tape_Head--;
>>>> int Left_Index = ((Tape_Head * -1) -1);
>>>> if (Left_Index == Left.size())
>>>> Left.push_back('_');
>>>> }
>>>>
>>>> void Tape_Type::move_right()
>>>> {
>>>> Tape_Head++;
>>>> if (Tape_Head == Right.size())
>>>> Right.push_back('_');
>>>> }
>>>
>>> I find the capitalisation odd and unhelpful as there does not seem to be
>>> any consistency about it.
>>
>> I found all of your suggestions very helpful.
>> I don't see the bug in the constructor.
>
> There is none. I just said the constructor leaves the tape unusable
> because of the bug in operator[].

Oh, OK.

>
>> I like mixed case because it is easier to read, mine not be consistent.
>>
>> Here they are implemented.
>>
>> //
>> // Tape_Type implements a two-way Turing machine tape.
>> // Right contains Tape_Head >= 0 values (right expansion)
>> // Left contains Tape_Head < 0 values (left expansion)
>> //
>> // Tape_Type has functionality very similar to std::deque
>
> This comment is not correct.
>
>> // yet implements this functionality much more simply.
>> // This saves time and space.
>> //
>> class Tape_Type
>> {
>> typedef unsigned char tape_element;
>
> You probably want that to be a public typedef. And now that it's in the
> class, the name can be sorter. The usual convention is _t for types:
>
> typedef unsigned char element_t;
>
> I plugged your tape class into my C++ TM interpreter and it made it
> slightly slower for the "big" BB(5) test compared with my naive tape
> that just uses a single string.
>

std::string or char * ?
If char * was pre-allocated that would give it a big speed advantage.

I could add reserve(left/right):
void reserve(unsigned int N)
{ Left.reserve(N); Right.reserve(N); }

> Note: this is not a comment on the design of your tape. There's nothing
> wrong with it (except a little inconvenience, see below). The speed
> will be determined almost entirely by how std::string and std::vector
> are implemented. You might see completely different timings just by
> linking with a different library.
>
> Mind you, I prefer using a string to all the other methods I've tried
> because it's so convenient. You can set up the TM with an input simply
> by writing
>
> tape = input
>
> and you can debug by printing the tape any time you like. And I use a
> string_view to get the non-blank "result" out of the TM and the end of a
> run. All easy to get round with a couple of functions, but still, since
> it's fast I see no reason t change.
>


Click here to read the complete article
Re: Implementing a two-way Turing Machine tape as an improvement to std::deque

<t5kgdb$c1c$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=32265&group=comp.theory#32265

  copy link   Newsgroups: comp.theory
Path: i2pn2.org!i2pn.org!aioe.org!7a25jG6pUKCqa0zKnKnvdg.user.46.165.242.75.POSTED!not-for-mail
From: pyt...@example.invalid (Python)
Newsgroups: comp.theory
Subject: Re: Implementing a two-way Turing Machine tape as an improvement to
std::deque
Date: Fri, 13 May 2022 04:39:38 +0200
Organization: Aioe.org NNTP Server
Message-ID: <t5kgdb$c1c$1@gioia.aioe.org>
References: <cNWdnXqV1cXzEuD_nZ2dnUU7_8zNnZ2d@giganews.com>
<87wneq1ejm.fsf@bsb.me.uk> <MeOdncpeZacPMeD_nZ2dnUU7_8zNnZ2d@giganews.com>
<8735he1abh.fsf@bsb.me.uk> <692dnROYz_PMWeD_nZ2dnUU7_83NnZ2d@giganews.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="12332"; posting-host="7a25jG6pUKCqa0zKnKnvdg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:91.0)
Gecko/20100101 Thunderbird/91.9.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: fr
 by: Python - Fri, 13 May 2022 02:39 UTC

Peter Olcott wrote:
> On 5/12/2022 8:38 PM, Ben wrote:
>> olcott <NoOne@NoWhere.com> writes:
>>
>>> On 5/12/2022 7:06 PM, Ben wrote:
>>>> olcott <NoOne@NoWhere.com> writes:
>>>> I've removed the philosophy group and comp.lang.c as this is C++.
>>>>
>>>>> C/C++ people please critique this as the basis for an improvement to
>>>>> std::deque.
>>>> You will get critiques of the code on whatever basis people feel
>>>> inclined to comment!  You can't limit the comments to some particular
>>>> context.
>>>>
>>>>> It seems to have the key functionality of std::deque and
>>>>> does it much more simply while saving time and space.
>>>> It does not have any of the functionality of std::deque.
>>>
>>> That is a ridiculously stupid thing to say. It has the key most
>>> important functionality of a std:deque
>>
>> Generally, when you think I am saying something absurd, you should
>> re-consider.
>>
>> A deque has (at least) these operations:
>>
>>    front
>>    back
>>    push_front
>>    push_back
>>    pop_front
>>    pop_back
>>
>> Your Tape_Type has none of these.  Even internally it does not maintain
>> the right data to be able to provide them.
>
> I also added a reserve so you could do a pre-allocated speed test.
>
> It was easy to add these in terms of the current implementation:
>
> public:
>   tape_element& front( )      { return Left.back();       }
>   tape_element& back()        { return Right.back();      }
>   void pop_front()                  { Left.pop_back();    }
>   void pop_back()                   { Right.pop_back();   }
>   void push_front(tape_element& E)  { Left.push_back(E);  }
>   void push_back(tape_element& E)   { Right.push_back(E); }
>
>   void reserve(unsigned int N)
>                      { Left.reserve(N); Right.reserve(N); }

Could you add eggs, bacon and beans? Thanks Peter.

Re: Implementing a two-way Turing Machine tape as an improvement to std::deque

<20220513080247.000077d7@reddwarf.jmc>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=32269&group=comp.theory#32269

  copy link   Newsgroups: comp.theory comp.ai.philosophy comp.lang.c comp.lang.c++
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!feeder.usenetexpress.com!tr2.eu1.usenetexpress.com!81.171.65.13.MISMATCH!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx04.ams4.POSTED!not-for-mail
From: flib...@reddwarf.jmc (Mr Flibble)
Newsgroups: comp.theory,comp.ai.philosophy,comp.lang.c,comp.lang.c++
Subject: Re: Implementing a two-way Turing Machine tape as an improvement to std::deque
Message-ID: <20220513080247.000077d7@reddwarf.jmc>
References: <cNWdnXqV1cXzEuD_nZ2dnUU7_8zNnZ2d@giganews.com> <20220512235610.00004914@reddwarf.jmc> <Vf2dnR9fAewpDuD_nZ2dnUU7_8xh4p2d@giganews.com> <20220513002218.00003fa0@reddwarf.jmc> <-s-dncjVifoXB-D_nZ2dnUU7_83NnZ2d@giganews.com> <20220513004049.00000d64@reddwarf.jmc> <HYudneQqVdKFAOD_nZ2dnUU7_83NnZ2d@giganews.com> <20220513005340.00001694@reddwarf.jmc> <Bo-dnemL1eT6P-D_nZ2dnUU7_81g4p2d@giganews.com> <20220513015816.00006f57@reddwarf.jmc> <D7WdnSjo4swvKOD_nZ2dnUU7_81g4p2d@giganews.com>
Organization: Jupiter Mining Corp
X-Newsreader: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-w64-mingw32)
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Lines: 165
X-Complaints-To: abuse@eweka.nl
NNTP-Posting-Date: Fri, 13 May 2022 07:02:46 UTC
Date: Fri, 13 May 2022 08:02:47 +0100
X-Received-Bytes: 7714
 by: Mr Flibble - Fri, 13 May 2022 07:02 UTC

On Thu, 12 May 2022 20:34:41 -0500
olcott <NoOne@NoWhere.com> wrote:

> On 5/12/2022 7:58 PM, Mr Flibble wrote:
> > On Thu, 12 May 2022 19:12:22 -0500
> > olcott <NoOne@NoWhere.com> wrote:
> >
> >> On 5/12/2022 6:53 PM, Mr Flibble wrote:
> >>> On Thu, 12 May 2022 18:49:43 -0500
> >>> olcott <NoOne@NoWhere.com> wrote:
> >>>
> >>>> On 5/12/2022 6:40 PM, Mr Flibble wrote:
> >>>>> On Thu, 12 May 2022 18:38:49 -0500
> >>>>> olcott <NoOne@NoWhere.com> wrote:
> >>>>>
> >>>>>> On 5/12/2022 6:22 PM, Mr Flibble wrote:
> >>>>>>> On Thu, 12 May 2022 18:09:39 -0500
> >>>>>>> olcott <NoOne@NoWhere.com> wrote:
> >>>>>>>
> >>>>>>>> On 5/12/2022 5:56 PM, Mr Flibble wrote:
> >>>>>>>>> On Thu, 12 May 2022 17:51:25 -0500
> >>>>>>>>> olcott <NoOne@NoWhere.com> wrote:
> >>>>>>>>>
> >>>>>>>>>> C/C++ people please critique this as the basis for an
> >>>>>>>>>> improvement to std::deque. It seems to have the key
> >>>>>>>>>> functionality of std::deque and does it much more simply
> >>>>>>>>>> while saving time and space.
> >>>>>>>>>> https://www.cplusplus.com/reference/deque/deque/
> >>>>>>>>>>
> >>>>>>>>>> #define tape_element unsigned char
> >>>>>>>>>>
> >>>>>>>>>> class Tape_Type
> >>>>>>>>>> {
> >>>>>>>>>> private:
> >>>>>>>>>> int Tape_Head = 0; // Can be negative
> >>>>>>>>>> std::vector<tape_element> Left; // Stores left
> >>>>>>>>>> expansion std::vector<tape_element> Right; // Stores right
> >>>>>>>>>> expansion tape_element & operator[](int index);
> >>>>>>>>>>
> >>>>>>>>>> public:
> >>>>>>>>>> void move_left(); // Tape_Head--;
> >>>>>>>>>> Left.push_back(0); as needed void move_right(); //
> >>>>>>>>>> Tape_Head++; Left.push_back(0); as needed void
> >>>>>>>>>> Write(tape_element Y){ this->operator[](Tape_Head) = Y; };
> >>>>>>>>>> tape_element Read() { return
> >>>>>>>>>> this->operator[](Tape_Head); }; Tape_Type(){
> >>>>>>>>>> Right.push_back('_'); } // constructor void Output(); };
> >>>>>>>>>>
> >>>>>>>>>> tape_element& Tape_Type::operator[](int index)
> >>>>>>>>>> {
> >>>>>>>>>> if (index > 0)
> >>>>>>>>>> return Right[index];
> >>>>>>>>>> int Left_Index = ((index * -1) -1);
> >>>>>>>>>> return Left[Left_Index];
> >>>>>>>>>> }
> >>>>>>>>>>
> >>>>>>>>>> void Tape_Type::Output()
> >>>>>>>>>> {
> >>>>>>>>>> printf("Tape_Type::Output()\n");
> >>>>>>>>>>
> >>>>>>>>>> if (Left.size())
> >>>>>>>>>> {
> >>>>>>>>>> int Last_One = Left.size() - 1;
> >>>>>>>>>> for (int N = Last_One; N >= 0; N--)
> >>>>>>>>>> {
> >>>>>>>>>> int TH = (N + 1) * -1; // determine Tape_Head
> >>>>>>>>>> from N printf("[%04d]:%c Left[%02d]\n", TH, Left[N], N);
> >>>>>>>>>> }
> >>>>>>>>>> }
> >>>>>>>>>> if (Right.size())
> >>>>>>>>>> for (int N = 0; N < Right.size(); N++)
> >>>>>>>>>> printf("[%04d]:%c Right[%02d]\n", N, Right[N],
> >>>>>>>>>> N); }
> >>>>>>>>>>
> >>>>>>>>>> void Tape_Type::move_left()
> >>>>>>>>>> {
> >>>>>>>>>> Tape_Head--;
> >>>>>>>>>> int Left_Index = ((Tape_Head * -1) -1);
> >>>>>>>>>> if (Left_Index == Left.size())
> >>>>>>>>>> Left.push_back('_');
> >>>>>>>>>> }
> >>>>>>>>>>
> >>>>>>>>>> void Tape_Type::move_right()
> >>>>>>>>>> {
> >>>>>>>>>> Tape_Head++;
> >>>>>>>>>> if (Tape_Head == Right.size())
> >>>>>>>>>> Right.push_back('_');
> >>>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> It might be a more appropriate solution than std::deque for
> >>>>>>>>> your specific use-case however it is NOT an improvement to
> >>>>>>>>> std::deque for the general case -- see my reply in the other
> >>>>>>>>> thread for why.
> >>>>>>>>>
> >>>>>>>>> /Flibble
> >>>>>>>>>
> >>>>>>>>
> >>>>>>>> I didn't see any reason why it would not make a better
> >>>>>>>> std::deque.
> >>>>>>>
> >>>>>>> Because it doesn't meet the complexity and referential
> >>>>>>> integrity requirements of std::deque.
> >>>>>>>
> >>>>>>> /Flibble
> >>>>>>>
> >>>>>>
> >>>>>> It is faster then std::deque.
> >>>>>> I couldn't find what you mean by referential integrity it has
> >>>>>> too many different meanings. invalidating iterators seemed to
> >>>>>> be what you mean otherwise I have no idea.
> >>>>>
> >>>>> I see you are choosing to ignore my reply in the other thread.
> >>>>> OK, I will repost why you are wrong here:
> >>>>>
> >>>>> * referential integrity and iterator invalidation are
> >>>>> different things: when you add or remove elements to either end
> >>>>> of a std::deque iterators are indeed invalidated however
> >>>>> references to existing elements remain valid
> >>>>
> >>>> Mine words the same way and has the added benefit of contiguous
> >>>> storage.
> >>>>
> >>>>> * If you do 1000 push_fronts followed by 1000 push_backs
> >>>>> followed by 1000 pop_fronts all is good however your next
> >>>>> pop_front will have linear complexity, O(n), as it will
> >>>>> necessitate removal of the first element of the right
> >>>>> std::vector.
> >>>>
> >>>> I don't think that this applies to the way that I implemented it.
> >>>> pop_front pops from the end of Left. pop_back pops from the end
> >>>> of Right. This is the key aspect that I used from David's
> >>>> two-stack approach.
> >>>
> >>> Then it is totally different to what std::deque offers: std::deque
> >>> allows ALL elements to be either popped from the front or back.
> >>> Try reading AND UNDERSTANDING what I wrote again.
> >>>
> >>> /Flibble
> >>>
> >>
> >> I could allow all elements to be popped from the front or the back
> >> too. Mine is much faster when you need far less than all elements.
> >>
> >
> > What you have does not offer what std::deque offers so is not
>
> All these things can be added and we end up with a simple, faster,
> std:deque that has most the conventional overhead and complexity
> abolished.
>
> > equivalent to std::deque so can't be considered better than
> > std::deque for the general case (I don't care about your specific
> > use-case).
> >
> > /Flibble
> >
>
> It just a matter of defining more member functions.

Click here to read the complete article

Re: Implementing a two-way Turing Machine tape as an improvement to std::deque

<20220513080435.00002bdc@reddwarf.jmc>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=32270&group=comp.theory#32270

  copy link   Newsgroups: comp.theory comp.lang.c++
Path: i2pn2.org!i2pn.org!news.swapon.de!news.uzoreto.com!feeder.usenetexpress.com!tr2.eu1.usenetexpress.com!81.171.65.13.MISMATCH!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx04.ams4.POSTED!not-for-mail
From: flib...@reddwarf.jmc (Mr Flibble)
Newsgroups: comp.theory,comp.lang.c++
Subject: Re: Implementing a two-way Turing Machine tape as an improvement to std::deque
Message-ID: <20220513080435.00002bdc@reddwarf.jmc>
References: <cNWdnXqV1cXzEuD_nZ2dnUU7_8zNnZ2d@giganews.com> <87wneq1ejm.fsf@bsb.me.uk> <MeOdncpeZacPMeD_nZ2dnUU7_8zNnZ2d@giganews.com> <20220513020134.00003f42@reddwarf.jmc> <D7WdnSvo4syeK-D_nZ2dnUU7_81g4p2d@giganews.com>
Organization: Jupiter Mining Corp
X-Newsreader: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-w64-mingw32)
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Lines: 49
X-Complaints-To: abuse@eweka.nl
NNTP-Posting-Date: Fri, 13 May 2022 07:04:34 UTC
Date: Fri, 13 May 2022 08:04:35 +0100
X-Received-Bytes: 2493
 by: Mr Flibble - Fri, 13 May 2022 07:04 UTC

On Thu, 12 May 2022 20:36:02 -0500
olcott <NoOne@NoWhere.com> wrote:

> On 5/12/2022 8:01 PM, Mr Flibble wrote:
> > On Thu, 12 May 2022 19:55:44 -0500
> > olcott <NoOne@NoWhere.com> wrote:
> >
> >> On 5/12/2022 7:06 PM, Ben wrote:
> >>> olcott <NoOne@NoWhere.com> writes:
> >>>
> >>> I've removed the philosophy group and comp.lang.c as this is C++.
> >>>
> >>>> C/C++ people please critique this as the basis for an improvement
> >>>> to std::deque.
> >>>
> >>> You will get critiques of the code on whatever basis people feel
> >>> inclined to comment! You can't limit the comments to some
> >>> particular context.
> >>>
> >>>> It seems to have the key functionality of std::deque and
> >>>> does it much more simply while saving time and space.
> >>>
> >>> It does not have any of the functionality of std::deque.
> >>
> >> That is a ridiculously stupid thing to say. It has the key most
> >> important functionality of a std:deque
> >>
> >> Double ended queue
> >> deque (usually pronounced like "deck") is an irregular acronym of
> >> double-ended queue. Double-ended queues are sequence containers
> >> with dynamic sizes that can be expanded or contracted on both ends
> >> (either its front or its back).
> >>
> >> All of the rest of the functionality of std::deque can be added as
> >> needed.
> >
> > Not with your chosen data structure of two std::vectors it can't as
> > it wouldn't meet the complexity
>
> It already has the same complexity.
>
> > and referential integrity
>
> and better referential integrity.

You are a fucking obtuse idiot, mate.

/Flibble

Re: Implementing a two-way Turing Machine tape as an improvement to std::deque

<t5l090$2f3k$1@news.gegeweb.eu>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=32272&group=comp.theory#32272

  copy link   Newsgroups: comp.theory comp.ai.philosophy comp.lang.c comp.lang.c++
Followup: comp.lang.c++
Path: i2pn2.org!i2pn.org!news.niel.me!news.gegeweb.eu!gegeweb.org!.POSTED.2001:861:5e50:f690:159b:da31:48b1:869d!not-for-mail
From: tth...@none.invalid (tth)
Newsgroups: comp.theory,comp.ai.philosophy,comp.lang.c,comp.lang.c++
Subject: Re: Implementing a two-way Turing Machine tape as an improvement to
std::deque
Followup-To: comp.lang.c++
Date: Fri, 13 May 2022 09:10:24 +0200
Organization: Gegeweb News Server
Message-ID: <t5l090$2f3k$1@news.gegeweb.eu>
References: <cNWdnXqV1cXzEuD_nZ2dnUU7_8zNnZ2d@giganews.com>
<20220512235610.00004914@reddwarf.jmc>
<Vf2dnR9fAewpDuD_nZ2dnUU7_8xh4p2d@giganews.com>
<20220513002218.00003fa0@reddwarf.jmc>
<-s-dncjVifoXB-D_nZ2dnUU7_83NnZ2d@giganews.com>
<20220513004049.00000d64@reddwarf.jmc>
<HYudneQqVdKFAOD_nZ2dnUU7_83NnZ2d@giganews.com>
<20220513005340.00001694@reddwarf.jmc>
<Bo-dnemL1eT6P-D_nZ2dnUU7_81g4p2d@giganews.com>
<20220513015816.00006f57@reddwarf.jmc>
<D7WdnSjo4swvKOD_nZ2dnUU7_81g4p2d@giganews.com>
<20220513080247.000077d7@reddwarf.jmc>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 13 May 2022 07:10:24 -0000 (UTC)
Injection-Info: news.gegeweb.eu; posting-account="tontonth@usenet.local"; posting-host="2001:861:5e50:f690:159b:da31:48b1:869d";
logging-data="81012"; mail-complaints-to="abuse@gegeweb.eu"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.8.0
Cancel-Lock: sha256:YgbXW+ljbbpnqPQ/orEEycqi/i1kpdklvKQYxrvS+MM=
Content-Language: en-US
In-Reply-To: <20220513080247.000077d7@reddwarf.jmc>
 by: tth - Fri, 13 May 2022 07:10 UTC

On 5/13/22 09:02, Mr Flibble wrote:

> You cannot implement all of std::deque's member functions meeting
> std::deque requirements using your chosen data structure of two
> std::vectors.

Not with any version of the C language.

--
+-------------------------------------------------------------------+
| sphinx of black quartz, judge my vow. |
+-------------------------------------------------------------------+

Re: Implementing a two-way Turing Machine tape as an improvement to std::deque

<87sfpdzofd.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=32274&group=comp.theory#32274

  copy link   Newsgroups: comp.theory
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben)
Newsgroups: comp.theory
Subject: Re: Implementing a two-way Turing Machine tape as an improvement to std::deque
Date: Fri, 13 May 2022 12:01:42 +0100
Organization: A noiseless patient Spider
Lines: 108
Message-ID: <87sfpdzofd.fsf@bsb.me.uk>
References: <cNWdnXqV1cXzEuD_nZ2dnUU7_8zNnZ2d@giganews.com>
<87wneq1ejm.fsf@bsb.me.uk>
<MeOdncpeZacPMeD_nZ2dnUU7_8zNnZ2d@giganews.com>
<8735he1abh.fsf@bsb.me.uk>
<692dnROYz_PMWeD_nZ2dnUU7_83NnZ2d@giganews.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="9d7070da1378146bf8b2ebf4ad06ac0b";
logging-data="2511"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1939+gAh9ALGWCYGhB0HqgGy/FjYZPNNc0="
Cancel-Lock: sha1:/xCWFP2KkTr1S5hY3iP2+Afvrng=
sha1:kIqMW5RTwfkuCSeICXWaiaN1Ks4=
X-BSB-Auth: 1.374c55caca33ea0104a8.20220513120142BST.87sfpdzofd.fsf@bsb.me.uk
 by: Ben - Fri, 13 May 2022 11:01 UTC

olcott <NoOne@NoWhere.com> writes:

> On 5/12/2022 8:38 PM, Ben wrote:
>> olcott <NoOne@NoWhere.com> writes:
>>
>>> On 5/12/2022 7:06 PM, Ben wrote:
>>>> olcott <NoOne@NoWhere.com> writes:
>>>> I've removed the philosophy group and comp.lang.c as this is C++.
>>>>
>>>>> C/C++ people please critique this as the basis for an improvement to
>>>>> std::deque.
>>>> You will get critiques of the code on whatever basis people feel
>>>> inclined to comment! You can't limit the comments to some particular
>>>> context.
>>>>
>>>>> It seems to have the key functionality of std::deque and
>>>>> does it much more simply while saving time and space.
>>>> It does not have any of the functionality of std::deque.
>>>
>>> That is a ridiculously stupid thing to say. It has the key most
>>> important functionality of a std:deque
>> Generally, when you think I am saying something absurd, you should
>> re-consider.
>> A deque has (at least) these operations:
>> front
>> back
>> push_front
>> push_back
>> pop_front
>> pop_back
>> Your Tape_Type has none of these. Even internally it does not maintain
>> the right data to be able to provide them.
>
> I also added a reserve so you could do a pre-allocated speed test.
>
> It was easy to add these in terms of the current implementation:

You have not provided the correct operations, so you have no idea how
hard it might be to do that. This keeps looking more and more like a
distraction to put off having to do what you said.

> public:
> tape_element& front( ) { return Left.back(); }
> tape_element& back() { return Right.back(); }
> void pop_front() { Left.pop_back(); }
> void pop_back() { Right.pop_back(); }
> void push_front(tape_element& E) { Left.push_back(E); }
> void push_back(tape_element& E) { Right.push_back(E); }
>
> void reserve(unsigned int N)
> { Left.reserve(N); Right.reserve(N); }

Not correct. Test first.

>>> Double ended queue
>>> deque (usually pronounced like "deck") is an irregular acronym of
>>> double-ended queue. Double-ended queues are sequence containers with
>>> dynamic sizes that can be expanded or contracted on both ends (either
>>> its front or its back).
>>>
>>> All of the rest of the functionality of std::deque can be added as
>>> needed.
>> You mean you could implement a deque using two arrays if you chose to?
>> So what? All I am saying is that you haven't got a deque.
>
> If I added these things then I would have a much better deque.

If you added them correctly and then removed the things that a deque
should not have. In other words, if you implemented a deque.

>>> Yes I tested so I don't see what you mean.
>> Testing should have caught the bug in operator[].
>
> It is was a new refactoring of existing working code.

A software engineer runs all the tests after every edit (or at least
before every commit). (I am not a software engineer.)

>> I plugged your tape class into my C++ TM interpreter and it made it
>> slightly slower for the "big" BB(5) test compared with my naive tape
>> that just uses a single string.
>>
>
> std::string or char * ?

std::string.

> If char * was pre-allocated that would give it a big speed advantage.

Nothing pre-allocated.

>> Mind you, I prefer using a string to all the other methods I've tried
>> because it's so convenient. You can set up the TM with an input simply
>> by writing
>> tape = input
>> and you can debug by printing the tape any time you like. And I use a
>> string_view to get the non-blank "result" out of the TM and the end of a
>> run. All easy to get round with a couple of functions, but still, since
>> it's fast I see no reason t change.
>
> What about memory allocation?

What about it? std::string does it.

--
Ben.
"le génie humain a des limites, quand la bêtise humaine n’en a pas"
Alexandre Dumas (fils)

Re: Implementing a two-way Turing Machine tape as an improvement to std::deque

<-LadnQlxFteO4eP_nZ2dnUU7_8zNnZ2d@giganews.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=32280&group=comp.theory#32280

  copy link   Newsgroups: comp.theory
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!buffer2.nntp.dca1.giganews.com!buffer1.nntp.dca1.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Fri, 13 May 2022 10:41:07 -0500
Date: Fri, 13 May 2022 10:41:06 -0500
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Subject: Re: Implementing a two-way Turing Machine tape as an improvement to
std::deque
Content-Language: en-US
Newsgroups: comp.theory
References: <cNWdnXqV1cXzEuD_nZ2dnUU7_8zNnZ2d@giganews.com>
<87wneq1ejm.fsf@bsb.me.uk> <MeOdncpeZacPMeD_nZ2dnUU7_8zNnZ2d@giganews.com>
<8735he1abh.fsf@bsb.me.uk> <692dnROYz_PMWeD_nZ2dnUU7_83NnZ2d@giganews.com>
<87sfpdzofd.fsf@bsb.me.uk>
From: NoO...@NoWhere.com (olcott)
In-Reply-To: <87sfpdzofd.fsf@bsb.me.uk>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <-LadnQlxFteO4eP_nZ2dnUU7_8zNnZ2d@giganews.com>
Lines: 125
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-10BqajsbVsjGLUfzRzBVqsuA1JTZRnedK/A4rpwnUha2Fz9BVhmVOKKZvf+t5t02WYNiX69YwYjldmW!h2uyd6L8m8547I3tqa10BUpqJmFP9mNXEvdJWy7nGNf7/BC+McudF1+u60sUOTjFLakIkYJflqs=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 6087
 by: olcott - Fri, 13 May 2022 15:41 UTC

On 5/13/2022 6:01 AM, Ben wrote:
> olcott <NoOne@NoWhere.com> writes:
>
>> On 5/12/2022 8:38 PM, Ben wrote:
>>> olcott <NoOne@NoWhere.com> writes:
>>>
>>>> On 5/12/2022 7:06 PM, Ben wrote:
>>>>> olcott <NoOne@NoWhere.com> writes:
>>>>> I've removed the philosophy group and comp.lang.c as this is C++.
>>>>>
>>>>>> C/C++ people please critique this as the basis for an improvement to
>>>>>> std::deque.
>>>>> You will get critiques of the code on whatever basis people feel
>>>>> inclined to comment! You can't limit the comments to some particular
>>>>> context.
>>>>>
>>>>>> It seems to have the key functionality of std::deque and
>>>>>> does it much more simply while saving time and space.
>>>>> It does not have any of the functionality of std::deque.
>>>>
>>>> That is a ridiculously stupid thing to say. It has the key most
>>>> important functionality of a std:deque
>>> Generally, when you think I am saying something absurd, you should
>>> re-consider.
>>> A deque has (at least) these operations:
>>> front
>>> back
>>> push_front
>>> push_back
>>> pop_front
>>> pop_back
>>> Your Tape_Type has none of these. Even internally it does not maintain
>>> the right data to be able to provide them.
>>
>> I also added a reserve so you could do a pre-allocated speed test.
>>
>> It was easy to add these in terms of the current implementation:
>
> You have not provided the correct operations, so you have no idea how
> hard it might be to do that. This keeps looking more and more like a
> distraction to put off having to do what you said.
>
>> public:
>> tape_element& front( ) { return Left.back(); }
>> tape_element& back() { return Right.back(); }
>> void pop_front() { Left.pop_back(); }
>> void pop_back() { Right.pop_back(); }
>> void push_front(tape_element& E) { Left.push_back(E); }
>> void push_back(tape_element& E) { Right.push_back(E); }
>>
>> void reserve(unsigned int N)
>> { Left.reserve(N); Right.reserve(N); }
>
> Not correct. Test first.

They are all correct. I don't see how you can say that they are not when
you don't know my design.

>
>>>> Double ended queue
>>>> deque (usually pronounced like "deck") is an irregular acronym of
>>>> double-ended queue. Double-ended queues are sequence containers with
>>>> dynamic sizes that can be expanded or contracted on both ends (either
>>>> its front or its back).
>>>>
>>>> All of the rest of the functionality of std::deque can be added as
>>>> needed.
>>> You mean you could implement a deque using two arrays if you chose to?
>>> So what? All I am saying is that you haven't got a deque.
>>
>> If I added these things then I would have a much better deque.
>
> If you added them correctly and then removed the things that a deque
> should not have. In other words, if you implemented a deque.
>

I mere want to know that the most basic functionality of my deque is
(a) simpler (b) faster (c) smaller than a std:deque.
If Tape_Type.reserve() is used it should be your std::string.

>>>> Yes I tested so I don't see what you mean.
>>> Testing should have caught the bug in operator[].
>>
>> It is was a new refactoring of existing working code.
>
> A software engineer runs all the tests after every edit (or at least
> before every commit). (I am not a software engineer.)
>
>>> I plugged your tape class into my C++ TM interpreter and it made it
>>> slightly slower for the "big" BB(5) test compared with my naive tape
>>> that just uses a single string.
>>>
>>
>> std::string or char * ?
>
> std::string.
>
>> If char * was pre-allocated that would give it a big speed advantage.
>
> Nothing pre-allocated.
>
>>> Mind you, I prefer using a string to all the other methods I've tried
>>> because it's so convenient. You can set up the TM with an input simply
>>> by writing
>>> tape = input
>>> and you can debug by printing the tape any time you like. And I use a
>>> string_view to get the non-blank "result" out of the TM and the end of a
>>> run. All easy to get round with a couple of functions, but still, since
>>> it's fast I see no reason t change.
>>
>> What about memory allocation?
>
> What about it? std::string does it.
>

It is probably much slower than my system now that I added reserve.
I do like the idea of simplicity, it is my primary design goal.

--
Copyright 2022 Pete Olcott

"Talent hits a target no one else can hit;
Genius hits a target no one else can see."
Arthur Schopenhauer

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor