Article View: chile.comp.programacion
Article #85Re: Pregunta ordenes de tiempo en PHP
From: Cristian Gutierrez
Date: Fri, 09 Sep 2005 03:56
Date: Fri, 09 Sep 2005 03:56
42 lines
4100 bytes
4100 bytes
Hoy en la noche, Jos� Miguel Santib��ez dijo: > En el cap�tulo anterior (news:dfqn6d$u0h$1@localhost.localdomain), Chano > <chano@lj.NOSPAM.cl> dijo: > >> En PHP, si tengo un array, $variable[$indice] = algo , por ejemplo >> , en donde $indice >> es un valor entero mayor a cero y no consecutivo (9,1,345, 123, 244), >> cual es el orden ( O(x) ) de hacer la operacion: >> >> if ( $variable[$valor] ) [...] > Hmmm.. lamento no tener respuesta real a tu pregunta, aunque hay que > aclarar que la premisa inicial no es correcta. Ese if no solo chequea si un > valor est� definido como llave, sino que adem�s la data sea distinta de > null y/o 0. > > De hecho, la forma correcta ser�a: if(array_key_exists($valor, $variable)) > aunque las discusiones en php.net afirman que es m�s lenta... Sin embargo, > tengo la impresi�n que para el caso que planteas, lo m�s probable es que > sean similares... Pero al no conocer la forma en que opera la funci�n, no > se si es posible indicar el orden... (hace a�os que no veo nada de eso). Segun [1] (llamado desde [2]), pareciera ser una tabla de hash de las tipicas, O(1) en general (no me atrevo a decir "en promedio" :-S) y O(n) en el peor caso. Las macros Z_STRVAL_PP y Z_LVAL_PP deberian dar la pista de como se calcula el hash (ulong de C) de un valor (string o long de PHP). Ahora, si no es mucha la indiscrecion, que motivaria tanto hurgueteo? Si estas implementando algo que debe ser muy pero muy eficiente, quizas hacerlo en PHP no era lo mas indicado... ? [1] <http://chora.php.net/co.php/ZendEngine2/zend_hash.c?r=1.124#1126> [2] <http://chora.php.net/co.php/php-src/ext/standard/array.c?r=1.199.2.44.2.7#3540> -- Cristian Gutierrez /* crgutier@dcc.uchile.cl */ The three most dangerous things are a programmer with a soldering iron, a manager who codes, and a user who gets ideas.
Technical Details
Message-ID:
<87fyse99mq.fsf@bender.guti.cl>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!atl-c02.usenetserver.com!news.usenetserver.com!atl-c04.usenetserver.com!news.usenetserver.com!newsfeed.yul.equant.net!news-santiago!helcaraxe.dcc.uchile.cl!bender.guti.cl!newsReferences:
<dfqn6d$u0h$1@localhost.localdomain> <Xns96CBE9C9F77EFjmsnews@200.27.221.71>Show Full Headers
Complete Article Headers
X-Google-Thread: 1593cb,ba4785603e789050 X-Google-Thread: 107d6b,ba4785603e789050 X-Google-Attributes: gid1593cb,gid107d6b,public X-Google-Language: SPANISH,ASCII Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!atl-c02.usenetserver.com!news.usenetserver.com!atl-c04.usenetserver.com!news.usenetserver.com!newsfeed.yul.equant.net!news-santiago!helcaraxe.dcc.uchile.cl!bender.guti.cl!news From: Cristian Gutierrez <crgutier@dcc.uchile.cl> Newsgroups: chile.comp.programacion,chile.comp.misc Subject: Re: Pregunta ordenes de tiempo en PHP Date: Thu, 08 Sep 2005 23:56:45 -0400 Organization: DCC - Universidad de Chile Lines: 42 Message-ID: <87fyse99mq.fsf@bender.guti.cl> References: <dfqn6d$u0h$1@localhost.localdomain> <Xns96CBE9C9F77EFjmsnews@200.27.221.71> NNTP-Posting-Host: anakena.dcc.uchile.cl Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: helcaraxe.dcc.uchile.cl 1126238402 16741 192.80.24.6 (9 Sep 2005 04:00:02 GMT) X-Complaints-To: newsmaster@dcc.uchile.cl NNTP-Posting-Date: Fri, 9 Sep 2005 04:00:02 +0000 (UTC) Face: iVBORw0KGgoAAAANSUhEUgAAADwAAAA8AgMAAABHkjHhAAAADFBMVEUWFhZfX1+ioqL6+vr8 dj+QAAAAAWJLR0QAiAUdSAAAAg5JREFUeNql0s9r02AYB/B4GIHuoAgVVmG9CVYwf4ILrht40Ynd dEXioWUsA3PaQQ8LKHpYLnbTThwiHbWYV9Sj9rL36NUObGkPUrVzuIs/6BvyluZ9ljcxaXI2lzwf eJOH9/k+AvhP/7j/Fv65OxMzmynhqO1zH/So+29NLeqvh6YU8WADmemIP4lxL8pxp6p3o2aZegZl R3YyaBJNaaGHKkqgxOXQNkKXzLQR+g9C6+b5kfcQevgmpYRuIrRZn5BCryO0US3ogW1BdV0J+3dz grpXmQXYfuf5nkLH5ksK/SIrnq/rg26ioTmdygtupwgWHSvoTnvF4CZl17dOYNoWy9yNPOzXfstg tYtXuR9o0JwlL+HgeWGBW8ZgGBbFnWUhw33Sbdz6TvHN1ey8a3YGIN+6T2C5PYFdD2sA6d5FAu9v LH3WBbAJBgmIDJ3ioooFoCzPNDq5in82TX7egsdXcE+0pZ3sEr+fxW7XoCvS3HRS4f7rrGHojRP0 6A72TOtuoBrZnVvz5kGIzVejX0jpvi2bF0Q+iz1TWuXFwbOkP7/hrrdaH58u+HakX7wwSsF8/eDT wf45417kFwIPd7yIcWDS52UDApevuZ86p0PLK1tuZHpoBN8YLgOM9pswfft/vO9oMf9g6UbMYNij /jDYglZwHRCYIIgx56aO4earyPlD89R0Mvo/9kR9HfgIgorhXaQc58oAAAAASUVORK5CYII= User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:2q88DDX7oc0aqvdBAi+eW3Zw0Ow=