Set Intersection: Generic Model

The LinkSet returned by the getLinkSet method of a GPO object provides a single method to interesect with another LinkSet:

ILinkSet ls1 = p1.getLinkSet("S1");
ILinkSet ls2 = p2.getLinkSet("S1");

IJoin join = ls1.join(ls2);

This IJoin object can be futher combined with other LinkSets:

ILinkSet ls3 = p3.getLinkSet("S1");

join.and(ls3);

And then an iterator can be retrieved to access the members of the intersected sets:

Iterator members = join.iterator();

For example, suppose we wanted to know the intersection of those "people" who "worked for Sun", "programmed in Java" and "Lived in France":

ILinkSet emps = sun.getLinkSet("employedBy");
ILinkSet javaps = java.getLinkSet("programsIn");
ILinkSet citizens = france.getLinkSet("livesIn");

Iterator members = emps.join(javaps).and(citizens).iterator();

Will do the job nicely.

Simple and Efficient

The implementation in GPO is both straightforward and efficient. The list of LinkSets is sorted in size order. The result is incrementally defined by filtering the members of this set and testing for set membership with the remaining members. Set membership testing is low-cost, so the total computational cost of enumerating the intersection is roughly the same as enumerating the smallest contributing set.