Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for graph.AdjacencyMatrix in C++ backend #513

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

nubol23
Copy link
Contributor

@nubol23 nubol23 commented Aug 12, 2022

Add graph cpp backend.

Currently working on AdjacencyMatrix implementation.

@czgdp1807
Copy link
Member

So, while adding support any data structure in C++ backend we need to make sure that there is no difference between the interface supported by C++ backend and Python backend. Internally both can follow different implementations.

Since we have already implemented Graph in Python backend so we need to make sure that interface of every method defined in https://github.com/codezonediitj/pydatastructs/blob/master/pydatastructs/graphs/graph.py works with C++ backend as well. The pattern I notice is here that we pass nodes as input, call str upon these nodes and use the output to index the graph data structure.

So I would say let's follow a similar pattern for now in C++ backend as well, with a small tweak i.e., I would use name attribute instead of calling str on the input nodes which will return the name for these nodes. Then use these names to index the data structure.

Now, AdjacencyMatrixCpp can contain the following containers to store information related to nodes and edges,

  1. std::map<std::pair<std::string, std::string>, bool> - Similarly to
    obj.matrix = {}
    for vertex in vertices:
    obj.matrix[vertex.name] = {}
    .
  2. std::map<std::pair<std::string, std::string>, GraphEdgeCpp> - Similar to

And in addition to AdjancencyMatrixCpp we will need following data structures in C++ backend,

  1. GraphNodeCpp - Similar to
    class GraphNode(Node):
    """
    Abastract class for graph nodes/vertices.
    """
    def __str__(self):
    return str((self.name, self.data))
    .
  2. AdjancencyMatrixGraphNodeCpp - Similar to
    class AdjacencyMatrixGraphNode(GraphNode):
  3. GraphEdgeCpp - Similar to
    class GraphEdge(object):

@codecov
Copy link

codecov bot commented Aug 17, 2022

Codecov Report

Merging #513 (eed61cb) into master (8f419fd) will increase coverage by 0.009%.
The diff coverage is 100.000%.

@@              Coverage Diff              @@
##            master      #513       +/-   ##
=============================================
+ Coverage   98.528%   98.538%   +0.009%     
=============================================
  Files           32        34        +2     
  Lines         4010      4037       +27     
=============================================
+ Hits          3951      3978       +27     
  Misses          59        59               
Impacted Files Coverage Δ
pydatastructs/graphs/__init__.py 100.000% <100.000%> (ø)
pydatastructs/graphs/_extensions.py 100.000% <100.000%> (ø)
pydatastructs/utils/__init__.py 100.000% <100.000%> (ø)
pydatastructs/utils/_extensions.py 100.000% <100.000%> (ø)
pydatastructs/utils/misc_util.py 99.148% <100.000%> (+0.018%) ⬆️

Impacted file tree graph

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants