On Sat, Jun 07, 2003 at 01:09:10PM +0900, you CAN teach an old dog ... wrote:
> Does anyone know of a Relation class with methods such as
>   domain
>   range
>   add
>   remove
>   image
>   inverse_image
>   compose
>   inverse_compose
>   inverse
>   override

If the relation is a function (in the mathematical sense) you can
basically use a Hash.

domain => keys
range  => values
add    => []=    w/ some wrapping
remove => delete
image  => []
etc

however inverse_image would be O(n) so probably something with two
hashes is better. 

Is the relation supposed to be
 1. injective
 2. surjective
 3. both (bijective)                ???

If (1) doesn't hold you'll have to wrap the methods of Hash so that each
value is an array, but things get more difficult if (2) is not
guaranteed.

-- 
 _           _                             
| |__   __ _| |_ ___ _ __ ___   __ _ _ __  
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ 
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
	Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Netscape is not a newsreader, and probably never shall be.
	-- Tom Christiansen