jpaul.DataStructs
Class RelFacts

java.lang.Object
  extended by jpaul.DataStructs.RelFacts

public abstract class RelFacts
extends java.lang.Object

RelFacts contains common relation factories. For each kind of relation factory, we have a corresponding static method. Note: some relation factories that used to exist as separate classes are now static inner classes of this class. They are provided mostly to simplify porting old code (programmers only have to change a few import statements).

Version:
$Id: RelFacts.java,v 1.4 2006/01/29 16:05:28 adam_kiezun Exp $
Author:
Alexandru Salcianu - salcianu@alum.mit.edu

Nested Class Summary
static class RelFacts.COWRelationFactory<K,V>
          Deprecated. As of jpaul 2.2, use cow(RelationFactory) instead.
static class RelFacts.MapSetRelationFactory<K,V>
          Deprecated. As of jpaul 2.2, use mapSet() or mapSet(MapFactory,SetFactory) instead.
 
Constructor Summary
RelFacts()
           
 
Method Summary
static
<K,V> RelationFactory<K,V>
cow(RelationFactory<K,V> underRelFact)
          Returns a relation factory that generates "copy-on-write" (COW) relations.
static
<K,V> RelationFactory<K,V>
mapSet()
          Returns a relation factory that generates Relations interface backed by a LinkedHashMap from keys to LinkedHashSets of values.
static
<K,V> RelationFactory<K,V>
mapSet(MapFactory<K,java.util.Set<V>> mapFact, SetFactory<V> setFact)
          Returns a relation factory that generates Relations interface backed by a Map from keys to Sets of values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RelFacts

public RelFacts()
Method Detail

mapSet

public static <K,V> RelationFactory<K,V> mapSet()
Returns a relation factory that generates Relations interface backed by a LinkedHashMap from keys to LinkedHashSets of values. This relation factory is very good for programs that use only a few large relations.


mapSet

public static <K,V> RelationFactory<K,V> mapSet(MapFactory<K,java.util.Set<V>> mapFact,
                                                SetFactory<V> setFact)
Returns a relation factory that generates Relations interface backed by a Map from keys to Sets of values. The map is created by mapFact and the sets by setFact. The two parameters allow the programmer to finely tune the relations from the program.


cow

public static <K,V> RelationFactory<K,V> cow(RelationFactory<K,V> underRelFact)
Returns a relation factory that generates "copy-on-write" (COW) relations. A COW relation shares its representation (also a relation) with other COW relations, until a mutation occurs. At that moment, the COW relation makes a private, exclusive copy of its underlying representation, and mutates that copy.

The internal representation of a COW representation maintains a "sharing" counter to identify cases when the representation is not shared with anyone (and hence, no cloning is necessary before a mutation).

Cloning a COW relation is a constant time operation. COW relations are good when it is hard to determine statically whether a clone of a relation will be mutated: they delay the real cloning until the first mutation (if any).

Parameters:
underRelFact - Relation factory for generating the relations used in the representation of the generated COW relations.


Copyright 2005 Alexandru Salcianu - salcianu@alum.mit.edu