yogendra-aurospaces / google-collections

Automatically exported from code.google.com/p/google-collections
Apache License 2.0
0 stars 0 forks source link

Find/Filter for Lists that returns indices #290

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Johan brought this up on the mailing list [1]: 

"I'm missing find/filter Iterable methods that return indices rather
than the objects themselves. For lists, this is more natural.
Implementing an index-based filter on top of the existing filter is
very clumsy compared to doing it the other way around. (again, only
for lists, that is)"

Some options arose out of the discussion:

   * Mirror the string index methods: with `int Lists.indexOf(List, Predicate)` and 
`int Lists.lastIndexOf(List, Predicate)` 
   * Compute Iterable/Iterators instead in ints (computed lazily, of course):
      * Iterator<Integer> Lists.leftIndexes(List, Predicate)
      * Iterator<Integer> Lists.rightIndexes(List, Predicate)

I'm partial to the later option, since the iterators are more powerful than the 
singular indexes.  In particular, using iterators clearly gives access to the 
entire 
list of identified indices, whereas indexOf/lastIndexOf methods either need 
overloads with starting offsets to search from, or the user must pass in a view 
of a 
subset of the input list.

The first use case that comes to mind comes up when working with legacy code 
that 
uses parallel lists in place of Tuple types or maps: list indices are the only 
link 
between different structures, so knowing where a given object (or objects) 
is/are is 
important.

I've also needed this when working with word vectors, but I don't have a 
specific 
use case at hand.

I could see this coming in handy when manipulating priority queues, to identify 
the 
location in a queue of a subset of the tasks at hand. ("How are the FooBar 
tasks 
distributed across the queue?")

[1]: http://groups.google.com/group/google-collections-
users/browse_thread/thread/2f0120513488977e?hl=en

Original issue reported on code.google.com by cresw...@gmail.com on 5 Nov 2009 at 10:39

GoogleCodeExporter commented 9 years ago
We're tentatively moving ahead with Itera*s.indexOf(Itera*, Predicate).  And
lastIndexOf().

Original comment by kevin...@gmail.com on 6 Nov 2009 at 10:01

GoogleCodeExporter commented 9 years ago
This issue has been moved to the Guava project (keeping the same id number). 
Simply replace 'google-collections' with 'guava-libraries' in your address 
bar and it should take you there.

Original comment by kevinb@google.com on 5 Jan 2010 at 11:09