class SimplexBirth: # An object that contains a set of landmarks that define a simplex, and a birth time measured in integer units. IMPORTANT: two SimplexBirths are considered equal iff they have the same landmark set, regardless of birth time. include_birth_time = False def __init__(self, landmark_list, birth_time, keep_sorted_list): if (keep_sorted_list): self.sll = sorted(landmark_list) else: self.sll = None self.landmark_set = ImmutableSet(landmark_list) self.birth_time = birth_time def __eq__(self, other): # For hashing if SimplexBirth.include_birth_time: return self.birth_time == other.birth_time and self.landmark_set.__eq__( other.landmark_set) else: return self.landmark_set.__eq__(other.landmark_set) def __cmp__(self, other): # For sorting if self.birth_time < other.birth_time: return -1 elif self.birth_time > other.birth_time: return 1 else: if len(self.landmark_set) < len(other.landmark_set): return -1 elif len(self.landmark_set) > len(other.landmark_set): return 1 else: if self.sll is None: return 0 for i in xrange(len(self.sll)): if self.sll[i] < other.sll[i]: return -1 elif self.sll[i] > other.sll[i]: return 1 return 0 def __hash__(self): return self.landmark_set.__hash__()
def __hash__(self): return frozenset.__hash__(self)