|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jpaul.DataStructs.Relation<K,V> jpaul.DataStructs.MapSetRelation<K,V>
public class MapSetRelation<K,V>
MapSetRelation
is an implementation of the
Relation
interface based on a Map
from
keys to Set
s of values.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class jpaul.DataStructs.Relation |
---|
Relation.EntryVisitor<Key,Value> |
Constructor Summary | |
---|---|
MapSetRelation()
Constructs a Relation represented using a
LinkedHashMap from keys to
LinkedHashSet s of values. |
|
MapSetRelation(MapFactory<K,java.util.Set<V>> mapFact,
SetFactory<V> setFact)
Constructs a Relation represented by a
Map from keys to Set s of values. |
Method Summary | |
---|---|
protected java.util.Set<V> |
_getValues(K key)
Method used by the internal implementation of the Relation or its subclasses. |
boolean |
add(K key,
V value)
Adds the pair <key, value> to the relation. |
boolean |
addAll(K key,
java.util.Collection<V> values)
Puts key in relation to each element of the
collection values . |
boolean |
addAll2(K key,
java.util.Collection<? extends V> values)
Similar to Relation.addAll(K, java.util.Collection except that the type of the
collection values allows more flexibility. |
void |
clear()
Removes all mappings stored in this relation. |
MapSetRelation<K,V> |
clone()
Creates a new, independent relation (independent = the operations on the new relation won't affect the old one). |
boolean |
containsKey(K key)
Checks the existence of the key key in this relation. |
boolean |
equals(java.lang.Object o)
Checks the equality of two relations |
int |
hashCode()
Complexity: linear in the number of (key,value) pairs from the relation. |
boolean |
isEmpty()
Tests if this relation is empty or not. |
java.util.Set<K> |
keys()
Returns an IMMUTABLE view of all the keys appearing in this relation. |
boolean |
remove(K key,
V value)
Removes the relation between key and
value . |
boolean |
removeAll(K key,
java.util.Collection<V> values)
Removes the relation between key and
any element from values . |
boolean |
removeKey(K key)
Removes all the relations attached to key . |
boolean |
removeKeys(Predicate<K> predicate)
Removes all the keys that satisfy predicate.check() . |
boolean |
removeValues(Predicate<V> predicate)
Removes all the values that satisfy predicate.check() . |
boolean |
union(Relation<K,V> rel)
Combines this relation with relation
rel . |
java.lang.Iterable<V> |
values()
Returns an IMMUTABLE view of all the values appearing in this relation. |
Methods inherited from class jpaul.DataStructs.Relation |
---|
contains, containsAll, forAllEntries, getValues, isFunction, revert, revert, size, synchronizedRelation, toString, unmodifiableRelation |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public MapSetRelation()
Relation
represented using a
LinkedHashMap
from keys to
LinkedHashSet
s of values. Consumes a lot of
memory but fast for large relation.
public MapSetRelation(MapFactory<K,java.util.Set<V>> mapFact, SetFactory<V> setFact)
Relation
represented by a
Map
from keys to Set
s of values.
The map is created by mapFact
and the sets by
setFact
.
MapFacts
,
SetFacts
Method Detail |
---|
public boolean add(K key, V value)
Relation
<key, value>
to the relation.
Returns true
if the new relation is bigger.
add
in class Relation<K,V>
public boolean addAll(K key, java.util.Collection<V> values)
Relation
key
in relation to each element of the
collection values
. Returns true
if
the relation becomes bigger.
addAll
in class Relation<K,V>
public boolean addAll2(K key, java.util.Collection<? extends V> values)
Relation
Relation.addAll(K, java.util.Collection)
except that the type of the
collection values
allows more flexibility. Puts
key
in relation to each element from the
collection values
. Returns true
if
the relation becomes bigger.
Only for the very curious users: A
legitimate question is "why two almost identical versions
of addAll
?" The answer has to do with speed
optimizations and historic reasons. In program analysis, it
is frequent to propagate large relations, with only the
mappings for a few keys being changed. Consequently,
jpaul
offers special Copy-On-Write
(COW) sets and other datastructures (see COWSetFactory
). For the rest of this
discussion, let's assume that key
is not in
relation with any value yet. The historically first version,
Relation.addAll(K, java.util.Collection
, allows the possible underlying set factory to
"clone" the COW set values
(if
values
is indeed a COW set). "Cloning" a COW
datastructure is very fast, and consumes almost no memory at
all, leading to enormous speedups (e.g., in Alex Salcianu's
pointer analysis prototype). Unfortunately, cloning in the
presence of wildcards would violate type safety: cloning a
Set<? extends V>
does not produce a
Set<V>
. Instead, the usual implementations
of Relation.addAll2(K, java.util.Collection extends V>)
work by creating a brand-new
Set<V>
and adding the new values to it,
one-by-one. Retrospectively, the design could have been
better, but we didn't want to do anything that would break the
performances of the applications that already use
jpaul
.
addAll2
in class Relation<K,V>
public void clear()
Relation
this
relation.
clear
in class Relation<K,V>
public boolean remove(K key, V value)
Relation
key
and
value
.
remove
in class Relation<K,V>
true
iff the relation changedpublic boolean removeAll(K key, java.util.Collection<V> values)
Relation
key
and
any element from values
.
removeAll
in class Relation<K,V>
true
iff the relation changedpublic boolean removeKey(K key)
Relation
key
.
removeKey
in class Relation<K,V>
true
iff the relation changedpublic boolean removeKeys(Predicate<K> predicate)
Relation
predicate.check()
.
removeKeys
in class Relation<K,V>
true
iff the relation changedpublic boolean removeValues(Predicate<V> predicate)
Relation
predicate.check()
.
removeValues
in class Relation<K,V>
true
iff the relation changedpublic boolean containsKey(K key)
Relation
key
key in this relation.
containsKey
in class Relation<K,V>
public boolean isEmpty()
Relation
isEmpty
in class Relation<K,V>
protected final java.util.Set<V> _getValues(K key)
Relation
Relation
or its subclasses. Similar to the
user-level Relation.getValues(K)
but the returned set IS MUTABLE.
Mutating this set affects the set of values that are
associated with a given key; therefore, this method cannot be
used by Relation
clients directly.
_getValues
in class Relation<K,V>
public java.util.Set<K> keys()
Relation
this
relation. If you want to delete a key, then
use Relation.removeKey(K)
.
keys
in class Relation<K,V>
public java.lang.Iterable<V> values()
Relation
this
relation. The view may contain the same
value twice, if it is associated with two distinct keys.
values
in class Relation<K,V>
public boolean union(Relation<K,V> rel)
Relation
this
relation with relation
rel
. A null
parameter is considered
to be an empty relation.
union
in class Relation<K,V>
true
iff this
relation has
changed.public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object o)
Relation
equals
in class Relation<K,V>
public MapSetRelation<K,V> clone()
clone
in class Relation<K,V>
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |