[M3devel] STL algorithms? sort/unique?

Jay K jay.krell at cornell.edu
Sat Sep 29 21:10:40 CEST 2012


 > The separation of algorithms from containers sounds a bit like a bug.
It isn't. It is a leap that allows for far greater code reuse. Efficiently.(You could do it inefficiently with lots of function pointers -- templates allowfor inlinability. C++ beats C for performance here.)

Imagine I have written quicksort.In C++ we have at least the following worthwhile "array-like" data structures:

  The builtin arrays. Like Modula-3 fixed arrays.

  Arrays you get with new[]. Like Modula-3 open arrays, but they don't expose their size.

  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.

  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.

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.

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.

There are "bidirectional iterators" which can, roughly speaking, only be incremented and decremented and dereferenced. Doubly linked lists expose these.

There are "output iterators".They are similar to "input".

input streams (cin, like stdin) exposes an input iterator.You can copy from it.Copy is another simple reusable algorithm.

output streams (cout, like stdout) exposes an output iterator.You can copy to it.

There are many more examples.Of course, besides quick sort, there is a stable sort.There is finding sequences.There is binary_search.There is upper_bound/lower_bound/equal_range which are like binary_search.There is unique.There is partition.Many many more, "built in" to the library.That work with multiple "built in" containers, and can work with custom containers as well.

I strongly recommend you read up on this stuff.It is really quite illimuninating. Good stuff.Teaches us how to better factor our code.And to strive for better factoring, when we find people have invented/discovered such things.

"Iterators" already do occur in Modula-3 libraries.

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.

I hand coded something.It took me a while to get it to work due to stupid small details.The result is significantly worse than I would have gotten in C++.Bigger code. Slower code. More copies. More heap allocations.I can eliminate one of the allocations by merging the next step.But in C++ I naturally wouldn't have had it anyway.Not great.

 - Jay


