Re: Comments on Math_BaseX - was Re: [PEAR-DEV] Question about package.xml

From: Date: Wed, 11 Dec 2002 23:40:59 +0000
Subject: Re: Comments on Math_BaseX - was Re: [PEAR-DEV] Question about package.xml
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-11574@lists.php.net to get a copy of this message
Hi Dave, --- Dave Mertens <dave@zyprexia.com> wrote: > On Tue, Dec 10, 2002 at 01:43:22PM -0800, Jesus M. Castagnetto wrote: > > It might be more explicit to name if Math_BaseConvert (but that is > debatable, > > Math_BaseX would also work fine), also the init() method might be better > named > > as setBase() accepting a base number (e.g. 2 or 23) and use the default > > conventions for bases 2 to 36 (i.e. the charset [0-9A-Z], the range() > function > > will help here), if the base number is bigger than 36 then check for an > > optional second parameter w/ the charset. Using internal lookup tables is > > always faster ;-) > This class is more flexible that only going to base36.. The character set for > the base is variable. Yep, I gathered that much from the code. What threw me off was that it was included in the Math_* namespace, which is why at first approach I was expecting to conform to base standard used in math where for the first 36 bases you use the alphanumeric charset, and from then on you are on your own ;-) Perhaps you can do both and support the normal mathematicl base char sets or random charsets. For example, the method that initializes the valid set of chars you could accept 2 parameters, check if the first one is numeric or a string. If it is a string, then the user wants to use a non-standard charset base (like in your case), and then ignore the second parameter. If the first parameter is numeric, check if the second parameter is a string, which will mean the same as the previous case, with the addition that you can also check that the base and the number of chars in the string match. Finally, if the second parameter is not a string, ignore it and use the usual mathematical conventions, just making sure that 2 <= base <= 36. Additionally, when a non-standard charset is being use, there should be a method that checks for uniqueness of all chars (count_chars() will here here). > I use this class to encode an ordernumber for use in an email. The user must > reply by visiting the link in the email. > We're using base13 (Only 13 characters from the alfabet). > > This class is indeed basicly doing the same as base_convert only with a > variable character set, > [0-9][A-Z][a-z][+/] will be look similar to base64 encoding, (which isn't > equal to base64_encode, because that function is using a totally different > algorithm (convert 3 8-byte numbers into 4 6-byte numbers)) I see. That is more akin to data encoding that numerical base transformation which has a definite meaning in math. Text_BaseEncoding might have been a more explicit moniker perhaps? > Renaming the init method to setBase is fine with me. > > > Also, you might want to check for the actual value of the integer passed, > and > > decide to use the base_convert() function from PHP accordingly, that way > most > > of the simple cases will be handled at the C level rather than in PHP code. > That's not possible if my character set is 'ACEGIKMOQSUWY'. This would be > base13. base_convert would using [0-9][A-C]. Yes, as it should be from a strict mathematical conventions point of view, which is not the data/text/information set encoding point of view that your class addresses. > > Finally, the encode()/decode() methods might be named toBase()/toDecimal(), > and > > should check that in the first method it is getting a base 10 number and in > the > > second it is getting a number that has valid chars according to the set > base, > > if something is not correct, then they can just return a PEAR::raiseError() > I agree that i have to add some checking to the class. toBase and toDecimal > is also fine with me.. > > > Let me know if I can give a hand (not that I think you need it by looking > at > > your code ;-) > Just watch tonight (CEST time) your CVS mails ;-) Cheers. ===== --- Jesus M. Castagnetto (jcastagnetto@yahoo.com) Research: http://metallo.scripps.edu/ Personal: http://www.castagnetto.org/ __________________________________________________ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com

« previous php.pear.dev (#11574) next »