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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,bd45e29f9dafca87 X-Google-Attributes: gid103376,public From: Gautier Subject: Re: bitwise comparators Date: 2000/01/18 Message-ID: <3883B6BA.476AD55@maths.unine.ch>#1/1 X-Deja-AN: 573985350 Content-Transfer-Encoding: 7bit References: <3880D375.7E363123@hotmail.com> <38829638.0@news.pacifier.com> <3882FC1C.2BA8C959@hotmail.com> <85vmn2$ki1$1@nnrp1.deja.com> <38836CF2.AB738B8B@hotmail.com> <388394E0.55D1E913@maths.unine.ch> <38838989.4F158467@hotmail.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Trace: 18 Jan 2000 00:40:07 +0100, 130.125.13.32 MIME-Version: 1.0 Newsgroups: comp.lang.ada Date: 2000-01-18T00:00:00+00:00 List-Id: Alexander Van Hecke wrote: > > > use structs and callback functions and you have perfect generic types! > > You imagine a rather inefficient way to implement generics. > As a matter of fact, this way is more efficient than using templates! Templates have to > be copied and filled in -> lots of overhead. If you use callback functions in structs, > all you have to do is link the correct pointers to the adresses of the functions and > that's it. I see - indeed for some "percent bar" feedback purposes I do so if callback doen't need to be inlined+optimized. It saves space. But genericity embrace more than functions but all sorts of parameters. One usage is to produce lots of overhead, but for each instance an optimized code for it. A trivial example of it is the PKZip `explode' method that appears in 2 versions, almost the same, apart of 2 parameters. As variables they would slow down the code, so it is preferable to instanciate twice the code with these numbers built-in and let the optimizer squeeze the shifts etc. But, only one copy of source is needed generic needed: integer; mask: unsigned_32; procedure explode_lit ( tb, tl, td : p_Table_list; bb, bl, bd : integer ); (etc.) Then, the instanciations: -- **************** exploding, method: 8k slide, 3 trees ***************** procedure explode_lit8 is new explode_lit( 7, 16#7F# ); -- **************** exploding, method: 4k slide, 3 trees ***************** procedure explode_lit4 is new explode_lit( 6, 16#3F# ); See http://members.xoom.com/_XMCM/gdemont/uza_html/unz_expl__adb.htm#60_11 For that a C macro would fit a best, wouldn't it ? But you can do more abstracted things like... generic -- to provide: type ring_elt is private; -- ring element type zero, one: ring_elt; -- 0 and 1 elements with function "-" (a:ring_elt) return ring_elt; -- unary oper. with function "+" (a,b:ring_elt) return ring_elt; -- binary oper. with function "*" (a,b:ring_elt) return ring_elt; package Frac is type frac_elt is record a,b:ring_elt; end record; -- define fraction frac_0: constant frac_elt:= (zero,one); frac_1: constant frac_elt:= (one,one); (...) and use it for creating rational numbers: package Rationals is new Frac_Euclid(Integer, 0,1, "-","+","-","*","/"); then rational polynomials: package Rationals.Polynomials is new Polynomials( frac_elt, frac_0, frac_1, "-","+","-","*","/","=" ); then using Frac again to create rational functions! (end of generic trip - the subject is so wide... ) -- Gautier _____\\________________\_______\ http://members.xoom.com/gdemont/