Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85628 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 68444 invoked from network); 1 Apr 2015 07:54:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Apr 2015 07:54:04 -0000 Authentication-Results: pb1.pair.com smtp.mail=smalyshev@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=smalyshev@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.170 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 209.85.192.170 mail-pd0-f170.google.com Received: from [209.85.192.170] ([209.85.192.170:33816] helo=mail-pd0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 31/31-56894-A14AB155 for ; Wed, 01 Apr 2015 02:54:04 -0500 Received: by pdbni2 with SMTP id ni2so47105867pdb.1 for ; Wed, 01 Apr 2015 00:54:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=ybTwedfNSaCNZw0mQHJMEVtZdwmmiF4vc+4kXjE5X6A=; b=ll3H61wql8BJj14kmy5k0M88+Vihu2H0J485hSGVtfn1ascpmWuvW1CCxPJlcNYK8Z UgGhivcDbSUcs8z48JVY/fltikW0fDu8VZaZnb4Qve2gIyG9iDteZzeyJXRzetBa/Wgh qyVPBy6cmWA43lsp4HlbKTkKX3mzdmqz07G/bROI+xYOGShjps0viANFoiCUMkbogkma ZcaUtBwlZbG8wK1yl2Q1T/Z3s4uBpXJ3WY4NQu+uFgSYNnvRdoWRqw0nZvIkSvtIt/Sh rsnhL+iVRIULSK1QmbIT8fIg3S6BBQ/W171uDW1kLQf4B1JwiV3GapXUpNkbe1eCdcYr OnPw== X-Received: by 10.70.133.66 with SMTP id pa2mr3419037pdb.164.1427874839954; Wed, 01 Apr 2015 00:53:59 -0700 (PDT) Received: from Stas-Air.local (108-66-6-48.lightspeed.sntcca.sbcglobal.net. [108.66.6.48]) by mx.google.com with ESMTPSA id k9sm1170194pbq.46.2015.04.01.00.53.58 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Apr 2015 00:53:59 -0700 (PDT) Message-ID: <551BA415.7050809@gmail.com> Date: Wed, 01 Apr 2015 00:53:57 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Danylo Medinsky , internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Potential binary search optimization or feature From: smalyshev@gmail.com (Stanislav Malyshev) Hi! > to utilize a binary search algorithm. Since the requirement for a binary > search is that the array being searched is sorted, I thought is would be a > good idea to have a Boolean parameter in the binary search function to > specify if the input array should be sorted or not. something among the Sorting array takes at least O(n*log n) (well, with comparison sort, but that's what you'd have to use I assume), while linear search can be done in O(n). So no profit here. If you *know* the array is sorted, binary search function could be useful, but I'm not sure how wide the use case for it would be. > lines of "function binary_search(string target, array arrayToSearch, bool > sort)". Doing this, the function can preform a sort if required to, thus > not needing to sort a array that is already sorted. Array function's name would have to start with array_ prefix. -- Stas Malyshev smalyshev@gmail.com