<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'><pre style="line-height: 21.81818199157715px; white-space: normal; font-size: 15.454545021057129px; background-color: rgb(255, 255, 255); "> > The separation of algorithms from containers sounds a bit like a bug.</pre><div><br></div>It isn't. It is a leap that allows for far greater code reuse. Efficiently.<div>(You could do it inefficiently with lots of function pointers -- templates allow</div><div>for inlinability. C++ beats C for performance here.)</div><div><div><br></div><div><br></div><div>Imagine I have written quicksort.</div><div>In C++ we have at least the following worthwhile "array-like" data structures:</div><div><br></div><div><br></div><div> The builtin arrays. Like Modula-3 fixed arrays.</div><div><br></div><div><br></div><div> Arrays you get with new[]. Like Modula-3 open arrays, but they don't expose their size.</div><div><br></div><div><br></div><div> std::vector<>. Like Modula-3 "sequence" -- a simple growable array. Grows by a constant factor greater than 1 (typically 2), so that long runs of "appends" are amortized cheap.</div><div><br></div><div><br></div><div> std::deque<>. More like Modula-3 sequence, in that you can amortized cheap at/remove from the front or the back. I believe this can be implemented as simply an "offset array". Element 0 starts in the middle, and whenever you grow it, you "center" it -- equal gaps at front and back.</div><div><br></div><div><br></div><div>Now, with the iterator/algorithm separation, one quicksort implementation can be applied to all these types. The input to "quicksort" is "random access iterators", which is very much like a "pointer", but isn't necessarily a pointer. It can be incremented, decremented, added to an integer, subtracted from another iterator, have an integer subtracted from it, dereferenced, and assigned and compared with other iterators of the same type -- all constant time fast operations.</div><div><br></div><div><br>There are "input iterators" which can, roughly speaking, only be incremented and dereferenced. They are all some containers can expose and all some algorithms require -- for example, a singly linked list and linear search.</div><div><br></div><div><br></div><div>There are "bidirectional iterators" which can, roughly speaking, only be incremented and decremented and dereferenced. Doubly linked lists expose these.</div><div><br></div><div><br></div><div>There are "output iterators".</div><div>They are similar to "input".</div><div><br></div><div><br></div><div>input streams (cin, like stdin) exposes an input iterator.</div><div>You can copy from it.</div><div>Copy is another simple reusable algorithm.</div><div><br></div><div><br></div><div>output streams (cout, like stdout) exposes an output iterator.</div><div>You can copy to it.</div><div><br></div><div><br></div><div>There are many more examples.</div><div>Of course, besides quick sort, there is a stable sort.</div><div>There is finding sequences.</div><div>There is binary_search.</div><div>There is upper_bound/lower_bound/equal_range which are like binary_search.</div><div>There is unique.</div><div>There is partition.</div><div>Many many more, "built in" to the library.</div><div>That work with multiple "built in" containers, and can work with custom containers as well.</div><div><br></div><div><br></div><div>I strongly recommend you read up on this stuff.</div><div>It is really quite illimuninating. Good stuff.</div><div>Teaches us how to better factor our code.</div><div>And to strive for better factoring, when we find people have invented/discovered such things.</div><div><br></div><div><br></div><div>"Iterators" already do occur in Modula-3 libraries.</div><div><br></div><div><br></div><div>All I want is a sorted vector that "closely knows" when it is being written vs. read, and when there are a series of writes with no intervening reads, it can amortize down the cost of maintaining the ordering.</div><div><br></div><div><br></div><div>I hand coded something.</div><div>It took me a while to get it to work due to stupid small details.</div><div>The result is significantly worse than I would have gotten in C++.</div><div>Bigger code. Slower code. More copies. More heap allocations.</div><div>I can eliminate one of the allocations by merging the next step.</div><div>But in C++ I naturally wouldn't have had it anyway.</div><div>Not great.</div><div><br></div><div><br></div><div> - Jay<br><br><br><div><div id="SkyDrivePlaceholder"></div>> To: jay.krell@cornell.edu<br>> CC: mika@async.caltech.edu; m3devel@elegosoft.com<br>> Subject: Re: [M3devel] STL algorithms? sort/unique?<br>> Date: Sat, 29 Sep 2012 11:29:48 -0700<br>> From: mika@async.caltech.edu<br>> <br>> <br>> Well that depends on how you maintain the vector, no?<br>> <br>> SortedTable uses "treaps" which are supposed to be good data structures.<br>> Too new to have made it into Knuth, last I checked. The amortized cost<br>> of your operations shouldn't be much worse than with your method, with<br>> the additional benefit that the sorted order is maintained dynamically.<br>> <br>> The separation of algorithms from containers sounds a bit like a bug.<br>> You have to be careful so you don't shoot yourself in the foot there!<br>> (Sorting a list using an algorithm that randomly accesses elements,<br>> say...)<br>> <br>> The Modula-3 approach is that you figure out what you want to do, pick<br>> the ADT you want that provides the minimal set of operations, import<br>> that interface, then instantiate a more carefully chosen implementation<br>> of the ADT. The language itself obviously can be coaxed into supporting the<br>> algorithm/data structure separation but no one uses it that way as<br>> far as I know. (Modula-3 generics are not that well explored, actually.<br>> I suspect there are many things you can do with them that no one has<br>> tried.)<br>> <br>> Mika<br>> <br>> Jay K writes:<br>> >--_7877d7e8-cb4a-4989-bdcd-d406e5b1f51f_<br>> >Content-Type: text/plain; charset="iso-8859-1"<br>> >Content-Transfer-Encoding: quoted-printable<br>> ><br>> >The following is very efficient:<br>> ><br>> >run through a bunch of records=2C picking out one number from some of thema=<br>> >ppend those numbers to a growing vectorsort the vectorunique the vector<br>> ><br>> >sequence allows for random access..but only via a function...or maybe an it=<br>> >erator<br>> ><br>> >STL has this wonderful separation of algorithms from containers=2C via iter=<br>> >ators.I suspect very few other libraries do.And it could be that most langu=<br>> >ages don't support it.It doesn't appear I can easily sort a sequence=2C unl=<br>> >ess I copy the data out into an array -- gross inefficiency.<br>> ><br>> >I've hacked something very manual together..and it is taking forever to get=<br>> > it to work. It turns out I can reasonably well bound the size of the data=<br>> >=2C so I'm using an open array...and I have to keep track of my position in=<br>> >stead of using addhi/push_back.Not happy.At some point I might give up and =<br>> >write the backend in C++..at which point I might as well write a C++ fronte=<br>> >nd anywa.<br>> ><br>> ><br>> >I absolutely do not want a sorted table and unique upon insert.That is much=<br>> > less efficient.What I'm describing uses temporarily larger working set but=<br>> > vastly less CPU.An array that gets sorted/uniqued occasionally=2C like jus=<br>> >t once.And not ongoing maintainence for every single add.<br>> ><br>> ><br>> > - Jay<br>> ><br>> ><br>> >> To: jay.krell@cornell.edu<br>> >> CC: m3devel@elegosoft.com<br>> >> Subject: Re: [M3devel] STL algorithms? sort/unique?<br>> >> Date: Fri=2C 28 Sep 2012 01:04:48 -0700<br>> >> From: mika@async.caltech.edu<br>> >>=20<br>> >>=20<br>> >> BTW I had the same experience when I first started using Modula-3.<br>> >> It was painful to jump through all its hoops=2C coming from C=2C where yo=<br>> >u<br>> >> can do whatever you want to whatever bits happen to be sloshing around<br>> >> your machine. C++ from what I have seen mainly lets you do that to<br>> >> more bits in fewer lines of code.<br>> >>=20<br>> >> But after a while I really came to appreciate the value of things like th=<br>> >e<br>> >> language's telling me I'm using the wrong data structure instead of<br>> >> just letting me use the same "nice=2C terse=2C efficient" syntax to write<br>> >> a crappy program :-)<br>> >>=20<br>> >> mika writes:<br>> >> >You're using the wrong (abstract) data structure if you want sort and un=<br>> >ique.<br>> >> ><br>> >> >A "sequence" is meant to be accessed sequentially...<br>> >> ><br>> >> >Not knowing precisely what you're doing it sounds like you might want a<br>> >> >SortedTable... you can get unique on insert and access it in increasing<br>> >> >or decreasing order.<br>> >> ><br>> >> > Mika<br>> >> ><br>> >> >Jay K writes:<br>> >> >>--_d2a02ece-d492-410e-88fb-fb53737d7219_<br>> >> >>Content-Type: text/plain=3B charset=3D"iso-8859-1"<br>> >> >>Content-Transfer-Encoding: quoted-printable<br>> >> >><br>> >> >> I have an IntSeq.T with a bunch of integers. =3D20<br>> >> >> What is a good terse efficient idiom for sort and unique? =3D20<br>> >> >><br>> >> >> In C++ I would say: vector<int> a=3D3B a.push_back(..=<br>> >.)=3D3B =3D<br>> >> >> a.push_back(...)=3D3B std::sort(a.begin()=3D2C a.end())=<br>> >=3D3B =3D<br>> >> >> a.resize(std::unique(a.begin()=3D2C a.end()) - a.begin())=3D3B =<br>> >for (aut=3D<br>> >> >>o i =3D3D a.begin()=3D3B i !=3D3D a.end()=3D3B ++i) {<br>> >> >> do stuff with *i }=3D20<br>> >> >> Nice=3D2C terse=3D2C efficient. In Modula-3? =3D20<br>> >> >><br>> >> >>I know that unique is one of the easiest algorithms to manually write i=<br>> >nlin=3D<br>> >> >>e=3D2Cbut I shouldn't have to.<br>> >> >><br>> >> >>(I'm really trying to stay in Modula-3 here=3D2C but it is definitely a=<br>> > strug=3D<br>> >> >>gle. :( )<br>> >> >><br>> >> >>Thank you=3D2C - Jay<br>> >> >><br>> >> >> =3D<br>> >> >><br>> >> >>--_d2a02ece-d492-410e-88fb-fb53737d7219_<br>> >> >>Content-Type: text/html=3B charset=3D"iso-8859-1"<br>> >> >>Content-Transfer-Encoding: quoted-printable<br>> >> >><br>> >> >><html><br>> >> >><head><br>> >> >><style><!--<br>> >> >>.hmmessage P<br>> >> >>{<br>> >> >>margin:0px=3D3B<br>> >> >>padding:0px<br>> >> >>}<br>> >> >>body.hmmessage<br>> >> >>{<br>> >> >>font-size: 12pt=3D3B<br>> >> >>font-family:Calibri<br>> >> >>}<br>> >> >>--></style></head><br>> >> >><body class=3D3D'hmmessage'><div dir=3D3D'ltr'> =3D3B  =3D3B&nb=<br>> >sp=3D3BI have =3D<br>> >> >>an IntSeq.T with a bunch of integers. =3D3B  =3D3B =3D3B<br=<br>> >><div><spa=3D<br>> >> >>n style=3D3D"font-size: 12pt=3D3B "> =3D3B  =3D3B</span><span s=<br>> >tyle=3D3D"font=3D<br>> >> >>-size: 12pt=3D3B "> =3D3B</span>What is a good terse efficient idio=<br>> >m for so=3D<br>> >> >>rt and unique?<span style=3D3D"font-size: 12pt=3D3B "> =3D3B  =<br>> >=3D3B</span><=3D<br>> >> >>span style=3D3D"font-size: 12pt=3D3B "> =3D3B</span></div><div><br>=<br>> ></div><div=3D<br>> >> >>><br></div><div> =3D3B  =3D3B In C++ I would say:<span style=3D=<br>> >3D"font-si=3D<br>> >> >>ze: 12pt=3D3B "> =3D3B  =3D3B</span><span style=3D3D"font-size:=<br>> > 12pt=3D3B ">&=3D<br>> >> >>nbsp=3D3B</span></div><div><span style=3D3D"font-size: 12pt=3D3B ">&nbs=<br>> >p=3D3B  =3D<br>> >> >>=3D3B</span><span style=3D3D"font-size: 12pt=3D3B "> =3D3B</span>ve=<br>> >ctor<=3D3Bin=3D<br>> >> >>t>=3D3B a=3D3B<span style=3D3D"font-size: 12pt=3D3B "> =3D3B &nbs=<br>> >p=3D3B</span><sp=3D<br>> >> >>an style=3D3D"font-size: 12pt=3D3B "> =3D3B</span></div><div><span =<br>> >style=3D3D"f=3D<br>> >> >>ont-size: 12pt=3D3B "> =3D3B  =3D3B</span><span style=3D3D"font=<br>> >-size: 12pt=3D<br>> >> >>=3D3B "> =3D3B</span>a.push_back(...)=3D3B<span style=3D3D"font-siz=<br>> >e: 12pt=3D3B "=3D<br>> >> >>> =3D3B  =3D3B</span><span style=3D3D"font-size: 12pt=3D3B ">&n=<br>> >bsp=3D3B</span=3D<br>> >> >>></div><div><div><span style=3D3D"font-size: 12pt=3D3B "> =3D3B &nb=<br>> >sp=3D3B</spa=3D<br>> >> >>n><span style=3D3D"font-size: 12pt=3D3B "> =3D3B</span>a.push_back(=<br>> >...)=3D3B<sp=3D<br>> >> >>an style=3D3D"font-size: 12pt=3D3B "> =3D3B  =3D3B</span><span =<br>> >style=3D3D"fon=3D<br>> >> >>t-size: 12pt=3D3B "> =3D3B</span></div><div><span style=3D3D"font-s=<br>> >ize: 12pt=3D<br>> >> >>=3D3B "> =3D3B  =3D3B</span><span style=3D3D"font-size: 12pt=3D=<br>> >3B "> =3D3B<=3D<br>> >> >>/span>std::sort(a.begin()=3D2C a.end())=3D3B<span style=3D3D"font-size:=<br>> > 12pt=3D3B "=3D<br>> >> >>> =3D3B  =3D3B</span><span style=3D3D"font-size: 12pt=3D3B ">&n=<br>> >bsp=3D3B</span=3D<br>> >> >>></div><div><span style=3D3D"font-size: 12pt=3D3B "> =3D3B  =3D=<br>> >3B</span><sp=3D<br>> >> >>an style=3D3D"font-size: 12pt=3D3B "> =3D3B</span>a.resize(std::uni=<br>> >que(a.begi=3D<br>> >> >>n()=3D2C a.end()) - a.begin())=3D3B<span style=3D3D"font-size: 12pt=3D3=<br>> >B "> =3D3B=3D<br>> >> >>  =3D3B</span><span style=3D3D"font-size: 12pt=3D3B "> =3D3B</s=<br>> >pan></div><d=3D<br>> >> >>iv><span style=3D3D"font-size: 12pt=3D3B "> =3D3B  =3D3B for (a=<br>> >uto i =3D3D a.=3D<br>> >> >>begin()=3D3B i !=3D3D a.end()=3D3B ++i)</span></div><div><span style=3D=<br>> >3D"font-size=3D<br>> >> >>: 12pt=3D3B "> =3D3B  =3D3B {<br> =3D3B  =3D3B  =3D=<br>> >3B do stuff with=3D<br>> >> >> *i</span></div><div><span style=3D3D"font-size: 12pt=3D3B "> =3D3B=<br>> >  =3D3B =3D<br>> >> >>}</span></div><div> =3D3B</div><div><br></div><div><span style=3D3D=<br>> >"font-si=3D<br>> >> >>ze: 12pt=3D3B "> =3D3B  =3D3B</span><span style=3D3D"font-size:=<br>> > 12pt=3D3B ">&=3D<br>> >> >>nbsp=3D3B</span>Nice=3D2C terse=3D2C efficient.<span style=3D3D"font-si=<br>> >ze: 12pt=3D3B =3D<br>> >> >>"> =3D3B  =3D3B</span><span style=3D3D"font-size: 12pt=3D3B ">&=<br>> >nbsp=3D3B</spa=3D<br>> >> >>n></div><div><span style=3D3D"font-size: 12pt=3D3B "> =3D3B  =<br>> >=3D3B</span><s=3D<br>> >> >>pan style=3D3D"font-size: 12pt=3D3B "> =3D3B</span>In Modula-3?<spa=<br>> >n style=3D3D=3D<br>> >> >>"font-size: 12pt=3D3B "> =3D3B  =3D3B</span><span style=3D3D"fo=<br>> >nt-size: 12p=3D<br>> >> >>t=3D3B "> =3D3B</span></div><div><br></div><div><br></div><div>I kn=<br>> >ow that =3D<br>> >> >>unique is one of the easiest algorithms to manually write inline=3D2C</=<br>> >div><d=3D<br>> >> >>iv>but I shouldn't have to.</div><div><br></div><div><br></div><div>(I'=<br>> >m re=3D<br>> >> >>ally trying to stay in Modula-3 here=3D2C but it is definitely a strugg=<br>> >le. :(=3D<br>> >> >> )</div><div><br></div><div><br></div><div>Thank you=3D2C</div><div>&nb=<br>> >sp=3D3B-=3D<br>> >> >> Jay</div><br><br></div> </div></body><br>> >> >></html>=3D<br>> >> >><br>> >> >>--_d2a02ece-d492-410e-88fb-fb53737d7219_--<br>> > =<br>> ><br>> >--_7877d7e8-cb4a-4989-bdcd-d406e5b1f51f_<br>> >Content-Type: text/html; charset="iso-8859-1"<br>> >Content-Transfer-Encoding: quoted-printable<br>> ><br>> ><html><br>> ><head><br>> ><style><!--<br>> >.hmmessage P<br>> >{<br>> >margin:0px=3B<br>> >padding:0px<br>> >}<br>> >body.hmmessage<br>> >{<br>> >font-size: 12pt=3B<br>> >font-family:Calibri<br>> >}<br>> >--></style></head><br>> ><body class=3D'hmmessage'><div dir=3D'ltr'><div><span style=3D"font-size: 1=<br>> >2pt=3B ">The following is very efficient:</span></div><div><br></div><div><=<br>> >br></div><div>run through a bunch of records=2C picking out one number from=<br>> > some of them</div><div>append those numbers to a growing vector</div><div>=<br>> >sort the vector</div><div>unique the vector</div><div><br></div><div><br></=<br>> >div><div>sequence allows for random access..but only via a function...</div=<br>> >><div>or maybe an iterator</div><div><br></div><div><br></div><div>STL has =<br>> >this wonderful separation of algorithms from containers=2C via iterators.</=<br>> >div><div>I suspect very few other libraries do.</div><div>And it could be t=<br>> >hat most languages don't support it.</div><div>It doesn't appear I can easi=<br>> >ly sort a sequence=2C unless I copy the data out into an array -- gross ine=<br>> >fficiency.</div><div><br></div><div><br></div><div>I've hacked something ve=<br>> >ry manual together..and it is taking forever to get it to work.</div><div>&=<br>> >nbsp=3B It turns out I can reasonably well bound the size of the data=2C so=<br>> > I'm using an open array...and I have to keep track of my position instead =<br>> >of using addhi/push_back.</div><div>Not happy.</div><div>At some point I mi=<br>> >ght give up and write the backend in C++..at which point I might as well wr=<br>> >ite a C++ frontend anywa.</div><div><br></div><div><br></div><div><br></div=<br>> >><div>I absolutely do not want a sorted table and unique upon insert.</div>=<br>> ><div>That is much less efficient.</div><div>What I'm describing uses tempor=<br>> >arily larger working set but vastly less CPU.</div><div>An array that gets =<br>> >sorted/uniqued occasionally=2C like just once.</div><div>And not ongoing ma=<br>> >intainence for every single add.</div><div><br></div><div><br></div><div><b=<br>> >r></div><div> =3B- Jay</div><div><br><br><br><div><div id=3D"SkyDrivePl=<br>> >aceholder"></div>>=3B To: jay.krell@cornell.edu<br>>=3B CC: m3devel@ele=<br>> >gosoft.com<br>>=3B Subject: Re: [M3devel] STL algorithms? sort/unique?<br=<br>> >>>=3B Date: Fri=2C 28 Sep 2012 01:04:48 -0700<br>>=3B From: mika@async.=<br>> >caltech.edu<br>>=3B <br>>=3B <br>>=3B BTW I had the same experience w=<br>> >hen I first started using Modula-3.<br>>=3B It was painful to jump throug=<br>> >h all its hoops=2C coming from C=2C where you<br>>=3B can do whatever you=<br>> > want to whatever bits happen to be sloshing around<br>>=3B your machine.=<br>> > C++ from what I have seen mainly lets you do that to<br>>=3B more bits =<br>> >in fewer lines of code.<br>>=3B <br>>=3B But after a while I really cam=<br>> >e to appreciate the value of things like the<br>>=3B language's telling m=<br>> >e I'm using the wrong data structure instead of<br>>=3B just letting me u=<br>> >se the same "nice=2C terse=2C efficient" syntax to write<br>>=3B a crappy=<br>> > program :-)<br>>=3B <br>>=3B mika writes:<br>>=3B >=3BYou're using=<br>> > the wrong (abstract) data structure if you want sort and unique.<br>>=3B=<br>> > >=3B<br>>=3B >=3BA "sequence" is meant to be accessed sequentially..=<br>> >.<br>>=3B >=3B<br>>=3B >=3BNot knowing precisely what you're doing =<br>> >it sounds like you might want a<br>>=3B >=3BSortedTable... you can get =<br>> >unique on insert and access it in increasing<br>>=3B >=3Bor decreasing =<br>> >order.<br>>=3B >=3B<br>>=3B >=3B Mika<br>>=3B >=3B<br>>=3B=<br>> > >=3BJay K writes:<br>>=3B >=3B>=3B--_d2a02ece-d492-410e-88fb-fb537=<br>> >37d7219_<br>>=3B >=3B>=3BContent-Type: text/plain=3B charset=3D"iso-8=<br>> >859-1"<br>>=3B >=3B>=3BContent-Transfer-Encoding: quoted-printable<br=<br>> >>>=3B >=3B>=3B<br>>=3B >=3B>=3B I have an IntSeq.T with a bu=<br>> >nch of integers. =3D20<br>>=3B >=3B>=3B What is a good terse eff=<br>> >icient idiom for sort and unique? =3D20<br>>=3B >=3B>=3B<br>>=3B =<br>> >>=3B>=3B In C++ I would say: vector<=3Bint>=3B a=3D3B =<br>> > a.push_back(...)=3D3B =3D<br>>=3B >=3B>=3B a.push_back(...)=<br>> >=3D3B std::sort(a.begin()=3D2C a.end())=3D3B =3D<br>>=3B >=<br>> >=3B>=3B a.resize(std::unique(a.begin()=3D2C a.end()) - a.begin())=3D3B =<br>> > for (aut=3D<br>>=3B >=3B>=3Bo i =3D3D a.begin()=3D3B i !=3D3D a.=<br>> >end()=3D3B ++i) {<br>>=3B >=3B>=3B do stuff with *i }=3D20=<br>> ><br>>=3B >=3B>=3B Nice=3D2C terse=3D2C efficient. In Modula=<br>> >-3? =3D20<br>>=3B >=3B>=3B<br>>=3B >=3B>=3BI know that unique=<br>> > is one of the easiest algorithms to manually write inlin=3D<br>>=3B >=<br>> >=3B>=3Be=3D2Cbut I shouldn't have to.<br>>=3B >=3B>=3B<br>>=3B &g=<br>> >t=3B>=3B(I'm really trying to stay in Modula-3 here=3D2C but it is defini=<br>> >tely a strug=3D<br>>=3B >=3B>=3Bgle. :( )<br>>=3B >=3B>=3B<br>&=<br>> >gt=3B >=3B>=3BThank you=3D2C - Jay<br>>=3B >=3B>=3B<br>>=3B >=<br>> >=3B>=3B =3D<br>>=3B >=3B>=3B<br>>=3B >=3B>=3B--_d2=<br>> >a02ece-d492-410e-88fb-fb53737d7219_<br>>=3B >=3B>=3BContent-Type: tex=<br>> >t/html=3B charset=3D"iso-8859-1"<br>>=3B >=3B>=3BContent-Transfer-Enc=<br>> >oding: quoted-printable<br>>=3B >=3B>=3B<br>>=3B >=3B>=3B<=3B=<br>> >html>=3B<br>>=3B >=3B>=3B<=3Bhead>=3B<br>>=3B >=3B>=3B<=<br>> >=3Bstyle>=3B<=3B!--<br>>=3B >=3B>=3B.hmmessage P<br>>=3B >=3B=<br>> >>=3B{<br>>=3B >=3B>=3Bmargin:0px=3D3B<br>>=3B >=3B>=3Bpadding=<br>> >:0px<br>>=3B >=3B>=3B}<br>>=3B >=3B>=3Bbody.hmmessage<br>>=3B=<br>> > >=3B>=3B{<br>>=3B >=3B>=3Bfont-size: 12pt=3D3B<br>>=3B >=3B&=<br>> >gt=3Bfont-family:Calibri<br>>=3B >=3B>=3B}<br>>=3B >=3B>=3B--&g=<br>> >t=3B<=3B/style>=3B<=3B/head>=3B<br>>=3B >=3B>=3B<=3Bbody cl=<br>> >ass=3D3D'hmmessage'>=3B<=3Bdiv dir=3D3D'ltr'>=3B&=3Bnbsp=3D3B &=<br>> >=3Bnbsp=3D3B&=3Bnbsp=3D3BI have =3D<br>>=3B >=3B>=3Ban IntSeq.T wi=<br>> >th a bunch of integers.&=3Bnbsp=3D3B &=3Bnbsp=3D3B&=3Bnbsp=3D3B<=<br>> >=3Bbr>=3B<=3Bdiv>=3B<=3Bspa=3D<br>>=3B >=3B>=3Bn style=3D3D"f=<br>> >ont-size: 12pt=3D3B ">=3B&=3Bnbsp=3D3B &=3Bnbsp=3D3B<=3B/span>=<br>> >=3B<=3Bspan style=3D3D"font=3D<br>>=3B >=3B>=3B-size: 12pt=3D3B "&g=<br>> >t=3B&=3Bnbsp=3D3B<=3B/span>=3BWhat is a good terse efficient idiom f=<br>> >or so=3D<br>>=3B >=3B>=3Brt and unique?<=3Bspan style=3D3D"font-siz=<br>> >e: 12pt=3D3B ">=3B&=3Bnbsp=3D3B &=3Bnbsp=3D3B<=3B/span>=3B<=<br>> >=3B=3D<br>>=3B >=3B>=3Bspan style=3D3D"font-size: 12pt=3D3B ">=3B&a=<br>> >mp=3Bnbsp=3D3B<=3B/span>=3B<=3B/div>=3B<=3Bdiv>=3B<=3Bbr>=<br>> >=3B<=3B/div>=3B<=3Bdiv=3D<br>>=3B >=3B>=3B>=3B<=3Bbr>=3B&=<br>> >lt=3B/div>=3B<=3Bdiv>=3B&=3Bnbsp=3D3B &=3Bnbsp=3D3B In C++ I wo=<br>> >uld say:<=3Bspan style=3D3D"font-si=3D<br>>=3B >=3B>=3Bze: 12pt=3D3=<br>> >B ">=3B&=3Bnbsp=3D3B &=3Bnbsp=3D3B<=3B/span>=3B<=3Bspan style=<br>> >=3D3D"font-size: 12pt=3D3B ">=3B&=3B=3D<br>>=3B >=3B>=3Bnbsp=3D3=<br>> >B<=3B/span>=3B<=3B/div>=3B<=3Bdiv>=3B<=3Bspan style=3D3D"font=<br>> >-size: 12pt=3D3B ">=3B&=3Bnbsp=3D3B &=3Bnbsp=3D<br>>=3B >=3B>=<br>> >=3B=3D3B<=3B/span>=3B<=3Bspan style=3D3D"font-size: 12pt=3D3B ">=3B=<br>> >&=3Bnbsp=3D3B<=3B/span>=3Bvector&=3Blt=3D3Bin=3D<br>>=3B >=3B=<br>> >>=3Bt&=3Bgt=3D3B a=3D3B<=3Bspan style=3D3D"font-size: 12pt=3D3B ">=<br>> >=3B&=3Bnbsp=3D3B &=3Bnbsp=3D3B<=3B/span>=3B<=3Bsp=3D<br>>=3B =<br>> >>=3B>=3Ban style=3D3D"font-size: 12pt=3D3B ">=3B&=3Bnbsp=3D3B<=<br>> >=3B/span>=3B<=3B/div>=3B<=3Bdiv>=3B<=3Bspan style=3D3D"f=3D<br>=<br>> >>=3B >=3B>=3Bont-size: 12pt=3D3B ">=3B&=3Bnbsp=3D3B &=3Bnbsp=<br>> >=3D3B<=3B/span>=3B<=3Bspan style=3D3D"font-size: 12pt=3D<br>>=3B &g=<br>> >t=3B>=3B=3D3B ">=3B&=3Bnbsp=3D3B<=3B/span>=3Ba.push_back(...)=3D=<br>> >3B<=3Bspan style=3D3D"font-size: 12pt=3D3B "=3D<br>>=3B >=3B>=3B>=<br>> >=3B&=3Bnbsp=3D3B &=3Bnbsp=3D3B<=3B/span>=3B<=3Bspan style=3D3D"=<br>> >font-size: 12pt=3D3B ">=3B&=3Bnbsp=3D3B<=3B/span=3D<br>>=3B >=3B=<br>> >>=3B>=3B<=3B/div>=3B<=3Bdiv>=3B<=3Bdiv>=3B<=3Bspan style=<br>> >=3D3D"font-size: 12pt=3D3B ">=3B&=3Bnbsp=3D3B &=3Bnbsp=3D3B<=3B/s=<br>> >pa=3D<br>>=3B >=3B>=3Bn>=3B<=3Bspan style=3D3D"font-size: 12pt=3D=<br>> >3B ">=3B&=3Bnbsp=3D3B<=3B/span>=3Ba.push_back(...)=3D3B<=3Bsp=3D=<br>> ><br>>=3B >=3B>=3Ban style=3D3D"font-size: 12pt=3D3B ">=3B&=3Bnbs=<br>> >p=3D3B &=3Bnbsp=3D3B<=3B/span>=3B<=3Bspan style=3D3D"fon=3D<br>>=<br>> >=3B >=3B>=3Bt-size: 12pt=3D3B ">=3B&=3Bnbsp=3D3B<=3B/span>=3B&=<br>> >lt=3B/div>=3B<=3Bdiv>=3B<=3Bspan style=3D3D"font-size: 12pt=3D<br>&=<br>> >gt=3B >=3B>=3B=3D3B ">=3B&=3Bnbsp=3D3B &=3Bnbsp=3D3B<=3B/span=<br>> >>=3B<=3Bspan style=3D3D"font-size: 12pt=3D3B ">=3B&=3Bnbsp=3D3B<=<br>> >=3B=3D<br>>=3B >=3B>=3B/span>=3Bstd::sort(a.begin()=3D2C a.end())=<br>> >=3D3B<=3Bspan style=3D3D"font-size: 12pt=3D3B "=3D<br>>=3B >=3B>=3B=<br>> >>=3B&=3Bnbsp=3D3B &=3Bnbsp=3D3B<=3B/span>=3B<=3Bspan style=3D=<br>> >3D"font-size: 12pt=3D3B ">=3B&=3Bnbsp=3D3B<=3B/span=3D<br>>=3B >=<br>> >=3B>=3B>=3B<=3B/div>=3B<=3Bdiv>=3B<=3Bspan style=3D3D"font-si=<br>> >ze: 12pt=3D3B ">=3B&=3Bnbsp=3D3B &=3Bnbsp=3D3B<=3B/span>=3B<=<br>> >=3Bsp=3D<br>>=3B >=3B>=3Ban style=3D3D"font-size: 12pt=3D3B ">=3B&a=<br>> >mp=3Bnbsp=3D3B<=3B/span>=3Ba.resize(std::unique(a.begi=3D<br>>=3B >=<br>> >=3B>=3Bn()=3D2C a.end()) - a.begin())=3D3B<=3Bspan style=3D3D"font-size=<br>> >: 12pt=3D3B ">=3B&=3Bnbsp=3D3B=3D<br>>=3B >=3B>=3B &=3Bnbsp=<br>> >=3D3B<=3B/span>=3B<=3Bspan style=3D3D"font-size: 12pt=3D3B ">=3B&am=<br>> >p=3Bnbsp=3D3B<=3B/span>=3B<=3B/div>=3B<=3Bd=3D<br>>=3B >=3B&g=<br>> >t=3Biv>=3B<=3Bspan style=3D3D"font-size: 12pt=3D3B ">=3B&=3Bnbsp=<br>> >=3D3B &=3Bnbsp=3D3B for (auto i =3D3D a.=3D<br>>=3B >=3B>=3Bbegin(=<br>> >)=3D3B i !=3D3D a.end()=3D3B ++i)<=3B/span>=3B<=3B/div>=3B<=3Bdiv=<br>> >>=3B<=3Bspan style=3D3D"font-size=3D<br>>=3B >=3B>=3B: 12pt=3D3B =<br>> >">=3B&=3Bnbsp=3D3B &=3Bnbsp=3D3B {<=3Bbr>=3B&=3Bnbsp=3D3B &a=<br>> >mp=3Bnbsp=3D3B &=3Bnbsp=3D3B do stuff with=3D<br>>=3B >=3B>=3B *i&=<br>> >lt=3B/span>=3B<=3B/div>=3B<=3Bdiv>=3B<=3Bspan style=3D3D"font-s=<br>> >ize: 12pt=3D3B ">=3B&=3Bnbsp=3D3B &=3Bnbsp=3D3B =3D<br>>=3B >=<br>> >=3B>=3B}<=3B/span>=3B<=3B/div>=3B<=3Bdiv>=3B&=3Bnbsp=3D3B&=<br>> >lt=3B/div>=3B<=3Bdiv>=3B<=3Bbr>=3B<=3B/div>=3B<=3Bdiv>=3B=<br>> ><=3Bspan style=3D3D"font-si=3D<br>>=3B >=3B>=3Bze: 12pt=3D3B ">=<br>> >=3B&=3Bnbsp=3D3B &=3Bnbsp=3D3B<=3B/span>=3B<=3Bspan style=3D3D"=<br>> >font-size: 12pt=3D3B ">=3B&=3B=3D<br>>=3B >=3B>=3Bnbsp=3D3B<=<br>> >=3B/span>=3BNice=3D2C terse=3D2C efficient.<=3Bspan style=3D3D"font-siz=<br>> >e: 12pt=3D3B =3D<br>>=3B >=3B>=3B">=3B&=3Bnbsp=3D3B &=3Bnbsp=<br>> >=3D3B<=3B/span>=3B<=3Bspan style=3D3D"font-size: 12pt=3D3B ">=3B&am=<br>> >p=3Bnbsp=3D3B<=3B/spa=3D<br>>=3B >=3B>=3Bn>=3B<=3B/div>=3B<=<br>> >=3Bdiv>=3B<=3Bspan style=3D3D"font-size: 12pt=3D3B ">=3B&=3Bnbsp=<br>> >=3D3B &=3Bnbsp=3D3B<=3B/span>=3B<=3Bs=3D<br>>=3B >=3B>=3Bpan=<br>> > style=3D3D"font-size: 12pt=3D3B ">=3B&=3Bnbsp=3D3B<=3B/span>=3BIn=<br>> > Modula-3?<=3Bspan style=3D3D=3D<br>>=3B >=3B>=3B"font-size: 12pt=<br>> >=3D3B ">=3B&=3Bnbsp=3D3B &=3Bnbsp=3D3B<=3B/span>=3B<=3Bspan s=<br>> >tyle=3D3D"font-size: 12p=3D<br>>=3B >=3B>=3Bt=3D3B ">=3B&=3Bnbsp=<br>> >=3D3B<=3B/span>=3B<=3B/div>=3B<=3Bdiv>=3B<=3Bbr>=3B<=3B/d=<br>> >iv>=3B<=3Bdiv>=3B<=3Bbr>=3B<=3B/div>=3B<=3Bdiv>=3BI know =<br>> >that =3D<br>>=3B >=3B>=3Bunique is one of the easiest algorithms to m=<br>> >anually write inline=3D2C<=3B/div>=3B<=3Bd=3D<br>>=3B >=3B>=3Bi=<br>> >v>=3Bbut I shouldn't have to.<=3B/div>=3B<=3Bdiv>=3B<=3Bbr>=<br>> >=3B<=3B/div>=3B<=3Bdiv>=3B<=3Bbr>=3B<=3B/div>=3B<=3Bdiv&g=<br>> >t=3B(I'm re=3D<br>>=3B >=3B>=3Bally trying to stay in Modula-3 here=<br>> >=3D2C but it is definitely a struggle. :(=3D<br>>=3B >=3B>=3B )<=3B=<br>> >/div>=3B<=3Bdiv>=3B<=3Bbr>=3B<=3B/div>=3B<=3Bdiv>=3B<=<br>> >=3Bbr>=3B<=3B/div>=3B<=3Bdiv>=3BThank you=3D2C<=3B/div>=3B<=<br>> >=3Bdiv>=3B&=3Bnbsp=3D3B-=3D<br>>=3B >=3B>=3B Jay<=3B/div>=3B=<br>> ><=3Bbr>=3B<=3Bbr>=3B<=3B/div>=3B <=3B/div>=3B<=<br>> >=3B/body>=3B<br>>=3B >=3B>=3B<=3B/html>=3B=3D<br>>=3B >=3B&=<br>> >gt=3B<br>>=3B >=3B>=3B--_d2a02ece-d492-410e-88fb-fb53737d7219_--<br><=<br>> >/div></div> </div></body><br>> ></html>=<br>> ><br>> >--_7877d7e8-cb4a-4989-bdcd-d406e5b1f51f_--<br></div></div></div> </div></body>
</html>