Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions examples/cycle_count.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <atomic>
#include <random>

#include <parlay/parallel.h>
#include <parlay/primitives.h>
Expand All @@ -24,14 +23,12 @@ struct lnk {

long cycle_count(parlay::sequence<long>& permutation) {
long n = permutation.size();
parlay::random_generator gen(0);
std::uniform_int_distribution<long> dis(0, n-1);
auto priority = parlay::random_permutation(n);
parlay::sequence<lnk> links(n);
parlay::parallel_for(0, n, [&] (long i) {
links[i].next = &links[permutation[i]];
links[permutation[i]].prev = &links[i];
auto r = gen[i];
links[i].p = dis(r);
links[i].p = priority[i];
});

parlay::parallel_for(0, n, [&] (long i) {
Expand All @@ -40,6 +37,7 @@ long cycle_count(parlay::sequence<long>& permutation) {
links[i].is_leaf = links[i].degree == 0;});

auto roots = parlay::tabulate(n, [&] (long i) {
if (permutation[i] == i) return 1;
if (!links[i].is_leaf) return 0;
lnk* l = &links[i];
do {
Expand Down
7 changes: 5 additions & 2 deletions examples/hash_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ struct hash_map {
std::optional<V> find(const K& k) {
index i = first_index(k);
while (true) {
if (H[i].status != full) return {};
if (H[i].key == k) return H[i].value;
if (H[i].status == empty || H[i].status == locked) return {};
if (H[i].key == k) {
if (H[i].status == full) return H[i].value;
else return {};
}
i = next_index(i);
}
}
Expand Down