kucci / guava-libraries

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

Introduce an InjectiveFunction interface #457

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
An injective function preserves distinctness, and thus can be used to preserve 
the Set and Map interfaces when applying transformations. For example, the 
following functionality becomes feasible:

public static <F, T> Set<T> transform( Set<F> fromSet, InjectiveFunction<? 
super F, T> injectiveFunction )

The InjectiveFunction would simply extend Function - no extra methods are 
required, but the programmer using the interface must understand the 
implications of it.

Original issue reported on code.google.com by antonmar...@gmail.com on 25 Oct 2010 at 10:13

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
This enhancement sort of relates to Issue 177 (the InvertibleFunction or 
Converter interface) - implementing a BijectiveFunction interface would make 
behavioural guarantees about the function.

Original comment by antonmar...@gmail.com on 2 Nov 2010 at 3:09

GoogleCodeExporter commented 9 years ago
After further thought, you can get some impressive performance advantages if 
applying a transformation to a BijectiveFunction - add(), remove(), contains(), 
etc., can all be written to work as efficiently as the transformed Set (in 
terms of computational complexity, assuming apply() and applyInverse() are 
constant time operations). Attached is a trivial implementation of a 
TransformedSet implementation.

Original comment by antonmar...@gmail.com on 2 Nov 2010 at 6:36

Attachments:

GoogleCodeExporter commented 9 years ago
We went down this road quite a while ago, but didn't quite get to the endpoint. 
One thing that held us up was discovering how shockingly many functions people 
want to use are *almost* bijective, and *seem* bijective, but aren't quite -- 
so subtle bugs will be lurking in your program.  This gave us pause, but I 
don't think it kills the whole idea necessarily.

Original comment by kevinb@google.com on 5 Nov 2010 at 5:55

GoogleCodeExporter commented 9 years ago

Original comment by kevinb@google.com on 6 Apr 2011 at 3:27

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:09