aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/algorithms/impl/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'algorithms/impl/__init__.py')
-rw-r--r--algorithms/impl/__init__.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/algorithms/impl/__init__.py b/algorithms/impl/__init__.py
new file mode 100644
index 0000000..84bd702
--- /dev/null
+++ b/algorithms/impl/__init__.py
@@ -0,0 +1,30 @@
+# Copyright (c) 2016 Egor Tensin <Egor.Tensin@gmail.com>
+# This file is part of the "Sorting algorithms" project.
+# For details, see https://github.com/egor-tensin/sorting-algorithms.
+# Distributed under the MIT License.
+
+from importlib import import_module
+import os.path
+from pkgutil import iter_modules
+
+from .. import algorithm
+
+
+_ALGORITHMS_NAME = '_ALGORITHMS'
+
+
+def refresh_algorithms():
+ all_algorithms = {}
+
+ for _, module_name, is_pkg in iter_modules([os.path.dirname(__file__)]):
+ if is_pkg:
+ continue
+ module = import_module('.' + module_name, __package__)
+ if hasattr(module, _ALGORITHMS_NAME):
+ module_algorithms = getattr(module, _ALGORITHMS_NAME)
+ for descr in module_algorithms:
+ assert isinstance(descr, algorithm.Algorithm)
+ assert descr.codename not in all_algorithms
+ all_algorithms[descr.codename] = descr
+
+ return all_algorithms