Skip to content

Commit

Permalink
Some code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
neatdecisions committed Apr 11, 2020
1 parent 3b06233 commit 3c1a25f
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 51 deletions.
8 changes: 4 additions & 4 deletions src/detwinner-lib/logic/MurmurHash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ fmix ( uint32_t h )
bool
MurmurHash::GetHash(const std::string & fileName, std::string & hash)
{
std::ifstream f(fileName.c_str(), std::ifstream::in | std::ifstream::binary);

if (!f) return false;

constexpr uint32_t seed = 5;
constexpr std::streamsize FILE_READ_BUFFER_SIZE = 4096;

uint8_t key[FILE_READ_BUFFER_SIZE];

uint32_t out[4];

std::ifstream f(fileName.c_str(), std::ifstream::in | std::ifstream::binary);

if (!f) return false;

size_t len = 0, l = 0;

uint32_t h1 = seed;
Expand Down
4 changes: 2 additions & 2 deletions src/detwinner-lib/logic/images/ImageFeatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Name : ImageFeatures.cpp
Author : NeatDecisions
Version :
Copyright : Copyright © 2018–2019 Neat Decisions. All rights reserved.
Copyright : Copyright © 2018–2020 Neat Decisions. All rights reserved.
Description : Detwinner
===============================================================================
*/
Expand Down Expand Up @@ -38,7 +38,7 @@ ImageFeatures::compare(const ImageFeatures & f, bool processRotations) const

std::array<float, 4> values{};
float minVal = 2.0f;
float isMinValueForSameRotation = true;
bool isMinValueForSameRotation = true;
const size_t nRot = processRotations ? kSectionCount : 1;
for (std::size_t i = 0; i < nRot; ++i)
{
Expand Down
25 changes: 9 additions & 16 deletions src/detwinner-lib/logic/images/SimilarImageFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Name : SimilarImageFinder.cpp
Author : NeatDecisions
Version :
Copyright : Copyright © 2018–2019 Neat Decisions. All rights reserved.
Copyright : Copyright © 2018–2020 Neat Decisions. All rights reserved.
Description : Detwinner
===============================================================================
*/
Expand Down Expand Up @@ -64,18 +64,17 @@ SimilarImageFinder::updateNeighboursPartial(
{
cluster.neighborId = mergedClusterId1;
cluster.neighborDistance = cache.get(cluster.id, mergedClusterId1);
for (auto && subcluster: clusters)
for (const auto & subcluster: clusters)
{
assert(subcluster.id != mergedClusterId2);
if ( (subcluster.id == mergedClusterId1) || (subcluster.id == cluster.id) ) continue;
Distance_t dist = cache.get(cluster.id, subcluster.id);
const Distance_t dist = cache.get(cluster.id, subcluster.id);
if (dist < cluster.neighborDistance)
{
cluster.neighborDistance = dist;
cluster.neighborId = subcluster.id;
}
}
if ( (cluster.neighborDistance > maxDistance) )
if (cluster.neighborDistance > maxDistance)
{
outliers.insert(i);
}
Expand Down Expand Up @@ -105,11 +104,11 @@ SimilarImageFinder::updateNeighbours(
std::ref(cache), maxDistance, mergedClusterId1, mergedClusterId2, 0, clusters.size(), std::ref(clusters) ) );
} else
{
for (auto && aIndexPair: parallelIndexes)
for (const auto & indexPair: parallelIndexes)
{
futures.push_back( std::async(std::launch::async,
&SimilarImageFinder::updateNeighboursPartial, this,
std::ref(cache), maxDistance, mergedClusterId1, mergedClusterId2, aIndexPair.first, aIndexPair.second, std::ref(clusters) ) );
std::ref(cache), maxDistance, mergedClusterId1, mergedClusterId2, indexPair.first, indexPair.second, std::ref(clusters) ) );
}
}

