Skip to content

Commit

Permalink
Clean up clustering generation code
Browse files Browse the repository at this point in the history
  • Loading branch information
hkalodner committed May 5, 2018
1 parent 53ce267 commit ed2071e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
12 changes: 0 additions & 12 deletions include/blocksci/cluster/cluster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,6 @@ namespace blocksci {

ranges::any_view<Address> getAddresses() const;

// auto taggedAddressesImpl(const std::unordered_map<DedupAddress, std::pair<AddressType::Enum, std::string> &tags) const {
// auto access_ = &clusterAccess.access;
// return getPossibleAddresses() | ranges::view::transform([tags, access_](const DedupAddress &address) -> ranges::optional<TaggedAddress> {
// auto it = tags.find(address);
// if (it != tags.end()) {
// return TaggedAddress{Address(address.scriptNum, it->second.first, *access_), it->second.second};
// } else {
// return ranges::nullopt;
// }
// }) | flatMapOptionals();
// }

auto taggedAddresses(const std::unordered_map<blocksci::Address, std::string> &tags) const {
return getPossibleAddresses() | ranges::view::transform([tags](Address && address) -> ranges::optional<TaggedAddress> {
auto it = tags.find(address);
Expand Down
6 changes: 6 additions & 0 deletions include/blocksci/core/dedup_address_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ namespace blocksci {
using all = std::tuple<DEDUP_ADDRESS_TYPE_LIST>;
#undef VAL
static constexpr Enum example = PUBKEY;

#define VAL(x) x
static std::array<Enum,size> allArray() {
return {{DEDUP_ADDRESS_TYPE_LIST}};
}
#undef VAL
};

template <template<DedupAddressType::Enum> class K>
Expand Down
21 changes: 13 additions & 8 deletions src/cluster/cluster_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,12 @@ namespace blocksci {
boost::filesystem::path offsetFile = outputLocation/"clusterOffsets.dat";
boost::filesystem::path addressesFile = outputLocation/"clusterAddresses.dat";
std::vector<boost::filesystem::path> clusterIndexPaths;
for_each(DedupAddressType::all(), [&](auto dedupType) {
clusterIndexPaths.resize(DedupAddressType::size);
for (auto dedupType : DedupAddressType::allArray()) {
std::stringstream ss;
ss << dedupAddressName(dedupType) << "_cluster_index.dat";
clusterIndexPaths.push_back(outputLocation/ss.str());
});
clusterIndexPaths[static_cast<size_t>(dedupType)] = outputLocation/ss.str();
}

std::vector<boost::filesystem::path> allPaths = clusterIndexPaths;
allPaths.push_back(offsetFile);
Expand Down Expand Up @@ -269,12 +270,16 @@ namespace blocksci {
size_t totalScriptCount = scripts.totalAddressCount();

std::unordered_map<DedupAddressType::Enum, uint32_t> scriptStarts;
for_each(DedupAddressType::all(), [&](auto type) {
scriptStarts[type] = 0;
for (size_t j = 0; j < static_cast<size_t>(type); j++) {
scriptStarts[type] += scripts.scriptCount(static_cast<DedupAddressType::Enum>(j));
{
std::vector<uint32_t> starts;
starts.reserve(DedupAddressType::size);
for (size_t i = 0; i < DedupAddressType::size; i++) {
if (i > 0) {
starts[i] = scripts.scriptCount(static_cast<DedupAddressType::Enum>(i - 1)) + starts[i - 1];
}
scriptStarts[static_cast<DedupAddressType::Enum>(i)] = starts[i];
}
});
}

auto parent = createClusters(chain, scriptStarts, static_cast<uint32_t>(totalScriptCount), changeHeuristic);
uint32_t clusterCount = remapClusterIds(parent);
Expand Down

0 comments on commit ed2071e

Please sign in to comment.