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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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-7-bit Path: g2news1.google.com!news4.google.com!feeder.news-service.com!feeder.erje.net!news-2.dfn.de!news.dfn.de!news.uni-weimar.de!not-for-mail From: stefan-lucks@see-the.signature Newsgroups: comp.lang.ada Subject: Re: Pascal Calling Convention Date: Tue, 29 Mar 2011 14:23:49 +0200 Organization: Bauhaus-Universitaet Weimar 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> Reply-To: stefan-lucks@see-the.signature NNTP-Posting-Host: medsec1.medien.uni-weimar.de Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: tigger.scc.uni-weimar.de 1301401563 26051 141.54.178.228 (29 Mar 2011 12:26:03 GMT) X-Complaints-To: news@tigger.scc.uni-weimar.de NNTP-Posting-Date: Tue, 29 Mar 2011 12:26:03 +0000 (UTC) X-X-Sender: lucks@medsec1.medien.uni-weimar.de In-Reply-To: <4d911e17$0$6776$9b4e6d93@newsspool3.arcor-online.net> Xref: g2news1.google.com comp.lang.ada:18575 Date: 2011-03-29T14:23:49+02:00 List-Id: On Tue, 29 Mar 2011, Georg Bauhaus wrote: > A transliteration attempt follows, with these additions in mind. Very nice, indeed. Here is a bare minimum version, which is closer to the original proposal. Note that in Ada we don't need to perform the explicit check for K < N, unlike C++. pragma Profile(Ravenscar); pragma Restrictions (No_Allocators); generic type Elements is mod <>; package USets is type Set is tagged private; function Has(This : Set; K : Elements) return Boolean; -- K has been stored in This procedure Add(This : in out Set; K: Elements); -- Insert K into This. Don't do anything if K is already there. procedure Del(This : in out Set; K: Elements); -- Remove K from This. Don't do anything if K isn't there. procedure clr(This : in out Set); -- Set This to the empty set. private type A_Type is array (Elements) of Elements; subtype Counter_Type is Integer range 0 .. Integer(Elements'Last)+1; type Set is tagged record N : Counter_Type := 0; S, D : A_Type; -- if I is in Set then D(S(I))=I end record; end USets; --------- package body USets is function Has(This : Set; K: Elements) return Boolean is N: Counter_Type renames This.N; S: A_Type renames This.S; D: A_Type renames This.D; begin return Integer(S(K)) < N and then D(S(K))=K; end Has; procedure Add(This : in out Set; K: Elements) is N: Counter_Type renames This.N; S: A_Type renames This.S; D: A_Type renames This.D; begin if not This.Has(K) then D(Elements(N)) := K; S(K) := Elements(N); -- now D(S(K))=K; N := N + 1; end if; end Add; procedure Del(This : in out Set; K: Elements) is N: Counter_Type renames This.N; S: A_Type renames This.S; D: A_Type renames This.D; begin if This.Has(K) then declare I: Elements := S(K); begin N := N - 1; D(I) := D(Elements(N)); S(D(I)) := I; end; end if; end Del; procedure Clr(This : in out Set) is N : Counter_Type renames This.N; begin N := 0; end Clr; end USets; --------- The original C++ from Hyman Rosen was template class set { unsigned n; // number of members in set unsigned d[N]; // members are in d[0..n-1] unsigned s[N]; // d[s[k]] == k if k is a member // unspecified elements of d and s are arbitrary public: set() : n(0) { } bool has(unsigned k) { return k < N && s[k] < n && d[s[k]] == k; } void add(unsigned k) { if (k < N && !has(k)) { d[n] = k; s[k] = n++; } void del(unsigned k) { if (has(k)) { unsigned i = s[k]; d[i] = d[--n]; s[d[i]] = i; } void clr() { n = 0; } }; -- ------ Stefan Lucks -- Bauhaus-University Weimar -- Germany ------ Stefan dot Lucks at uni minus weimar dot de ------ I love the taste of Cryptanalysis in the morning! ------