in 1_synthetic-qa-generation/reasoningplaning/evolve.py [0:0]
def addOrUpdate(self, node: Nde, branch: str, priority: float):
"""
Add a new branch or update the priority of an existing branch.
Parameters:
- node (Nde): The node associated with the branch.
- branch (str): The branch string.
- priority (float): The new priority score.
"""
node_id = id(node) # Unique identifier for the node object
branch_key = (node_id, branch)
# Check if the branch already exists in the pool
if branch_key in self.latest_id_per_branch:
# Previous unique_id exists; it is now outdated
old_unique_id = self.latest_id_per_branch[branch_key]
# Mark the old entry as invalid by removing it from entry_finder
if old_unique_id in self.entry_finder:
del self.entry_finder[old_unique_id]
del self.id_to_branch[old_unique_id]
# Assign a new unique_id for the updated branch
unique_id = next(self.counter)
self.latest_id_per_branch[branch_key] = unique_id
# Add the new entry to the heap and mappings
heapq.heappush(self.heap, (-priority, unique_id)) # Max-heap using negative priority
self.entry_finder[unique_id] = (-priority, unique_id)
self.id_to_branch[unique_id] = (node, branch)