harpoon.Analysis.PointerAnalysis
Class RelationImpl

java.lang.Object
  extended by harpoon.Analysis.PointerAnalysis.RelationImpl
All Implemented Interfaces:
Relation, Serializable

public class RelationImpl
extends Object
implements Relation, Serializable

RelationImpl is a heavy-weight implementation of the Relation interface: it is basically a Hashtable from keys to HashSet's of values. It is good for very big relations but consumes lots of memory.

Version:
$Id: RelationImpl.java,v 1.1 2005/08/17 23:34:01 salcianu Exp $
Author:
Alexandru SALCIANU <salcianu@retezat.lcs.mit.edu>
See Also:
Serialized Form

Constructor Summary
RelationImpl()
          Creates an empty Relation.
 
Method Summary
 boolean add(Object key, Object value)
          Adds the pair <key, value> to the relation.
 boolean addAll(Object key, Collection values)
          Adds a relation from key to each element of the set values.
 Object clone()
          Creates a new, independent relation (the operations on the new relation won't affect the old one).
 boolean contains(Object key, Object value)
          Checks the existence of the relation <key,value>.
 boolean containsKey(Object key)
          Checks the existence of the key key in this relation.
 Relation convert(Map map, Relation result)
          Convert this relation through the mapping map.
 boolean equals(Object o)
          Checks the equality of two relations
 void forAllEntries(RelationEntryVisitor visitor)
          Visits all the entries <key,value> of this relation and calls visitor.visit on each of them.
 Relation getEmptyRelation()
           
 Set getValues(Object key)
          Returns the image of key through this relation.
 boolean isEmpty()
          Tests if this relation is empty or not.
 Set keys()
          Returns all the keys appearing in this relation.
 void remove(Object key, Object value)
          Removes the relation between key and value.
 void removeAll(Object key, Collection values)
          Removes the relation between key and any element from values.
 void removeKey(Object key)
          Removes all the relations attached to key.
 void removeKeys(PredicateWrapper predicate)
          Removes all the keys that satisfy predicate.check().
 void removeObjects(PredicateWrapper predicate)
          Removes all the relations involving at least one object that satisfy predicate.check().
 void removeValues(PredicateWrapper predicate)
          Removes all the values that satisfy predicate.check().
 Relation revert(Relation result)
          Revert this relation and store the result into the relation result.
 Relation select(Collection selected_keys)
          Returns the subrelation of this relation that contains only the keys that appear in selected_keys.
 String toString()
          Pretty-print function for debug.
 boolean union(Relation rel)
          Combines this relation with relation rel.
 Set values()
          Returns all the values appearing in this relation.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RelationImpl

public RelationImpl()
Creates an empty Relation.

Method Detail

getEmptyRelation

public Relation getEmptyRelation()

add

public boolean add(Object key,
                   Object value)
Description copied from interface: Relation
Adds the pair <key, value> to the relation. Returns true if the new relation is bigger.

Specified by:
add in interface Relation

addAll

public boolean addAll(Object key,
                      Collection values)
Description copied from interface: Relation
Adds a relation from key to each element of the set values. values should not contain duplicated elements. Returns true if the new relation is bigger.

Specified by:
addAll in interface Relation

remove

public void remove(Object key,
                   Object value)
Description copied from interface: Relation
Removes the relation between key and value.

Specified by:
remove in interface Relation

removeAll

public void removeAll(Object key,
                      Collection values)
Description copied from interface: Relation
Removes the relation between key and any element from values.

Specified by:
removeAll in interface Relation

removeKey

public void removeKey(Object key)
Description copied from interface: Relation
Removes all the relations attached to key.

Specified by:
removeKey in interface Relation

removeKeys

public void removeKeys(PredicateWrapper predicate)
Description copied from interface: Relation
Removes all the keys that satisfy predicate.check().

Specified by:
removeKeys in interface Relation

removeValues

public void removeValues(PredicateWrapper predicate)
Description copied from interface: Relation
Removes all the values that satisfy predicate.check().

Specified by:
removeValues in interface Relation

removeObjects

public void removeObjects(PredicateWrapper predicate)
Description copied from interface: Relation
Removes all the relations involving at least one object that satisfy predicate.check().

Specified by:
removeObjects in interface Relation

contains

public boolean contains(Object key,
                        Object value)
Description copied from interface: Relation
Checks the existence of the relation <key,value>.

Specified by:
contains in interface Relation

containsKey

public boolean containsKey(Object key)
Description copied from interface: Relation
Checks the existence of the key key in this relation.

Specified by:
containsKey in interface Relation

isEmpty

public boolean isEmpty()
Description copied from interface: Relation
Tests if this relation is empty or not.

Specified by:
isEmpty in interface Relation

getValues

public Set getValues(Object key)
Description copied from interface: Relation
Returns the image of key through this relation. The returned collection is guarranted not to contain duplicates. Can return null if no value is attached to key. If the result is non-null, additions and removals on the returned collection take effect on the relation.

Specified by:
getValues in interface Relation

keys

public Set keys()
Description copied from interface: Relation
Returns all the keys appearing in this relation. The result is guaranted not to contain duplicates.

Specified by:
keys in interface Relation

values

public Set values()
Description copied from interface: Relation
Returns all the values appearing in this relation.

Specified by:
values in interface Relation

union

public boolean union(Relation rel)
Description copied from interface: Relation
Combines this relation with relation rel. A null parameter is considered to be an empty relation.

Specified by:
union in interface Relation
Returns:
true iff this relation has changed.

equals

public boolean equals(Object o)
Description copied from interface: Relation
Checks the equality of two relations

Specified by:
equals in interface Relation
Overrides:
equals in class Object

select

public Relation select(Collection selected_keys)
Description copied from interface: Relation
Returns the subrelation of this relation that contains only the keys that appear in selected_keys.

Specified by:
select in interface Relation

forAllEntries

public void forAllEntries(RelationEntryVisitor visitor)
Description copied from interface: Relation
Visits all the entries <key,value> of this relation and calls visitor.visit on each of them.

Specified by:
forAllEntries in interface Relation

clone

public Object clone()
Creates a new, independent relation (the operations on the new relation won't affect the old one).

Specified by:
clone in interface Relation
Overrides:
clone in class Object

toString

public String toString()
Pretty-print function for debug. rel1.equals(rel2) <==> rel1.toString().equals(rel2.toString())

Overrides:
toString in class Object

revert

public Relation revert(Relation result)
Description copied from interface: Relation
Revert this relation and store the result into the relation result. <a,b> appears in the reverse relation iff <b,a> appears in this relation. Returns the new relation (ie, result).

Specified by:
revert in interface Relation

convert

public Relation convert(Map map,
                        Relation result)
Description copied from interface: Relation
Convert this relation through the mapping map. The converted mapping contains all pairs (a,b) such that there exists c,d such that (c,d) appears in this mapping, and map maps c to a and d to b. If an object is not mapped to anything by map, it will be mapped to itself by default. The result is stored in result. Returns the converted mapping (ie, result).

Specified by:
convert in interface Relation