bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Q: what is a fast way to see if an 'item' is present in an array?


From: Greg Wooledge
Subject: Re: Q: what is a fast way to see if an 'item' is present in an array?
Date: Wed, 17 Feb 2016 08:27:59 -0500
User-agent: Mutt/1.4.2.3i

On Tue, Feb 16, 2016 at 07:26:06PM -0800, Linda Walsh wrote:
> In my case it's only 2, but other interfaces... still not that long
> *usually*,
> > (cd $PWD/holders; echo *)
> dm-0 dm-1 dm-12 dm-2 dm-3 dm-4 dm-5 dm-6 dm-7 dm-8 dm-9
> ----
> But I tend to think about worst case behaviors and at least
> try to ask around if anyone has anything better... but in this case,
> the impact is minimal.

Well, you have choices to make.  You can do a sequential search through
the list each time, or you can build an associative array from the
list right after reading it (and any other time you modify the list).

If the typical list is about 2 elements, then the sequential search is
fine.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]