Set theory optimization

This commit adds optimizations for the set theory operation using hash
set