Expand Down Expand Up @@ -173,7 +172,6 @@ SimilarImageFinder::addClusterToResult(
std::size_t
SimilarImageFinder::findMinimalDistanceIndex(const std::vector<Cluster_t> & clusters) const
{
assert(!clusters.empty());
auto it = std::min_element(clusters.begin(), clusters.end(),
[](const Cluster_t & c1, const Cluster_t & c2) { return c1.neighborDistance < c2.neighborDistance; });
return std::distance(clusters.begin(), it);
Expand Down Expand Up @@ -260,17 +258,12 @@ SimilarImageFinder::clusterize(
}
}

if (!isOutlier)
if (isOutlier)
{
Cluster_t cluster;
cluster.id = i;
cluster.items.insert(i);
cluster.neighborDistance = minDistance;
cluster.neighborId = neighborId;
clusters.push_back(std::move(cluster));
if (callback) callback->imgOrganizingProgress(++progress, count);
} else
{
if (callback) callback->imgOrganizingProgress(++progress, count);
clusters.emplace_back(i, neighborId, minDistance, i);
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/detwinner-lib/logic/images/SimilarImageFinder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Name : SimilarImageFinder.hpp
Author : NeatDecisions
Version :
Copyright : Copyright © 2018–2019 Neat Decisions. All rights reserved.
Copyright : Copyright © 2018–2020 Neat Decisions. All rights reserved.
Description : Detwinner
===============================================================================
*/
Expand Down Expand Up @@ -47,6 +47,9 @@ class SimilarImageFinder

struct Cluster_t
{
Cluster_t() = default;
Cluster_t(std::size_t id, std::size_t neighborId, Distance_t neighborDistance, std::size_t firstItemId) :
id(id), neighborId(neighborId), neighborDistance(neighborDistance), items({firstItemId}) {}
std::size_t id = 0;
std::size_t neighborId = 0;
Distance_t neighborDistance = 0;
Expand Down Expand Up @@ -94,8 +97,8 @@ class SimilarImageFinder
std::set<std::size_t> updateNeighboursPartial(
const SimilarityCache & cache,
const Distance_t maxDistance,
const std::size_t iMergedClusterId1,
const std::size_t iMergedClusterId2,
const std::size_t mergedClusterId1,
const std::size_t mergedClusterId2,
const std::size_t startIndex,
const std::size_t endIndex,
std::vector<Cluster_t> & clusters) const;
Expand Down
6 changes: 2 additions & 4 deletions src/detwinner/settings/SearchSettingsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Name : SearchSettingsManager.cpp
Author : NeatDecisions
Version :
Copyright : Copyright © 2018–2019 Neat Decisions. All rights reserved.
Copyright : Copyright © 2018–2020 Neat Decisions. All rights reserved.
Description : Detwinner
==============================================================================
*/
Expand Down Expand Up @@ -158,9 +158,7 @@ SearchSettingsManager::createDefaultSimilarImagesSettings() const
SearchSettings
SearchSettingsManager::createDefaultExactDuplicatesSettings() const
{
SearchSettings result;
result.searchMode = SearchSettings::SearchMode_t::kExactDuplicates;
return result;
return SearchSettings();
}


Expand Down
24 changes: 5 additions & 19 deletions src/detwinner/ui/DuplicatesTreeView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Name : DuplicatesTreeView.cpp
Author : NeatDecisions
Version :
Copyright : Copyright © 2018–2019 Neat Decisions. All rights reserved.
Copyright : Copyright © 2018–2020 Neat Decisions. All rights reserved.
Description : Detwinner
===============================================================================
*/
Expand Down Expand Up @@ -325,14 +325,7 @@ DuplicatesTreeView::on_render_filename(Gtk::CellRenderer * cellRenderer, const G
{
if (cellRenderer == nullptr || !iter) return;
CheckState_t checkState = getCheck(iter);
static const Glib::ustring kProperty_StrikeThrough("strikethrough");
if (checkState == CheckState_t::Checked)
{
cellRenderer->set_property(kProperty_StrikeThrough, true);
} else
{
cellRenderer->set_property(kProperty_StrikeThrough, false);
}
cellRenderer->set_property("strikethrough", checkState == CheckState_t::Checked);
const auto & kids = iter->children();
if (kids && !kids.empty())
{
Expand Down Expand Up @@ -1300,14 +1293,7 @@ DuplicatesTreeView::TreeSelect_Bulk_t::processNext()
states.insert(newCheck);
m_tree.setCheck(file, newCheck, true, true);
}

if (states.size() == 1)
{
m_tree.setCheck(m_iter, *states.begin(), true, true);
} else
{
m_tree.setCheck(m_iter, CheckState_t::Mixed, true, true);
}
m_tree.setCheck(m_iter, (states.size() == 1) ? *states.begin() : CheckState_t::Mixed, true, true);

++m_currentItem;
return static_cast<bool>(++m_iter);
Expand Down Expand Up @@ -1366,8 +1352,8 @@ DuplicatesTreeView::TreePopulateAction::processNext()
{
auto t = *m_tree.m_store->append(treeRow->children());

Glib::RefPtr<Gio::File> file = Gio::File::create_for_path(duplicateFile.name);
Glib::RefPtr<Gio::FileInfo> fileInfo = file->query_info("time::modified");
const Glib::RefPtr<Gio::File> file = Gio::File::create_for_path(duplicateFile.name);
const Glib::RefPtr<Gio::FileInfo> fileInfo = file->query_info("time::modified");

if (fileInfo->has_attribute(G_FILE_ATTRIBUTE_TIME_MODIFIED))
{
Expand Down
4 changes: 1 addition & 3 deletions src/detwinner/ui/SearchResultsPane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Name : SearchResultsPane.cpp
Author : NeatDecisions
Version :
Copyright : Copyright © 2018 Neat Decisions. All rights reserved.
Copyright : Copyright © 2018–2020 Neat Decisions. All rights reserved.
Description : Detwinner
===============================================================================
*/
Expand Down Expand Up @@ -89,8 +89,6 @@ SearchResultsPane::execute_duplicate_action(const Glib::ustring & label, callbac
freeze_notify();

Glib::Timer timer;

timer.start();
while (action->processNext())
{
if (timer.elapsed() > 0.2)
Expand Down

0 comments on commit 3c1a25f

Please sign in to comment.