-
Notifications
You must be signed in to change notification settings - Fork 4
/
permute.hpp
43 lines (32 loc) · 1.2 KB
/
permute.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (c) Lorenz Hübschle-Schneider
// All Rights Reserved. This source code is licensed under the Apache 2.0
// License (found in the LICENSE file in the root directory).
#pragma once
#include "config.hpp"
#include "hasher.hpp"
namespace ribbon {
template <typename Config>
class Permuter : public ChooseHasher<Config> {
public:
using Index = typename Config::Index;
using ChooseHasher<Config>::ChooseHasher;
static constexpr Index StartToSort(Index startpos) {
return (startpos ^ (Config::kBucketSize - 1));
}
// the transformation is identical
static constexpr Index SortToStart(Index sortpos) {
return StartToSort(sortpos);
}
static constexpr Index GetBucket(Index sortOrStartPos) {
return sortOrStartPos / Config::kBucketSize;
}
static constexpr Index GetIntraBucket(Index sortpos) {
// it's a compile-time power-of-two constant -> fast
return sortpos % Config::kBucketSize;
}
static constexpr Index GetIntraBucketFromStart(Index startpos) {
// it's a compile-time power-of-two constant -> fast
return Config::kBucketSize - 1 - (startpos % Config::kBucketSize);
}
};
} // namespace ribbon