> To: jay.krell at cornell.edu
> CC: mika at async.caltech.edu; m3devel at elegosoft.com
> Subject: Re: [M3devel] STL algorithms? sort/unique?
> Date: Sat, 29 Sep 2012 11:29:48 -0700
> From: mika at async.caltech.edu
> 
> 
> Well that depends on how you maintain the vector, no?
> 
> SortedTable uses "treaps" which are supposed to be good data structures.
> Too new to have made it into Knuth, last I checked.  The amortized cost
> of your operations shouldn't be much worse than with your method, with
> the additional benefit that the sorted order is maintained dynamically.
> 
> The separation of algorithms from containers sounds a bit like a bug.
> You have to be careful so you don't shoot yourself in the foot there!
> (Sorting a list using an algorithm that randomly accesses elements,
> say...)
> 
> The Modula-3 approach is that you figure out what you want to do, pick
> the ADT you want that provides the minimal set of operations, import
> that interface, then instantiate a more carefully chosen implementation
> of the ADT.  The language itself obviously can be coaxed into supporting the
> algorithm/data structure separation but no one uses it that way as
> far as I know.  (Modula-3 generics are not that well explored, actually.
> I suspect there are many things you can do with them that no one has
> tried.)
> 
>      Mika
> 
> Jay K writes:
> >--_7877d7e8-cb4a-4989-bdcd-d406e5b1f51f_
> >Content-Type: text/plain; charset="iso-8859-1"
> >Content-Transfer-Encoding: quoted-printable
> >
> >The following is very efficient:
> >
> >run through a bunch of records=2C picking out one number from some of thema=
> >ppend those numbers to a growing vectorsort the vectorunique the vector
> >
> >sequence allows for random access..but only via a function...or maybe an it=
> >erator
> >
> >STL has this wonderful separation of algorithms from containers=2C via iter=
> >ators.I suspect very few other libraries do.And it could be that most langu=
> >ages don't support it.It doesn't appear I can easily sort a sequence=2C unl=
> >ess I copy the data out into an array -- gross inefficiency.
> >
> >I've hacked something very manual together..and it is taking forever to get=
> > it to work.  It turns out I can reasonably well bound the size of the data=
> >=2C so I'm using an open array...and I have to keep track of my position in=
> >stead of using addhi/push_back.Not happy.At some point I might give up and =
> >write the backend in C++..at which point I might as well write a C++ fronte=
> >nd anywa.
> >
> >
> >I absolutely do not want a sorted table and unique upon insert.That is much=
> > less efficient.What I'm describing uses temporarily larger working set but=
> > vastly less CPU.An array that gets sorted/uniqued occasionally=2C like jus=
> >t once.And not ongoing maintainence for every single add.
> >
> >
> > - Jay
> >
> >
> >> To: jay.krell at cornell.edu
> >> CC: m3devel at elegosoft.com
> >> Subject: Re: [M3devel] STL algorithms? sort/unique?
> >> Date: Fri=2C 28 Sep 2012 01:04:48 -0700
> >> From: mika at async.caltech.edu
> >>=20
> >>=20
> >> BTW I had the same experience when I first started using Modula-3.
> >> It was painful to jump through all its hoops=2C coming from C=2C where yo=
> >u
> >> can do whatever you want to whatever bits happen to be sloshing around
> >> your machine.  C++ from what I have seen mainly lets you do that to
> >> more bits in fewer lines of code.
> >>=20
> >> But after a while I really came to appreciate the value of things like th=
> >e
> >> language's telling me I'm using the wrong data structure instead of
> >> just letting me use the same "nice=2C terse=2C efficient" syntax to write
> >> a crappy program :-)
> >>=20
> >> mika writes:
> >> >You're using the wrong (abstract) data structure if you want sort and un=
> >ique.
> >> >
> >> >A "sequence" is meant to be accessed sequentially...
> >> >
> >> >Not knowing precisely what you're doing it sounds like you might want a
> >> >SortedTable... you can get unique on insert and access it in increasing
> >> >or decreasing order.
> >> >
> >> >    Mika
> >> >
> >> >Jay K writes:
> >> >>--_d2a02ece-d492-410e-88fb-fb53737d7219_
> >> >>Content-Type: text/plain=3B charset=3D"iso-8859-1"
> >> >>Content-Transfer-Encoding: quoted-printable
> >> >>
> >> >>    I have an IntSeq.T with a bunch of integers.   =3D20
> >> >>    What is a good terse efficient idiom for sort and unique?   =3D20
> >> >>
> >> >>    In C++ I would say:        vector<int> a=3D3B        a.push_back(..=
> >.)=3D3B =3D
> >> >>       a.push_back(...)=3D3B        std::sort(a.begin()=3D2C a.end())=
> >=3D3B       =3D
> >> >> a.resize(std::unique(a.begin()=3D2C a.end()) - a.begin())=3D3B        =
> >for (aut=3D
> >> >>o i =3D3D a.begin()=3D3B i !=3D3D a.end()=3D3B ++i)    {
> >> >>      do stuff with *i    }=3D20
> >> >>    Nice=3D2C terse=3D2C efficient.        In Modula-3?   =3D20
> >> >>
> >> >>I know that unique is one of the easiest algorithms to manually write i=
> >nlin=3D
> >> >>e=3D2Cbut I shouldn't have to.
> >> >>
> >> >>(I'm really trying to stay in Modula-3 here=3D2C but it is definitely a=
> > strug=3D
> >> >>gle. :( )
> >> >>
> >> >>Thank you=3D2C - Jay
> >> >>
> >> >> 		 	   		  =3D
> >> >>
> >> >>--_d2a02ece-d492-410e-88fb-fb53737d7219_
> >> >>Content-Type: text/html=3B charset=3D"iso-8859-1"
> >> >>Content-Transfer-Encoding: quoted-printable
> >> >>
> >> >><html>
> >> >><head>
> >> >><style><!--
> >> >>.hmmessage P
> >> >>{
> >> >>margin:0px=3D3B
> >> >>padding:0px
> >> >>}
> >> >>body.hmmessage
> >> >>{
> >> >>font-size: 12pt=3D3B
> >> >>font-family:Calibri
> >> >>}
> >> >>--></style></head>
> >> >><body class=3D3D'hmmessage'><div dir=3D3D'ltr'>&nbsp=3D3B &nbsp=3D3B&nb=
> >sp=3D3BI have =3D
> >> >>an IntSeq.T with a bunch of integers.&nbsp=3D3B &nbsp=3D3B&nbsp=3D3B<br=
> >><div><spa=3D
> >> >>n style=3D3D"font-size: 12pt=3D3B ">&nbsp=3D3B &nbsp=3D3B</span><span s=
> >tyle=3D3D"font=3D
> >> >>-size: 12pt=3D3B ">&nbsp=3D3B</span>What is a good terse efficient idio=
> >m for so=3D
> >> >>rt and unique?<span style=3D3D"font-size: 12pt=3D3B ">&nbsp=3D3B &nbsp=
> >=3D3B</span><=3D
> >> >>span style=3D3D"font-size: 12pt=3D3B ">&nbsp=3D3B</span></div><div><br>=
> ></div><div=3D
> >> >>><br></div><div>&nbsp=3D3B &nbsp=3D3B In C++ I would say:<span style=3D=
> >3D"font-si=3D
> >> >>ze: 12pt=3D3B ">&nbsp=3D3B &nbsp=3D3B</span><span style=3D3D"font-size:=
> > 12pt=3D3B ">&=3D
> >> >>nbsp=3D3B</span></div><div><span style=3D3D"font-size: 12pt=3D3B ">&nbs=
> >p=3D3B &nbsp=3D
> >> >>=3D3B</span><span style=3D3D"font-size: 12pt=3D3B ">&nbsp=3D3B</span>ve=
> >ctor&lt=3D3Bin=3D
> >> >>t&gt=3D3B a=3D3B<span style=3D3D"font-size: 12pt=3D3B ">&nbsp=3D3B &nbs=
> >p=3D3B</span><sp=3D
> >> >>an style=3D3D"font-size: 12pt=3D3B ">&nbsp=3D3B</span></div><div><span =
> >style=3D3D"f=3D
> >> >>ont-size: 12pt=3D3B ">&nbsp=3D3B &nbsp=3D3B</span><span style=3D3D"font=
> >-size: 12pt=3D
> >> >>=3D3B ">&nbsp=3D3B</span>a.push_back(...)=3D3B<span style=3D3D"font-siz=
> >e: 12pt=3D3B "=3D
> >> >>>&nbsp=3D3B &nbsp=3D3B</span><span style=3D3D"font-size: 12pt=3D3B ">&n=
> >bsp=3D3B</span=3D
> >> >>></div><div><div><span style=3D3D"font-size: 12pt=3D3B ">&nbsp=3D3B &nb=
> >sp=3D3B</spa=3D
> >> >>n><span style=3D3D"font-size: 12pt=3D3B ">&nbsp=3D3B</span>a.push_back(=
> >...)=3D3B<sp=3D
> >> >>an style=3D3D"font-size: 12pt=3D3B ">&nbsp=3D3B &nbsp=3D3B</span><span =
> >style=3D3D"fon=3D
> >> >>t-size: 12pt=3D3B ">&nbsp=3D3B</span></div><div><span style=3D3D"font-s=
> >ize: 12pt=3D
> >> >>=3D3B ">&nbsp=3D3B &nbsp=3D3B</span><span style=3D3D"font-size: 12pt=3D=
> >3B ">&nbsp=3D3B<=3D
> >> >>/span>std::sort(a.begin()=3D2C a.end())=3D3B<span style=3D3D"font-size:=
> > 12pt=3D3B "=3D
> >> >>>&nbsp=3D3B &nbsp=3D3B</span><span style=3D3D"font-size: 12pt=3D3B ">&n=
> >bsp=3D3B</span=3D
> >> >>></div><div><span style=3D3D"font-size: 12pt=3D3B ">&nbsp=3D3B &nbsp=3D=
> >3B</span><sp=3D
> >> >>an style=3D3D"font-size: 12pt=3D3B ">&nbsp=3D3B</span>a.resize(std::uni=
> >que(a.begi=3D
> >> >>n()=3D2C a.end()) - a.begin())=3D3B<span style=3D3D"font-size: 12pt=3D3=
> >B ">&nbsp=3D3B=3D
> >> >> &nbsp=3D3B</span><span style=3D3D"font-size: 12pt=3D3B ">&nbsp=3D3B</s=
> >pan></div><d=3D
> >> >>iv><span style=3D3D"font-size: 12pt=3D3B ">&nbsp=3D3B &nbsp=3D3B for (a=
> >uto i =3D3D a.=3D
> >> >>begin()=3D3B i !=3D3D a.end()=3D3B ++i)</span></div><div><span style=3D=
> >3D"font-size=3D
> >> >>: 12pt=3D3B ">&nbsp=3D3B &nbsp=3D3B {<br>&nbsp=3D3B &nbsp=3D3B &nbsp=3D=
> >3B do stuff with=3D
> >> >> *i</span></div><div><span style=3D3D"font-size: 12pt=3D3B ">&nbsp=3D3B=
> > &nbsp=3D3B =3D
> >> >>}</span></div><div>&nbsp=3D3B</div><div><br></div><div><span style=3D3D=
> >"font-si=3D
> >> >>ze: 12pt=3D3B ">&nbsp=3D3B &nbsp=3D3B</span><span style=3D3D"font-size:=
> > 12pt=3D3B ">&=3D
> >> >>nbsp=3D3B</span>Nice=3D2C terse=3D2C efficient.<span style=3D3D"font-si=
> >ze: 12pt=3D3B =3D
> >> >>">&nbsp=3D3B &nbsp=3D3B</span><span style=3D3D"font-size: 12pt=3D3B ">&=
> >nbsp=3D3B</spa=3D
> >> >>n></div><div><span style=3D3D"font-size: 12pt=3D3B ">&nbsp=3D3B &nbsp=
> >=3D3B</span><s=3D
> >> >>pan style=3D3D"font-size: 12pt=3D3B ">&nbsp=3D3B</span>In Modula-3?<spa=
> >n style=3D3D=3D
> >> >>"font-size: 12pt=3D3B ">&nbsp=3D3B &nbsp=3D3B</span><span style=3D3D"fo=
> >nt-size: 12p=3D
> >> >>t=3D3B ">&nbsp=3D3B</span></div><div><br></div><div><br></div><div>I kn=
> >ow that =3D
> >> >>unique is one of the easiest algorithms to manually write inline=3D2C</=
> >div><d=3D
> >> >>iv>but I shouldn't have to.</div><div><br></div><div><br></div><div>(I'=
> >m re=3D
> >> >>ally trying to stay in Modula-3 here=3D2C but it is definitely a strugg=
> >le. :(=3D
> >> >> )</div><div><br></div><div><br></div><div>Thank you=3D2C</div><div>&nb=
> >sp=3D3B-=3D
> >> >> Jay</div><br><br></div> 		 	   		  </div></body>
> >> >></html>=3D
> >> >>
> >> >>--_d2a02ece-d492-410e-88fb-fb53737d7219_--
> > 		 	   		  =
> >
> >--_7877d7e8-cb4a-4989-bdcd-d406e5b1f51f_
> >Content-Type: text/html; charset="iso-8859-1"
> >Content-Transfer-Encoding: quoted-printable
> >
> ><html>
> ><head>
> ><style><!--
> >.hmmessage P
> >{
> >margin:0px=3B
> >padding:0px
> >}
> >body.hmmessage
> >{
> >font-size: 12pt=3B
> >font-family:Calibri
> >}
> >--></style></head>
> ><body class=3D'hmmessage'><div dir=3D'ltr'><div><span style=3D"font-size: 1=
> >2pt=3B ">The following is very efficient:</span></div><div><br></div><div><=
> >br></div><div>run through a bunch of records=2C picking out one number from=
> > some of them</div><div>append those numbers to a growing vector</div><div>=
> >sort the vector</div><div>unique the vector</div><div><br></div><div><br></=
> >div><div>sequence allows for random access..but only via a function...</div=
> >><div>or maybe an iterator</div><div><br></div><div><br></div><div>STL has =
> >this wonderful separation of algorithms from containers=2C via iterators.</=
> >div><div>I suspect very few other libraries do.</div><div>And it could be t=
> >hat most languages don't support it.</div><div>It doesn't appear I can easi=
> >ly sort a sequence=2C unless I copy the data out into an array -- gross ine=
> >fficiency.</div><div><br></div><div><br></div><div>I've hacked something ve=
> >ry manual together..and it is taking forever to get it to work.</div><div>&=
> >nbsp=3B It turns out I can reasonably well bound the size of the data=2C so=
> > I'm using an open array...and I have to keep track of my position instead =
> >of using addhi/push_back.</div><div>Not happy.</div><div>At some point I mi=
> >ght give up and write the backend in C++..at which point I might as well wr=
> >ite a C++ frontend anywa.</div><div><br></div><div><br></div><div><br></div=
> >><div>I absolutely do not want a sorted table and unique upon insert.</div>=
> ><div>That is much less efficient.</div><div>What I'm describing uses tempor=
> >arily larger working set but vastly less CPU.</div><div>An array that gets =
> >sorted/uniqued occasionally=2C like just once.</div><div>And not ongoing ma=
> >intainence for every single add.</div><div><br></div><div><br></div><div><b=
> >r></div><div>&nbsp=3B- Jay</div><div><br><br><br><div><div id=3D"SkyDrivePl=
> >aceholder"></div>&gt=3B To: jay.krell at cornell.edu<br>&gt=3B CC: m3devel at ele=
> >gosoft.com<br>&gt=3B Subject: Re: [M3devel] STL algorithms? sort/unique?<br=
> >>&gt=3B Date: Fri=2C 28 Sep 2012 01:04:48 -0700<br>&gt=3B From: mika at async.=
> >caltech.edu<br>&gt=3B <br>&gt=3B <br>&gt=3B BTW I had the same experience w=
> >hen I first started using Modula-3.<br>&gt=3B It was painful to jump throug=
> >h all its hoops=2C coming from C=2C where you<br>&gt=3B can do whatever you=
> > want to whatever bits happen to be sloshing around<br>&gt=3B your machine.=
> >  C++ from what I have seen mainly lets you do that to<br>&gt=3B more bits =
> >in fewer lines of code.<br>&gt=3B <br>&gt=3B But after a while I really cam=
> >e to appreciate the value of things like the<br>&gt=3B language's telling m=
> >e I'm using the wrong data structure instead of<br>&gt=3B just letting me u=
> >se the same "nice=2C terse=2C efficient" syntax to write<br>&gt=3B a crappy=
> > program :-)<br>&gt=3B <br>&gt=3B mika writes:<br>&gt=3B &gt=3BYou're using=
> > the wrong (abstract) data structure if you want sort and unique.<br>&gt=3B=
> > &gt=3B<br>&gt=3B &gt=3BA "sequence" is meant to be accessed sequentially..=
> >.<br>&gt=3B &gt=3B<br>&gt=3B &gt=3BNot knowing precisely what you're doing =
> >it sounds like you might want a<br>&gt=3B &gt=3BSortedTable... you can get =
> >unique on insert and access it in increasing<br>&gt=3B &gt=3Bor decreasing =
> >order.<br>&gt=3B &gt=3B<br>&gt=3B &gt=3B    Mika<br>&gt=3B &gt=3B<br>&gt=3B=
> > &gt=3BJay K writes:<br>&gt=3B &gt=3B&gt=3B--_d2a02ece-d492-410e-88fb-fb537=
> >37d7219_<br>&gt=3B &gt=3B&gt=3BContent-Type: text/plain=3B charset=3D"iso-8=
> >859-1"<br>&gt=3B &gt=3B&gt=3BContent-Transfer-Encoding: quoted-printable<br=
> >>&gt=3B &gt=3B&gt=3B<br>&gt=3B &gt=3B&gt=3B    I have an IntSeq.T with a bu=
> >nch of integers.   =3D20<br>&gt=3B &gt=3B&gt=3B    What is a good terse eff=
> >icient idiom for sort and unique?   =3D20<br>&gt=3B &gt=3B&gt=3B<br>&gt=3B =
> >&gt=3B&gt=3B    In C++ I would say:        vector&lt=3Bint&gt=3B a=3D3B    =
> >    a.push_back(...)=3D3B =3D<br>&gt=3B &gt=3B&gt=3B       a.push_back(...)=
> >=3D3B        std::sort(a.begin()=3D2C a.end())=3D3B       =3D<br>&gt=3B &gt=
> >=3B&gt=3B a.resize(std::unique(a.begin()=3D2C a.end()) - a.begin())=3D3B   =
> >     for (aut=3D<br>&gt=3B &gt=3B&gt=3Bo i =3D3D a.begin()=3D3B i !=3D3D a.=
> >end()=3D3B ++i)    {<br>&gt=3B &gt=3B&gt=3B      do stuff with *i    }=3D20=
> ><br>&gt=3B &gt=3B&gt=3B    Nice=3D2C terse=3D2C efficient.        In Modula=
> >-3?   =3D20<br>&gt=3B &gt=3B&gt=3B<br>&gt=3B &gt=3B&gt=3BI know that unique=
> > is one of the easiest algorithms to manually write inlin=3D<br>&gt=3B &gt=
> >=3B&gt=3Be=3D2Cbut I shouldn't have to.<br>&gt=3B &gt=3B&gt=3B<br>&gt=3B &g=
> >t=3B&gt=3B(I'm really trying to stay in Modula-3 here=3D2C but it is defini=
> >tely a strug=3D<br>&gt=3B &gt=3B&gt=3Bgle. :( )<br>&gt=3B &gt=3B&gt=3B<br>&=
> >gt=3B &gt=3B&gt=3BThank you=3D2C - Jay<br>&gt=3B &gt=3B&gt=3B<br>&gt=3B &gt=
> >=3B&gt=3B 		 	   		  =3D<br>&gt=3B &gt=3B&gt=3B<br>&gt=3B &gt=3B&gt=3B--_d2=
> >a02ece-d492-410e-88fb-fb53737d7219_<br>&gt=3B &gt=3B&gt=3BContent-Type: tex=
> >t/html=3B charset=3D"iso-8859-1"<br>&gt=3B &gt=3B&gt=3BContent-Transfer-Enc=
> >oding: quoted-printable<br>&gt=3B &gt=3B&gt=3B<br>&gt=3B &gt=3B&gt=3B&lt=3B=
> >html&gt=3B<br>&gt=3B &gt=3B&gt=3B&lt=3Bhead&gt=3B<br>&gt=3B &gt=3B&gt=3B&lt=
> >=3Bstyle&gt=3B&lt=3B!--<br>&gt=3B &gt=3B&gt=3B.hmmessage P<br>&gt=3B &gt=3B=
> >&gt=3B{<br>&gt=3B &gt=3B&gt=3Bmargin:0px=3D3B<br>&gt=3B &gt=3B&gt=3Bpadding=
> >:0px<br>&gt=3B &gt=3B&gt=3B}<br>&gt=3B &gt=3B&gt=3Bbody.hmmessage<br>&gt=3B=
> > &gt=3B&gt=3B{<br>&gt=3B &gt=3B&gt=3Bfont-size: 12pt=3D3B<br>&gt=3B &gt=3B&=
> >gt=3Bfont-family:Calibri<br>&gt=3B &gt=3B&gt=3B}<br>&gt=3B &gt=3B&gt=3B--&g=
> >t=3B&lt=3B/style&gt=3B&lt=3B/head&gt=3B<br>&gt=3B &gt=3B&gt=3B&lt=3Bbody cl=
> >ass=3D3D'hmmessage'&gt=3B&lt=3Bdiv dir=3D3D'ltr'&gt=3B&amp=3Bnbsp=3D3B &amp=
> >=3Bnbsp=3D3B&amp=3Bnbsp=3D3BI have =3D<br>&gt=3B &gt=3B&gt=3Ban IntSeq.T wi=
> >th a bunch of integers.&amp=3Bnbsp=3D3B &amp=3Bnbsp=3D3B&amp=3Bnbsp=3D3B&lt=
> >=3Bbr&gt=3B&lt=3Bdiv&gt=3B&lt=3Bspa=3D<br>&gt=3B &gt=3B&gt=3Bn style=3D3D"f=
> >ont-size: 12pt=3D3B "&gt=3B&amp=3Bnbsp=3D3B &amp=3Bnbsp=3D3B&lt=3B/span&gt=
> >=3B&lt=3Bspan style=3D3D"font=3D<br>&gt=3B &gt=3B&gt=3B-size: 12pt=3D3B "&g=
> >t=3B&amp=3Bnbsp=3D3B&lt=3B/span&gt=3BWhat is a good terse efficient idiom f=
> >or so=3D<br>&gt=3B &gt=3B&gt=3Brt and unique?&lt=3Bspan style=3D3D"font-siz=
> >e: 12pt=3D3B "&gt=3B&amp=3Bnbsp=3D3B &amp=3Bnbsp=3D3B&lt=3B/span&gt=3B&lt=
> >=3B=3D<br>&gt=3B &gt=3B&gt=3Bspan style=3D3D"font-size: 12pt=3D3B "&gt=3B&a=
> >mp=3Bnbsp=3D3B&lt=3B/span&gt=3B&lt=3B/div&gt=3B&lt=3Bdiv&gt=3B&lt=3Bbr&gt=
> >=3B&lt=3B/div&gt=3B&lt=3Bdiv=3D<br>&gt=3B &gt=3B&gt=3B&gt=3B&lt=3Bbr&gt=3B&=
> >lt=3B/div&gt=3B&lt=3Bdiv&gt=3B&amp=3Bnbsp=3D3B &amp=3Bnbsp=3D3B In C++ I wo=
> >uld say:&lt=3Bspan style=3D3D"font-si=3D<br>&gt=3B &gt=3B&gt=3Bze: 12pt=3D3=
> >B "&gt=3B&amp=3Bnbsp=3D3B &amp=3Bnbsp=3D3B&lt=3B/span&gt=3B&lt=3Bspan style=
> >=3D3D"font-size: 12pt=3D3B "&gt=3B&amp=3B=3D<br>&gt=3B &gt=3B&gt=3Bnbsp=3D3=
> >B&lt=3B/span&gt=3B&lt=3B/div&gt=3B&lt=3Bdiv&gt=3B&lt=3Bspan style=3D3D"font=
> >-size: 12pt=3D3B "&gt=3B&amp=3Bnbsp=3D3B &amp=3Bnbsp=3D<br>&gt=3B &gt=3B&gt=
> >=3B=3D3B&lt=3B/span&gt=3B&lt=3Bspan style=3D3D"font-size: 12pt=3D3B "&gt=3B=
> >&amp=3Bnbsp=3D3B&lt=3B/span&gt=3Bvector&amp=3Blt=3D3Bin=3D<br>&gt=3B &gt=3B=
> >&gt=3Bt&amp=3Bgt=3D3B a=3D3B&lt=3Bspan style=3D3D"font-size: 12pt=3D3B "&gt=
> >=3B&amp=3Bnbsp=3D3B &amp=3Bnbsp=3D3B&lt=3B/span&gt=3B&lt=3Bsp=3D<br>&gt=3B =
> >&gt=3B&gt=3Ban style=3D3D"font-size: 12pt=3D3B "&gt=3B&amp=3Bnbsp=3D3B&lt=
> >=3B/span&gt=3B&lt=3B/div&gt=3B&lt=3Bdiv&gt=3B&lt=3Bspan style=3D3D"f=3D<br>=
> >&gt=3B &gt=3B&gt=3Bont-size: 12pt=3D3B "&gt=3B&amp=3Bnbsp=3D3B &amp=3Bnbsp=
> >=3D3B&lt=3B/span&gt=3B&lt=3Bspan style=3D3D"font-size: 12pt=3D<br>&gt=3B &g=
> >t=3B&gt=3B=3D3B "&gt=3B&amp=3Bnbsp=3D3B&lt=3B/span&gt=3Ba.push_back(...)=3D=
> >3B&lt=3Bspan style=3D3D"font-size: 12pt=3D3B "=3D<br>&gt=3B &gt=3B&gt=3B&gt=
> >=3B&amp=3Bnbsp=3D3B &amp=3Bnbsp=3D3B&lt=3B/span&gt=3B&lt=3Bspan style=3D3D"=
> >font-size: 12pt=3D3B "&gt=3B&amp=3Bnbsp=3D3B&lt=3B/span=3D<br>&gt=3B &gt=3B=
> >&gt=3B&gt=3B&lt=3B/div&gt=3B&lt=3Bdiv&gt=3B&lt=3Bdiv&gt=3B&lt=3Bspan style=
> >=3D3D"font-size: 12pt=3D3B "&gt=3B&amp=3Bnbsp=3D3B &amp=3Bnbsp=3D3B&lt=3B/s=
> >pa=3D<br>&gt=3B &gt=3B&gt=3Bn&gt=3B&lt=3Bspan style=3D3D"font-size: 12pt=3D=
> >3B "&gt=3B&amp=3Bnbsp=3D3B&lt=3B/span&gt=3Ba.push_back(...)=3D3B&lt=3Bsp=3D=
> ><br>&gt=3B &gt=3B&gt=3Ban style=3D3D"font-size: 12pt=3D3B "&gt=3B&amp=3Bnbs=
> >p=3D3B &amp=3Bnbsp=3D3B&lt=3B/span&gt=3B&lt=3Bspan style=3D3D"fon=3D<br>&gt=
> >=3B &gt=3B&gt=3Bt-size: 12pt=3D3B "&gt=3B&amp=3Bnbsp=3D3B&lt=3B/span&gt=3B&=
> >lt=3B/div&gt=3B&lt=3Bdiv&gt=3B&lt=3Bspan style=3D3D"font-size: 12pt=3D<br>&=
> >gt=3B &gt=3B&gt=3B=3D3B "&gt=3B&amp=3Bnbsp=3D3B &amp=3Bnbsp=3D3B&lt=3B/span=
> >&gt=3B&lt=3Bspan style=3D3D"font-size: 12pt=3D3B "&gt=3B&amp=3Bnbsp=3D3B&lt=
> >=3B=3D<br>&gt=3B &gt=3B&gt=3B/span&gt=3Bstd::sort(a.begin()=3D2C a.end())=
> >=3D3B&lt=3Bspan style=3D3D"font-size: 12pt=3D3B "=3D<br>&gt=3B &gt=3B&gt=3B=
> >&gt=3B&amp=3Bnbsp=3D3B &amp=3Bnbsp=3D3B&lt=3B/span&gt=3B&lt=3Bspan style=3D=
> >3D"font-size: 12pt=3D3B "&gt=3B&amp=3Bnbsp=3D3B&lt=3B/span=3D<br>&gt=3B &gt=
> >=3B&gt=3B&gt=3B&lt=3B/div&gt=3B&lt=3Bdiv&gt=3B&lt=3Bspan style=3D3D"font-si=
> >ze: 12pt=3D3B "&gt=3B&amp=3Bnbsp=3D3B &amp=3Bnbsp=3D3B&lt=3B/span&gt=3B&lt=
> >=3Bsp=3D<br>&gt=3B &gt=3B&gt=3Ban style=3D3D"font-size: 12pt=3D3B "&gt=3B&a=
> >mp=3Bnbsp=3D3B&lt=3B/span&gt=3Ba.resize(std::unique(a.begi=3D<br>&gt=3B &gt=
> >=3B&gt=3Bn()=3D2C a.end()) - a.begin())=3D3B&lt=3Bspan style=3D3D"font-size=
> >: 12pt=3D3B "&gt=3B&amp=3Bnbsp=3D3B=3D<br>&gt=3B &gt=3B&gt=3B &amp=3Bnbsp=
> >=3D3B&lt=3B/span&gt=3B&lt=3Bspan style=3D3D"font-size: 12pt=3D3B "&gt=3B&am=
> >p=3Bnbsp=3D3B&lt=3B/span&gt=3B&lt=3B/div&gt=3B&lt=3Bd=3D<br>&gt=3B &gt=3B&g=
> >t=3Biv&gt=3B&lt=3Bspan style=3D3D"font-size: 12pt=3D3B "&gt=3B&amp=3Bnbsp=
> >=3D3B &amp=3Bnbsp=3D3B for (auto i =3D3D a.=3D<br>&gt=3B &gt=3B&gt=3Bbegin(=
> >)=3D3B i !=3D3D a.end()=3D3B ++i)&lt=3B/span&gt=3B&lt=3B/div&gt=3B&lt=3Bdiv=
> >&gt=3B&lt=3Bspan style=3D3D"font-size=3D<br>&gt=3B &gt=3B&gt=3B: 12pt=3D3B =
> >"&gt=3B&amp=3Bnbsp=3D3B &amp=3Bnbsp=3D3B {&lt=3Bbr&gt=3B&amp=3Bnbsp=3D3B &a=
> >mp=3Bnbsp=3D3B &amp=3Bnbsp=3D3B do stuff with=3D<br>&gt=3B &gt=3B&gt=3B *i&=
> >lt=3B/span&gt=3B&lt=3B/div&gt=3B&lt=3Bdiv&gt=3B&lt=3Bspan style=3D3D"font-s=
> >ize: 12pt=3D3B "&gt=3B&amp=3Bnbsp=3D3B &amp=3Bnbsp=3D3B =3D<br>&gt=3B &gt=
> >=3B&gt=3B}&lt=3B/span&gt=3B&lt=3B/div&gt=3B&lt=3Bdiv&gt=3B&amp=3Bnbsp=3D3B&=
> >lt=3B/div&gt=3B&lt=3Bdiv&gt=3B&lt=3Bbr&gt=3B&lt=3B/div&gt=3B&lt=3Bdiv&gt=3B=
> >&lt=3Bspan style=3D3D"font-si=3D<br>&gt=3B &gt=3B&gt=3Bze: 12pt=3D3B "&gt=
> >=3B&amp=3Bnbsp=3D3B &amp=3Bnbsp=3D3B&lt=3B/span&gt=3B&lt=3Bspan style=3D3D"=
> >font-size: 12pt=3D3B "&gt=3B&amp=3B=3D<br>&gt=3B &gt=3B&gt=3Bnbsp=3D3B&lt=
> >=3B/span&gt=3BNice=3D2C terse=3D2C efficient.&lt=3Bspan style=3D3D"font-siz=
> >e: 12pt=3D3B =3D<br>&gt=3B &gt=3B&gt=3B"&gt=3B&amp=3Bnbsp=3D3B &amp=3Bnbsp=
> >=3D3B&lt=3B/span&gt=3B&lt=3Bspan style=3D3D"font-size: 12pt=3D3B "&gt=3B&am=
> >p=3Bnbsp=3D3B&lt=3B/spa=3D<br>&gt=3B &gt=3B&gt=3Bn&gt=3B&lt=3B/div&gt=3B&lt=
> >=3Bdiv&gt=3B&lt=3Bspan style=3D3D"font-size: 12pt=3D3B "&gt=3B&amp=3Bnbsp=
> >=3D3B &amp=3Bnbsp=3D3B&lt=3B/span&gt=3B&lt=3Bs=3D<br>&gt=3B &gt=3B&gt=3Bpan=
> > style=3D3D"font-size: 12pt=3D3B "&gt=3B&amp=3Bnbsp=3D3B&lt=3B/span&gt=3BIn=
> > Modula-3?&lt=3Bspan style=3D3D=3D<br>&gt=3B &gt=3B&gt=3B"font-size: 12pt=
> >=3D3B "&gt=3B&amp=3Bnbsp=3D3B &amp=3Bnbsp=3D3B&lt=3B/span&gt=3B&lt=3Bspan s=
> >tyle=3D3D"font-size: 12p=3D<br>&gt=3B &gt=3B&gt=3Bt=3D3B "&gt=3B&amp=3Bnbsp=
> >=3D3B&lt=3B/span&gt=3B&lt=3B/div&gt=3B&lt=3Bdiv&gt=3B&lt=3Bbr&gt=3B&lt=3B/d=
> >iv&gt=3B&lt=3Bdiv&gt=3B&lt=3Bbr&gt=3B&lt=3B/div&gt=3B&lt=3Bdiv&gt=3BI know =
> >that =3D<br>&gt=3B &gt=3B&gt=3Bunique is one of the easiest algorithms to m=
> >anually write inline=3D2C&lt=3B/div&gt=3B&lt=3Bd=3D<br>&gt=3B &gt=3B&gt=3Bi=
> >v&gt=3Bbut I shouldn't have to.&lt=3B/div&gt=3B&lt=3Bdiv&gt=3B&lt=3Bbr&gt=
> >=3B&lt=3B/div&gt=3B&lt=3Bdiv&gt=3B&lt=3Bbr&gt=3B&lt=3B/div&gt=3B&lt=3Bdiv&g=
> >t=3B(I'm re=3D<br>&gt=3B &gt=3B&gt=3Bally trying to stay in Modula-3 here=
> >=3D2C but it is definitely a struggle. :(=3D<br>&gt=3B &gt=3B&gt=3B )&lt=3B=
> >/div&gt=3B&lt=3Bdiv&gt=3B&lt=3Bbr&gt=3B&lt=3B/div&gt=3B&lt=3Bdiv&gt=3B&lt=
> >=3Bbr&gt=3B&lt=3B/div&gt=3B&lt=3Bdiv&gt=3BThank you=3D2C&lt=3B/div&gt=3B&lt=
> >=3Bdiv&gt=3B&amp=3Bnbsp=3D3B-=3D<br>&gt=3B &gt=3B&gt=3B Jay&lt=3B/div&gt=3B=
> >&lt=3Bbr&gt=3B&lt=3Bbr&gt=3B&lt=3B/div&gt=3B 		 	   		  &lt=3B/div&gt=3B&lt=
> >=3B/body&gt=3B<br>&gt=3B &gt=3B&gt=3B&lt=3B/html&gt=3B=3D<br>&gt=3B &gt=3B&=
> >gt=3B<br>&gt=3B &gt=3B&gt=3B--_d2a02ece-d492-410e-88fb-fb53737d7219_--<br><=
> >/div></div> 		 	   		  </div></body>
> ></html>=
> >
> >--_7877d7e8-cb4a-4989-bdcd-d406e5b1f51f_--
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20120929/6a18c380/attachment-0002.html>


More information about the M3devel mailing list