$25 GRAYBYTE WORDPRESS FILE MANAGER $48

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/usr/lib64/python2.7/site-packages/sqlalchemy/util/

HOME
Current File : /usr/lib64/python2.7/site-packages/sqlalchemy/util//topological.py
# util/topological.py
# Copyright (C) 2005-2024 the SQLAlchemy authors and contributors
# <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
# the MIT License: https://www.opensource.org/licenses/mit-license.php

"""Topological sorting algorithms."""

from .. import util
from ..exc import CircularDependencyError

__all__ = ["sort", "sort_as_subsets", "find_cycles"]


def sort_as_subsets(tuples, allitems):

    edges = util.defaultdict(set)
    for parent, child in tuples:
        edges[child].add(parent)

    todo = list(allitems)
    todo_set = set(allitems)

    while todo_set:
        output = []
        for node in todo:
            if todo_set.isdisjoint(edges[node]):
                output.append(node)

        if not output:
            raise CircularDependencyError(
                "Circular dependency detected.",
                find_cycles(tuples, allitems),
                _gen_edges(edges),
            )

        todo_set.difference_update(output)
        todo = [t for t in todo if t in todo_set]
        yield output


def sort(tuples, allitems, deterministic_order=True):
    """sort the given list of items by dependency.

    'tuples' is a list of tuples representing a partial ordering.

    deterministic_order is no longer used, the order is now always
    deterministic given the order of "allitems".    the flag is there
    for backwards compatibility with Alembic.

    """

    for set_ in sort_as_subsets(tuples, allitems):
        for s in set_:
            yield s


def find_cycles(tuples, allitems):
    # adapted from:
    # https://neopythonic.blogspot.com/2009/01/detecting-cycles-in-directed-graph.html

    edges = util.defaultdict(set)
    for parent, child in tuples:
        edges[parent].add(child)
    nodes_to_test = set(edges)

    output = set()

    # we'd like to find all nodes that are
    # involved in cycles, so we do the full
    # pass through the whole thing for each
    # node in the original list.

    # we can go just through parent edge nodes.
    # if a node is only a child and never a parent,
    # by definition it can't be part of a cycle.  same
    # if it's not in the edges at all.
    for node in nodes_to_test:
        stack = [node]
        todo = nodes_to_test.difference(stack)
        while stack:
            top = stack[-1]
            for node in edges[top]:
                if node in stack:
                    cyc = stack[stack.index(node) :]
                    todo.difference_update(cyc)
                    output.update(cyc)

                if node in todo:
                    stack.append(node)
                    todo.remove(node)
                    break
            else:
                node = stack.pop()
    return output


def _gen_edges(edges):
    return set([(right, left) for left in edges for right in edges[left]])

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
23 Sep 2024 10.41 AM
root / root
0755
__init__.py
6.302 KB
5 Sep 2024 10.50 PM
root / root
0644
__init__.pyc
7.756 KB
23 Sep 2024 10.41 AM
root / root
0644
_collections.py
28.456 KB
5 Sep 2024 10.50 PM
root / root
0644
_collections.pyc
47.026 KB
23 Sep 2024 10.41 AM
root / root
0644
_compat_py3k.py
2.144 KB
5 Sep 2024 10.50 PM
root / root
0644
_concurrency_py3k.py
6.395 KB
5 Sep 2024 10.50 PM
root / root
0644
_preloaded.py
2.34 KB
5 Sep 2024 10.50 PM
root / root
0644
_preloaded.pyc
2.892 KB
23 Sep 2024 10.41 AM
root / root
0644
compat.py
17.954 KB
5 Sep 2024 10.50 PM
root / root
0644
compat.pyc
21.016 KB
23 Sep 2024 10.41 AM
root / root
0644
concurrency.py
2.225 KB
5 Sep 2024 10.50 PM
root / root
0644
concurrency.pyc
2.472 KB
23 Sep 2024 10.41 AM
root / root
0644
deprecations.py
13.354 KB
5 Sep 2024 10.50 PM
root / root
0644
deprecations.pyc
12.528 KB
23 Sep 2024 10.41 AM
root / root
0644
langhelpers.py
54.969 KB
5 Sep 2024 10.50 PM
root / root
0644
langhelpers.pyc
60.869 KB
23 Sep 2024 10.41 AM
root / root
0644
queue.py
9.075 KB
5 Sep 2024 10.50 PM
root / root
0644
queue.pyc
10.05 KB
23 Sep 2024 10.41 AM
root / root
0644
tool_support.py
5.991 KB
5 Sep 2024 10.50 PM
root / root
0644
topological.py
2.792 KB
5 Sep 2024 10.50 PM
root / root
0644
topological.pyc
2.474 KB
23 Sep 2024 10.41 AM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF