Skip to main content

Tools that enable operations on graphs where graphs are represented by an adjacency Mapping.

Project description

meshed

Tools that enable operations on graphs where graphs are represented by an adjacency Mapping.

Again.

Graphs: You know them. Networks. Nodes and edges, and the ecosystem descriptive or transformative functions surrounding these. Few languages have builtin support for the graph data structure, but all have their libraries to compensate.

The one you're looking at focuses on the representation of a graph as Mapping encoding its adjacency list. That is, a dictionary-like interface that specifies the graph by specifying for each node what nodes it's adjacent to:

assert graph[source_node] == iterator_of_nodes_that_source_node_has_edges_to

We emphasize that there is no specific graph instance that you need to squeeze your graph into to be able to use the functions of meshed. Suffices that your graph's structure is expressed by that dict-like interface -- which grown-ups call Mapping (see the collections.abc or typing standard libs for more information).

You'll find a lot of Mappings around pythons. And if the object you want to work with doesn't have that interface, you can easily create one using one of the many tools of py2store meant exactly for that purpose.

Examples

>>> from meshed.itools import edges, nodes, isolated_nodes
>>> graph = dict(a='c', b='ce', c='abde', d='c', e=['c', 'b'], f={})
>>> sorted(edges(graph))
[('a', 'c'), ('b', 'c'), ('b', 'e'), ('c', 'a'), ('c', 'b'), ('c', 'd'), ('c', 'e'), ('d', 'c'), ('e', 'b'), ('e', 'c')]
>>> sorted(nodes(graph))
['a', 'b', 'c', 'd', 'e', 'f']
>>> set(isolated_nodes(graph))
{'f'}
>>>
>>> from meshed.makers import edge_reversed_graph
>>> g = dict(a='c', b='cd', c='abd', e='')
>>> assert edge_reversed_graph(g) == {'c': ['a', 'b'], 'd': ['b', 'c'], 'a': ['c'], 'b': ['c'], 'e': []}
>>> reverse_g_with_sets = edge_reversed_graph(g, set, set.add)
>>> assert reverse_g_with_sets == {'c': {'a', 'b'}, 'd': {'b', 'c'}, 'a': {'c'}, 'b': {'c'}, 'e': set([])}

Project details


Release history Release notifications | RSS feed

This version

0.1.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

meshed-0.1.1.tar.gz (40.3 kB view details)

Uploaded Source

File details

Details for the file meshed-0.1.1.tar.gz.

File metadata

  • Download URL: meshed-0.1.1.tar.gz
  • Upload date:
  • Size: 40.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.11

File hashes

Hashes for meshed-0.1.1.tar.gz
Algorithm Hash digest
SHA256 36bafe5cec4dfcf1486f044991a6122698432febb6fd423f3e33a51e27468e9c
MD5 f5ba599e8c8c32ef4fee34347b1ea17b
BLAKE2b-256 56204bff942891794db5a22e76f07680178772b9188375ca681570f8e8294929

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page