From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2cb1f0b6d642e1dc X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!dn9g2000vbb.googlegroups.com!not-for-mail From: Phil Clayton Newsgroups: comp.lang.ada Subject: Re: Pascal Calling Convention Date: Wed, 30 Mar 2011 06:42:39 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <9b04626e-567d-408c-aab3-39b964b3ffd6@l2g2000prg.googlegroups.com> <4d90efdd$1$14806$882e7ee2@usenet-news.net> <330393be-cb82-4cd8-ba44-6e59af7b75bf@v11g2000prb.googlegroups.com> <4d90fd41$1$14782$882e7ee2@usenet-news.net> <4d911e17$0$6776$9b4e6d93@newsspool3.arcor-online.net> NNTP-Posting-Host: 91.110.248.185 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1301492559 16756 127.0.0.1 (30 Mar 2011 13:42:39 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 30 Mar 2011 13:42:39 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: dn9g2000vbb.googlegroups.com; posting-host=91.110.248.185; posting-account=v7gx3AoAAABfjb9m5b7l_Lt2KVEgQBIe User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-GB; rv:1.9.1.9) Gecko/20100330 Fedora/3.5.9-1.fc12 Firefox/3.5.9,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:19572 Date: 2011-03-30T06:42:39-07:00 List-Id: On Mar 29, 1:23 pm, stefan-lu...@see-the.signature wrote: > The original C++ from Hyman Rosen was > > template > class set > { > =A0 =A0 unsigned n; =A0 =A0// number of members in set > =A0 =A0 unsigned d[N]; // members are in d[0..n-1] > =A0 =A0 unsigned s[N]; // d[s[k]] =3D=3D k if k is a member > =A0 =A0 // unspecified elements of d and s are arbitrary > > public: > =A0 =A0 set() : n(0) { } > =A0 =A0 bool has(unsigned k) > =A0 =A0 =A0 =A0 { return k < N && s[k] < n && d[s[k]] =3D=3D k; } > =A0 =A0 void add(unsigned k) > =A0 =A0 =A0 =A0 { if (k < N && !has(k)) { d[n] =3D k; s[k] =3D n++; } > =A0 =A0 void del(unsigned k) > =A0 =A0 =A0 =A0 { if (has(k)) { unsigned i =3D s[k]; d[i] =3D d[--n]; s[d= [i]] =3D i; } > =A0 =A0 void clr() { n =3D 0; } > > }; Interesting. It's worth noting that if N is equal to the number of keys representable by unsigned and every key is added to the set, n++ in the final add will 'overflow' because n (of type unsigned) needs to be able to have the range 0 .. N, i.e. N + 1 distinct values. I doubt this would cause a problem in practice because 1. unsigned is likely to be at least 32 bits these days(?) so N will be much smaller; 2. these are designed for sparse arrays, there is a low probability of filling the entire array. Clearly I'm not the first person to notice this though... On Mar 29, 1:23 pm, stefan-lu...@see-the.signature wrote: > type Elements is mod <>; > ... > subtype Counter_Type is Integer range 0 .. Integer(Elements'Last)+1; Phil