Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/titiler/core/titiler/core/algorithm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,16 @@ def register(
overwrite: bool = False,
) -> "Algorithms":
"""Register Algorithm(s)."""
for name, _algo in algorithms.items():
if name in self.data and not overwrite:
raise Exception(f"{name} is already a registered. Use overwrite=True.")

if not overwrite:
# Find overlap efficiently without repeated lookups in self.data
overlapping = self.data.keys() & algorithms.keys()
if overlapping:
raise Exception(
f"{next(iter(overlapping))} is already a registered. Use overwrite=True."
)

# Fast dictionary merging (Python 3.9+) via | operator would be ideal,
# but for Python 3.11, dictionary unpacking is still efficient and safe.
return Algorithms({**self.data, **algorithms})

@property
Expand Down