Skip to content

Commit

Permalink
add clone_class
Browse files Browse the repository at this point in the history
  • Loading branch information
kk-mats committed Sep 30, 2019
1 parent dd43c41 commit 27a826c
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 4 deletions.
4 changes: 2 additions & 2 deletions asterism.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
<ClCompile Include="layer\color_selector.cpp" />
<ClCompile Include="clone_format\csv.cpp" />
<ClCompile Include="gui\central\current_grid_detail_widget.cpp" />
<ClCompile Include="model\clone_set.cpp" />
<ClCompile Include="model\clone_class.cpp" />
<ClCompile Include="model\detection_result.cpp" />
<ClCompile Include="core\detection_results.cpp" />
<ClCompile Include="gui\tools\external_tools_settings_dialog.cpp" />
Expand Down Expand Up @@ -250,7 +250,7 @@
<ClInclude Include="clone_format\csv.hpp" />
<QtMoc Include="gui\central\current_grid_detail_widget.hpp">
</QtMoc>
<ClInclude Include="model\clone_set.hpp" />
<ClInclude Include="model\clone_class.hpp" />
<ClInclude Include="model\detection_result.hpp" />
<ClInclude Include="core\detection_results.hpp" />
<ClInclude Include="gui\docks.hpp" />
Expand Down
4 changes: 2 additions & 2 deletions asterism.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
<ClCompile Include="core\statistics.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="model\clone_set.cpp">
<ClCompile Include="model\clone_class.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
Expand Down Expand Up @@ -293,7 +293,7 @@
<ClInclude Include="core\statistics.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="model\clone_set.hpp">
<ClInclude Include="model\clone_class.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
Expand Down
72 changes: 72 additions & 0 deletions model/clone_class.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "clone_class.hpp"

namespace asterism
{

void edge(BronKerbosch::Graph<fragment> &G, const std::shared_ptr<clone_pair> &p)
{
auto itr1=std::find_if(G.begin(), G.end(), [&](const auto &v) { return v.id==p->fragment1(); });
if(itr1==G.end())
{
G.push_front(p->fragment1());
itr1=G.begin();
}

auto itr2=std::find_if(G.begin(), G.end(), [&](const auto &v) { return v.id==p->fragment2(); });
if(itr2==G.end())
{
G.push_front(p->fragment2());
itr2=G.begin();
}

itr1->ns.insert(p->fragment2());
itr2->ns.insert(p->fragment1());
}

void aggregator(std::forward_list<BronKerbosch::Graph<fragment>> &all, BronKerbosch::Graph<fragment> R, BronKerbosch::Graph<fragment> P, BronKerbosch::Graph<fragment>)
{
all.push_front(R);
for(const auto &v:R)
{
P.remove(v);
}

if(!P.empty())
{
BronKerbosch::solve<fragment>({{}}, P, {{}}, std::bind(aggregator, std::ref(all), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
}
}

std::vector<clone_class> to_clone_class(const shared_set<clone_pair> &clone_pairs)
{
BronKerbosch::Graph<fragment> G;
for(const auto &p:clone_pairs)
{
edge(G, p);
}

std::forward_list<BronKerbosch::Graph<fragment>> all;
aggregator(all, {{}}, G, {{}});

std::vector<clone_class> all_set;

for(const auto &s:all)
{
if(s.empty())
{
continue;
}

clone_class set;
for(const auto &v:s)
{
set.insert(v.id);
}

all_set.push_back(std::move(set));
}

return all_set;
}

}
25 changes: 25 additions & 0 deletions model/clone_class.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef CLONE_CLASS_HPP
#define CLONE_CLASS_HPP

#include <vector>
#include <functional>

#include <QSet>
#include <BronKerbosch/bron-kerbosch_utils.h>

#include "clone_pair.hpp"

namespace asterism
{

using clone_class=QSet<fragment>;

void edge(BronKerbosch::Graph<fragment> &G, const std::shared_ptr<clone_pair> &p);

void aggregator(std::forward_list<BronKerbosch::Graph<fragment>> &all, BronKerbosch::Graph<fragment> R, BronKerbosch::Graph<fragment> P, BronKerbosch::Graph<fragment>);

std::vector<clone_class> to_clone_class(const shared_set<clone_pair> &clone_pairs);

}

#endif // CLONE_CLASS_HPP

0 comments on commit 27a826c

Please sign in to comment.