comparator for hierarchy