Skip to content

Commit

Permalink
Removed redundancy in Graph API (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
czgdp1807 authored Mar 12, 2020
1 parent b257d5a commit b0c3136
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pydatastructs/graphs/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class Graph(object):
implementation: str
The implementation to be used for storing
graph in memory.
graph in memory. It can be figured out
from type of the vertices(if passed at construction).
By default, 'adjacency_list'.
vertices: AdjacencyListGraphNode(s)
For AdjacencyList implementation vertices
Expand Down Expand Up @@ -47,7 +48,8 @@ class Graph(object):
__slots__ = ['_impl']

def __new__(cls, *args, **kwargs):
implementation = kwargs.get('implementation', 'adjacency_list')
default_impl = args[0]._impl if args else 'adjacency_list'
implementation = kwargs.get('implementation', default_impl)
if implementation is 'adjacency_list':
from pydatastructs.graphs.adjacency_list import AdjacencyList
obj = AdjacencyList(*args)
Expand Down
2 changes: 2 additions & 0 deletions pydatastructs/utils/misc_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class AdjacencyListGraphNode(GraphNode):
def __new__(cls, name, data=None, adjacency_list=None):
obj = GraphNode.__new__(cls)
obj.name, obj.data = str(name), data
obj._impl = 'adjacency_list'
if adjacency_list is not None:
for node in adjacency_list:
obj.__setattr__(node.name, node)
Expand Down Expand Up @@ -201,6 +202,7 @@ def __new__(cls, name, data=None):
obj = GraphNode.__new__(cls)
obj.name, obj.data, obj.is_connected = \
int(name), data, None
obj._impl = 'adjacency_matrix'
return obj

class GraphEdge(object):
Expand Down

0 comments on commit b0c3136

Please sign in to comment.