Data Structures and Algorithms for Relations