From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7832 invoked by alias); 6 Nov 2014 04:43:48 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 19352 Received: (qmail 18868 invoked from network); 6 Nov 2014 04:43:45 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=GLe/yVJP c=1 sm=1 tr=0 a=FT8er97JFeGWzr5TCOCO5w==:117 a=kj9zAlcOel0A:10 a=q2GGsy2AAAAA:8 a=oR5dmqMzAAAA:8 a=-9mUelKeXuEA:10 a=BrDiTsk0AAAA:8 a=OePrh_y-XQbu3TxhL0sA:9 a=-LUbMIF-Imde7378:21 a=AGafIDSO1021o9v6:21 a=CjuIK1q_8ugA:10 From: Bart Schaefer Message-id: <141105204330.ZM2973@torch.brasslantern.com> Date: Wed, 05 Nov 2014 20:43:30 -0800 In-reply-to: <20141105180035.22f6e9b1@pwslap01u.europe.root.pri> Comments: In reply to Peter Stephenson "Re: 'whence' question" (Nov 5, 6:00pm) References: <545A6D66.3080500@eastlink.ca> <1458.1415209763@thecus.kiddle.eu> <20141105180035.22f6e9b1@pwslap01u.europe.root.pri> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Zsh Users Subject: Re: 'whence' question MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Nov 5, 6:00pm, Peter Stephenson wrote: } Subject: Re: 'whence' question } } On Wed, 05 Nov 2014 18:49:23 +0100 } Oliver Kiddle wrote: } > Looking at the source, it seems that whence doesn't support both -a and } > -m together though it doesn't produce an error. } } You're right: I think *that's* a bug. Hmm. This is more complicated than it at first appears. The -a option is O(n*c) where n is $#path and c is $#argv, because it merely has to glue the two arrays together and test whether each of the resulting strings is an executable file path. (I discount the cost of one hash lookup for each hash table.) The -m option currently is O(h*c) where h is the size of all the hash tables, plus (one time only) the cost of filling the command table if it hasn't already been. To do "whence -am" the "right way" would also be approximately O(h*c) because we have to compare every file in every directory in $path to the list of patterns (and h is a fair estimate of that number of files). However, I'm not sure what the "right way" *is*, because: The pattern accepted by the -m option is not a glob, it's a pattern of the string-matching variety. If we were to simply glue each of the arguments onto the end of each $path directory and glob the resulting cross-product, the wrong results could be returned. Furthermore, for e.g. cygwin, the filled hash table has dealt with mapping "foo.exe" onto "foo" with the suffix case-insensitive, so even a string match against the file names across $path could be wrong. Having just written that, it occurs to me that perhaps the "right way" is the equivalent of this? -- whence -a ${(k)commands[(I)pattern]}