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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,bc4137777a63bff X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.scarlet.biz!news.scarlet.biz.POSTED!not-for-mail NNTP-Posting-Date: Thu, 28 Jul 2005 13:32:29 -0500 Newsgroups: comp.lang.ada Subject: Re: Help needed for ada package References: <1122305318.728942.304120@f14g2000cwb.googlegroups.com> <2OudnZo-iL1aN3jfRVn-iQ@comcast.com> <1122475184.849564.159870@g44g2000cwa.googlegroups.com> <1122547648.069514.63520@g14g2000cwa.googlegroups.com> From: Ludovic Brenta Date: Thu, 28 Jul 2005 20:33:32 +0200 Message-ID: <87ll3qwzk3.fsf@tiscali.be> User-Agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:LaO5HA7dAxDQuYYruHDLVzGQ2lg= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii NNTP-Posting-Host: 83.134.238.169 X-Trace: sv3-XypaobJGKGRFEXFV7dVULYqkhHaS9JWfdDTBc6I+Qc+VAwFe1wE8l4RGWRvJummUvAqrHhXx5Kg1c9V!Hu+CkwtyTgKdchrVRdp6LaLC7SpJk1SSZgjP27chJyEP8jJUQp5xS9dK2RXit6nJ X-Complaints-To: abuse@scarlet.be X-DMCA-Complaints-To: abuse@scarlet.biz 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.32 Xref: g2news1.google.com comp.lang.ada:3824 Date: 2005-07-28T20:33:32+02:00 List-Id: Whoa, everyone seems to be going over the top, I think the solution can be much simpler. generic type ID is (<>); --some discrete type to be put here package POP is --update database type Rating is new Integer range 0..255; procedure Rate (Citizen : in ID; Badness : in Rating); procedure Associate (Citizen_1, Citizen_2 : in ID); --query the database function Most_Dangerous return ID; function Next_Member return ID; function More_In_Group return Boolean; --administrative procedure reset; end POP; Since the type ID is discrete, why not just use that as the array index type? package body POP is Society : array (ID) of Rating := (others => Rating'First); Associacion : array (ID, ID) of Boolean := (others => others => False)); pragma Pack (Association); Last_Reported : ID := ID'First; procedure Rate (Citizen : in ID; Badness : in Rating) is begin Society (Citizen) := Rating; end Rate; procedure Associate (Citizen_1, Citizen_2 : in ID) is begin Association (Citizen_1, Citizen_2) := True; end Associate; function Most_Dagerous return ID is Result : ID := ID'First; begin for J in Society'Range loop if Society (J) > Result then Result := J; end if; end loop; return Result; end Most_Dangerous; function Next_Member return ID is J : constant ID := Most_Dangerous; begin if Last_Reported = ID'First then Last_Reported := J; end if; for K in ID'Succ (Last_Reported) .. Association'Last (2) loop if Association (J, K) then Last_Reported := K; exit; end loop; end loop; return Last_Reported; end Next_Member; function More_In_Group return Boolean is J : constant ID := Most_Dangerous; Result : Boolean := False; begin for K in ID'Succ (Last_Reported) .. Association'Last (2) loop if Association (J, K) then Result := True; exit; end loop; end loop; return Result; end More_In_Group; procedure Reset is begin Society := (others => Rating'First); Association := (others => others => False)); Last_Reported := ID'First; end Reset; end POP; Of course, the above solution is outrageously inefficient, both memory- and CPU-wise. Optimisations are left as an exercise to the reader. -- Ludovic Brenta.