Skip to content

Commit

Permalink
Fix #80 - shuffle with containers that have 32bit index
Browse files Browse the repository at this point in the history
  • Loading branch information
martinus committed Dec 5, 2022
1 parent a1fcc09 commit a7030c6
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/CODE_OF_CONDUCT.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<img src="_static/nanobench-logo.svg" class="logo" alt="Logo"/>
</a>
<div class="version">
v4.3.8
v4.3.9
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
Expand Down
2 changes: 1 addition & 1 deletion docs/comparison.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<img src="_static/nanobench-logo.svg" class="logo" alt="Logo"/>
</a>
<div class="version">
v4.3.8
v4.3.9
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
Expand Down
2 changes: 1 addition & 1 deletion docs/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<img src="_static/nanobench-logo.svg" class="logo" alt="Logo"/>
</a>
<div class="version">
v4.3.8
v4.3.9
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<img src="_static/nanobench-logo.svg" class="logo" alt="Logo"/>
</a>
<div class="version">
v4.3.8
v4.3.9
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
Expand Down
2 changes: 1 addition & 1 deletion docs/license.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<img src="_static/nanobench-logo.svg" class="logo" alt="Logo"/>
</a>
<div class="version">
v4.3.8
v4.3.9
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
Expand Down
2 changes: 1 addition & 1 deletion docs/reference.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<img src="_static/nanobench-logo.svg" class="logo" alt="Logo"/>
</a>
<div class="version">
v4.3.8
v4.3.9
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
Expand Down
2 changes: 1 addition & 1 deletion docs/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<img src="_static/nanobench-logo.svg" class="logo" alt="Logo"/>
</a>
<div class="version">
v4.3.8
v4.3.9
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="#" method="get">
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<img src="_static/nanobench-logo.svg" class="logo" alt="Logo"/>
</a>
<div class="version">
v4.3.8
v4.3.9
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
Expand Down
2 changes: 1 addition & 1 deletion src/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
project = 'nanobench'
copyright = '2019-2022 Martin Leitner-Ankerl <[email protected]>'
author = 'Martin Leitner-Ankerl'
version = 'v4.3.8'
version = 'v4.3.9'

# -- General configuration ---------------------------------------------------

Expand Down
7 changes: 4 additions & 3 deletions src/include/nanobench.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// see https://semver.org/
#define ANKERL_NANOBENCH_VERSION_MAJOR 4 // incompatible API changes
#define ANKERL_NANOBENCH_VERSION_MINOR 3 // backwards-compatible changes
#define ANKERL_NANOBENCH_VERSION_PATCH 8 // backwards-compatible bug fixes
#define ANKERL_NANOBENCH_VERSION_PATCH 9 // backwards-compatible bug fixes

///////////////////////////////////////////////////////////////////////////////////////////////////
// public facing api - as minimal as possible
Expand Down Expand Up @@ -1182,10 +1182,11 @@ void Rng::shuffle(Container& container) noexcept {
while (i > 1U) {
using std::swap;
auto n = operator()();
auto b1 = static_cast<size_t>((static_cast<uint32_t>(n) * static_cast<uint64_t>(i)) >> 32U);
// using decltype(i) instead of size_t to be compatible to containers with 32bit index (see #80)
auto b1 = static_cast<decltype(i)>((static_cast<uint32_t>(n) * static_cast<uint64_t>(i)) >> 32U);
swap(container[--i], container[b1]);

auto b2 = static_cast<size_t>(((n >> 32U) * static_cast<uint64_t>(i)) >> 32U);
auto b2 = static_cast<decltype(i)>(((n >> 32U) * static_cast<uint64_t>(i)) >> 32U);
swap(container[--i], container[b2]);
}
}
Expand Down

0 comments on commit a7030c6

Please sign in to comment.