Skip to content

Commit

Permalink
Update rng.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
KRM7 committed Sep 15, 2024
1 parent a12b17a commit c08c71a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
{ cxx: g++-11, pkgs: gcc@11, extra-flags: "-undefined dynamic_lookup -Wno-psabi -Wno-nonnull" },
{ cxx: g++-12, pkgs: gcc@12, extra-flags: "-undefined dynamic_lookup -Wno-psabi -Wno-nonnull" },
{ cxx: g++-13, pkgs: gcc@13, extra-flags: "-undefined dynamic_lookup -Wno-psabi -Wno-nonnull" },
{ cxx: g++-14, pkgs: gcc@14, extra-flags: "-undefined dynamic_lookup -Wno-psabi -Wno-nonnull" },
{ cxx: g++-14, pkgs: gcc@14 llvm@15, extra-flags: "-undefined dynamic_lookup -Wno-psabi -Wno-nonnull -fsanitize=undefined -g -fno-omit-frame-pointer" },
{
cxx: $(brew --prefix llvm@15)/bin/clang++,
pkgs: llvm@15 gcc@11,
Expand Down
15 changes: 14 additions & 1 deletion src/utility/rng.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <cstddef>
#include <concepts>

#include <iostream>


#ifndef GAPP_SEED
# define GAPP_SEED 0x3da99432ab975d26LL
Expand Down Expand Up @@ -457,6 +459,8 @@ namespace gapp::rng
template<std::integral IntType>
GAPP_NOINLINE small_vector<IntType> sampleUniqueSet(IntType lbound, IntType ubound, size_t count)
{
std::cout << "sampleUniqueSet\n";

std::unordered_set<IntType> selected(count);
small_vector<IntType> numbers(count);

Expand All @@ -477,20 +481,29 @@ namespace gapp::rng
{
const size_t range_len = detail::range_length(lbound, ubound);

std::cout << "Sample unique lbound: " << lbound << ", ubound: " << ubound << ", count: " << count << "\n";

GAPP_ASSERT(ubound >= lbound);
GAPP_ASSERT(range_len >= count);

const bool select_many = (count > 0.6 * range_len);
const bool huge_range = (range_len >= 65536);
const bool huge_range = (range_len >= 65536_sz);

std::cout << "Range len: " << range_len << ", huge_range: " << huge_range << "\n";
std::cout << "select many: " << select_many << "\n";

if (huge_range) [[unlikely]] return rng::sampleUniqueSet(lbound, ubound, count);

std::cout << "Sample unique small\n";

small_vector<IntType> numbers(count);

thread_local detail::dynamic_bitset is_selected;
is_selected.resize(range_len);
is_selected.fill(select_many);

std::cout << "Allocated\n";

if (!select_many)
{
IntType limit = ubound - detail::promoted_t<IntType>(count);
Expand Down

0 comments on commit c08c71a

Please sign in to comment.