Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gblelloch committed Mar 1, 2024
1 parent fa95e45 commit 2b5154e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 15 deletions.
1 change: 0 additions & 1 deletion examples/BFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ int main(int argc, char* argv[]) {
catch (...) {}
if (n == 0) {
G = utils::read_symmetric_graph_from_file(argv[1]);
n = G.size();
} else {
G = utils::rmat_graph(n, 20*n);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/hash_map.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#include <iostream>
#include <string>

#include <parlay/internal/get_time.h>
#include <parlay/primitives.h>
#include <parlay/random.h>
#include <parlay/internal/get_time.h>

#include "hash_map.h"

// **************************************************************
// Driver
// **************************************************************
int main(int argc, char* argv[]) {
auto usage = "hash_map <n>";
const auto usage = "hash_map <n>";
if (argc != 2) std::cout << usage << std::endl;
else {
long n;
Expand Down
6 changes: 3 additions & 3 deletions examples/hash_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

#include <algorithm>
#include <atomic>
#include <functional>
#include <optional>
#include <utility>
#include <iostream>
#include <functional>
#include <utility>

#include <parlay/primitives.h>
#include <parlay/sequence.h>
Expand Down Expand Up @@ -47,7 +47,7 @@ struct hash_map {

public:
hash_map(long size, Hash&& hash = {}, Equal&& equal = {})
: m(100 + static_cast<index>(1.5 * size)),
: m(100 + static_cast<long>(1.5 * static_cast<float>(size))),
hash(hash), equal(equal),
H(parlay::sequence<entry>(m)) {}

Expand Down
11 changes: 8 additions & 3 deletions examples/helper/graph_utils.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#include <utility>
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <type_traits>

#include <parlay/primitives.h>
#include <parlay/sequence.h>
#include <parlay/delayed.h>
#include <parlay/random.h>
#include <parlay/io.h>

namespace delay = parlay::delayed;
Expand Down Expand Up @@ -138,19 +143,19 @@ struct graph_utils {
}

static graph rmat_graph(long n, long m, double a=.5, double b=.15, double c=.15) {
int logn = round(log2(n));
int logn = static_cast<int>(round(log2(static_cast<int>(n))));
auto edges = rmat_edges_(logn, m, a, b, c);
return parlay::group_by_index(edges, 1 << logn);
}

static graph rmat_symmetric_graph(long n, long m, double a=.5, double b=.15, double c=.15) {
int logn = round(log2(n));
int logn = static_cast<int>(round(log2(static_cast<int>(n))));
auto edges = rmat_edges_(logn, m/2, a, b, c);
return symmetrize(edges, 1 << logn);
}

static graph grid_graph(long n) {
vertex sqn = sqrt(n);
vertex sqn = static_cast<vertex>(std::sqrt(static_cast<float>(n)));
parlay::sequence<vertex> offsets({-1-sqn,-sqn,1-sqn,-1,1,-1+sqn,sqn,1+sqn});
return parlay::tabulate(sqn*sqn, [&] (vertex u) {
auto nghs = map(offsets, [&] (vertex o) {return u+o;});
Expand Down
2 changes: 1 addition & 1 deletion examples/integer_sort.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void radix_sort(Range in, Range out, long bits, bool inplace) {

// extract the needed bits for the keys
auto keys = parlay::delayed::tabulate(n, [&] (long i) {
return (in[i] >> bits - radix_bits) & (num_buckets-1);});
return (in[i] >> (bits - radix_bits)) & (num_buckets-1);});

// sort in into the out based on keys
auto offsets = counting_sort(in.begin(), in.end(), out.begin(), keys.begin(),
Expand Down
4 changes: 2 additions & 2 deletions examples/word_counts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ int main(int argc, char* argv[]) {
charseq str = parlay::chars_from_file(argv[2]);

// clean up by just keeping alphabetic chars, and lowercase them
str = parlay::map(str, [] (unsigned char c) -> char {
return std::isalpha(c) ? std::tolower(c) : ' '; });
str = parlay::map(str, [] (char c) -> char {
return std::isalpha(c) ? static_cast<char>(std::tolower(c)) : ' '; });

parlay::sequence<std::pair<parlay::chars, long>> counts;
parlay::internal::timer t("Time");
Expand Down
6 changes: 3 additions & 3 deletions include/parlay/internal/get_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct timer {
return std::chrono::system_clock::now();
}

void report(double time, std::string str) {
void report(double time, const std::string& str) {
std::ios::fmtflags cout_settings = std::cout.flags();
std::cout.precision(4);
std::cout << std::fixed;
Expand All @@ -39,7 +39,7 @@ struct timer {


timer(std::string name = "Parlay time", bool start_ = true)
: total_so_far(0.0), on(false), name(name) {
: total_so_far(0.0), on(false), name(std::move(name)) {
if (start_) start();
}

Expand Down Expand Up @@ -74,7 +74,7 @@ struct timer {
else return total_so_far;
}

void next(std::string str) {
void next(const std::string& str) {
if (on) report(next_time(), str);
}

Expand Down

0 comments on commit 2b5154e

Please sign in to comment.