Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46596 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97202 invoked from network); 3 Jan 2010 14:30:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Jan 2010 14:30:16 -0000 Authentication-Results: pb1.pair.com smtp.mail=patchnow@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=patchnow@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.226 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: patchnow@gmail.com X-Host-Fingerprint: 209.85.219.226 mail-ew0-f226.google.com Received: from [209.85.219.226] ([209.85.219.226:56117] helo=mail-ew0-f226.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AD/EC-12956-7F9A04B4 for ; Sun, 03 Jan 2010 09:30:16 -0500 Received: by ewy26 with SMTP id 26so12194241ewy.23 for ; Sun, 03 Jan 2010 06:30:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:cc:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=BE1DOh8dxp9UkoeQZhLraQhlc002TiuPLH6TuQWIFpY=; b=gKuHINTcb6SDI2Ikdf6MyRYM3VN9R+2NhMu0h4o76WU64e6++pXkphy1EDLO0Yqk63 E4/r2mzYoFT9td+LqI0C574EDbGjYfdk0NKCCgHzRe4zvIkxvgqTwygYhcRNWodfT+25 CpbVLPLlJvOfSb5laRu9bkNMgbXVPFoUDCnfA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=Y3KEkMPri6aV08ssSMczmHIfxnip95fIW9+D+y3ydbLeDoK5kF5joaqmFaScVAH+3K Zp8L1ZgTmZSOVB8I5Hdh7W1mHOG9gMcFspvUyXqAtiYjPk9sFTzDm2QTer8M1YexTW6L E1sKdWgiu6WFOLN1SAzyflfb+5L3j9qSImAZQ= Received: by 10.213.102.129 with SMTP id g1mr15048345ebo.41.1262529013114; Sun, 03 Jan 2010 06:30:13 -0800 (PST) Received: from ?192.168.0.80? (xdsl-89-0-188-51.netcologne.de [89.0.188.51]) by mx.google.com with ESMTPS id 15sm11983864ewy.0.2010.01.03.06.30.10 (version=SSLv3 cipher=RC4-MD5); Sun, 03 Jan 2010 06:30:11 -0800 (PST) Message-ID: <4B40A9F4.6000907@gmail.com> Date: Sun, 03 Jan 2010 15:30:12 +0100 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.5) Gecko/20091204 Thunderbird/3.0 MIME-Version: 1.0 To: Kalle Sommer Nielsen CC: internals@lists.php.net References: <4B3F788E.7090200@gmail.com> <2dedb8a1001021236i19571279tf6fc4b57664ca2b@mail.gmail.com> In-Reply-To: <2dedb8a1001021236i19571279tf6fc4b57664ca2b@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] array position isfirst / islast / valid ? From: patchnow@gmail.com (Oskar Eisemuth) Hello On 2.1.2010 21:36, Kalle Sommer Nielsen wrote: > How about just array_pos() if any. The remaining functions can easily > be implemented in userland like: > > function array_pos_isfirst(Array&$array) { > return array_pos($array) == 0; > } > > function array_pos_islast(Array&$array) { > return array_pos($array) == (sizeof($array) - 1); > } > > I don't think it should be needed to add array_pos_isvalid(), since it > *shouldn't* be possible to point to an invalid position. Rather > "isset($array['key'])" should be used to check if a position is valid. > > Well, the internal Zend Hash doesn't know it's position as index, getting to know if the internal pointer is on the last or first entry is much easier as both ends are defined by ht->pListHead and ht->pListTail. Something like: int zend_hash_pointer_is_head(HashTable *ht, HashPosition *pos) { Bucket *p; p = pos ? (*pos) : ht->pInternalPointer; if (p == ht->pListHead) return 1; return 0; } You really don't want to return memory pointers to user code so you would need to traverse the array to get some kind of index number. array_pos_isvalid would be mapped to zend_hash_has_more_elements_ex, that is defined by checking zend_hash_get_current_key_type_ex returning HASH_KEY_NON_EXISTANT. Internally it means really check the pointer for null, so you could call it array_pos_isundefined too. Generally you can use key($array) === null with the same effect. so this would only be for interface completeness and needs to move less data around then a key() call. Best regards Oskar Eisemuth