From: Honza M. <hon...@ec...> - 2003-02-03 10:45:33
|
On P=E1, 2003-01-31 at 23:08, Mitra wrote: > Honza >=20 > Did you make this change to new_id? > I don't see it in the new_id in the current CVS I do not send it to CVS, yet. I have quite a lot of changes, which I do not want to send to CVS at this time. If you can add it here I will appreciate it: /** * Returns new unpacked md5 unique id, except these which can force * unexpected end of string (or other problems) */ function new_id ($seed=3D"hugo"){ do { $foo=3Dmd5(uniqid($seed)); } while (ereg("(00|27)",$foo) || (substr($foo,30,2)=3D=3D'20')); =20 // '00' is end of string, '27' is ' and packed '20' is space,=20 // which is removed by MySQL return $foo; }=20 Honza > - Mitra >=20 >=20 > At 2:43 PM +0100 25/1/03, Honza Malik wrote: > > Hi Mitra, > >=20 > > I did some more testing on ids and now I know, where the problem > > is. > > The new_id() is OK - it returns allways 32 character long id, but > > sometimes it return id with ...20 at the end. Packed '20' is space > > and > > this is problem, because if you insert 16 characters long packed id > > ending with space into MySQL and then you get it back, the id is 15 > > character long. > >=20 > > MySQL REMOVES ENDING SPACES FROM INSERTED STRING! > > I will fix new_id() to not generate such ids. > >=20 > >=20 > > On P=E1, 2003-01-24 at 12:28, Mitra wrote: > > > Ok - stranger .... my guess was wrong, md5 returns a 32 character > > > string, which cannot contain 00 or 27 so cannot end up as a > > shorter > > > string. > > > > > > To test, I ran a loop through 99999 samples of new_id, which > > should > > > have generated about 400 bad ids by your statistics. > > > > > > I think the bad ids in your database must be the result of some > > buggy > > > earlier code. > > > > > > Lets try three things. > > > 1: Please check my test - appended at the end of this message. > >=20 > > I test it and all 99999 ids are 32 characters long. > >=20 > > > 2: Please re-run your test, see if the number of bad ids has gone > > up, > > > if there is something bad then as long as you have created more > > than > > > 256 ids then statistically it should have increased by 1 or more. > >=20 > > Increased: [16] =3D> 92254 [15] =3D> 367 [14] =3D> 4 > >=20 > > > 3: Please send the code for your test, I'll run it on my > > installation > > > and see how many odd length ids I have. > >=20 > > require "include/config.php3"; > > require $GLOBALS[AA_INC_PATH]."util.php3"; > > require $GLOBALS[AA_INC_PATH]."locsessi.php3"; > >=20 > > $db =3D new DB_AA; > >=20 > > $db->query( "SELECT id from item" ); > > while($db->next_record()) { > > $fromdb[$len_p =3D strlen($db->f('id'))]++; > > $unpdb[$len_u =3D strlen(unpack_id($db->f('id')))]++; > > // if( $len_p<16 ) > > // echo "<br>".$db->f('id'); > > } =20 > >=20 > > huh($fromdb, 'packed'); > > huh($unpdb, 'unpacked'); > > echo " > > Regards > > Honza "; > > > > > > - Mitra > > > > > > > > > At 11:55 PM +0100 22/1/03, Honza Malik wrote: > > > > >3) Your assumption that packed ids are EXACTLY 16 characters > > long (and > > > > >unpacked are EXACTLY 32 characters long) is unfortunately > > wrong. I can't > > > > >say you why - we generate the ids by new_id() function, but in > > our > > > > >database are packed ids for item 16 (in 91907 items), 15 (366) > > and 14 > > > > >(4) characters long. > > > > > > > > Strange - because new_id uses "md5" which has to return 128 > > bits. > > > > > > > > I wonder if these were ids which generated a leading ascii > > zero, the > > > > ratios look reasonable for this, i.e. 919007/366 =3D 251, which > > is > > > > close to a one in 256 chance, i.e. something that occurred when > > 8 > > > > bits (2^8=3D256) all were zero. This makes sense if we assume > > that > > > > md5 returns a number which the ereg in new_id casts as a > > string, and > > > > so ignores the leading zero. > > > > > > > > I've fixed zids.php3 to allow 12..16 character packed ids, and > > 24..32 > > > > long, but this could break my tagged ids. I've also fixed > > > > util.php3.new_id to only return a string of exactly 16 chars. > > > > > > > > > >5) In zids.php3 you wrote: > > > >> > > > > >> >function id_t2l(&$str) { > > > >> >#TODO: Look online for quicker way to substr last 32 chars - > > mitra > > > >> > if (ereg("(.*)([0-9a-f]{32})",$str,$parts)) > > > >> > return $parts[2]; > > > >> > > > > >> >The quicker way is: substr($str, -32), but see 3) > > > >> > > > >> Ok - I'll make this 24..32, and I guess we can't use tags that > > end in > > > >> a hex character [0-9a-f) > > > > > > > >Or you can use some delimeter (tag:unpacked_id). As I write > > before, we > > > >never use tags so far, so the syntax is on your choice. > > > > > > > > > require "../include/config.php3"; > > > require $GLOBALS[AA_INC_PATH]."util.php3"; > > > > > > $i =3D 0; > > > $j=3D 99999; > > > print "<br>Testing start, loops=3D$j: sample=3D"; > > > $foo =3D new_id(); > > > print $foo; > > > while ($i++ < $j) { > > > $foo =3D new_id(); > > > if (strlen($foo) !=3D 32) print > > "<br>FOO:$i:$foo:strlen=3D".strlen($foo); > > > if (strlen(pack_id($foo)) !=3D 16) print "<br>FOO:$i:$foo:packed > > > strlen=3D".strlen(\ > > > pack_id($foo)); > > > } > > > print "<br>Testing end sample =3D "; > > > $foo =3D new_id(); > > > print $foo; > > > > > > print "Done\n"; > > > > >=20 > >=20 > >=20 > > ------------------------------------------------------- > > This SF.NET email is sponsored by: > > SourceForge Enterprise Edition + IBM + LinuxWorld > > http://www.vasoftware.com > > _______________________________________________ > > Apc-aa-coders mailing list > > Apc...@li... > > https://lists.sourceforge.net/lists/listinfo/apc-aa-coders >=20 >=20 >=20 > --=20 > Mitra Technology Consulting - www.mitra.biz - mi...@mi... > 02-6684-8096 or 0414-648-0722=20 >=20 > Life is a Mystery to be Lived, not a Problem to be Solved >=20 |