Implement Hash for TreeSet

cc #15294