| 1 | #cxx . . $ `<file>/src/include/sampler.hpp`/pragma once |
| 2 | |
| 3 | #if !defined(_WIN32) |
| 4 | #include <pthread.h> |
| 5 | #include <unistd.h> |
| 6 | #endif |
| 7 | |
| 8 | #include <cmath> |
| 9 | #include <cstdint> |
| 10 | #include <iostream> |
| 11 | #include <random> |
| 12 | #include <thread> |
| 13 | |
| 14 | #include "common.hpp"cxx . . $ `<file>/src/include/common.hpp`/ |
| 15 | #include "printf.h"cxx . . $ `<file>/vendor/printf/printf.h`/ |
| 16 | |
| 17 | #define SAMPLER_DETERMINISTICcxx . . $ `src/include/sampler.hpp:17:9`! 0 |
| 18 | #define SAMPLER_LOWDISCREPANCYcxx . . $ `src/include/sampler.hpp:18:9`! 0 |
| 19 | |
| 20 | #include <stdio.h> |
| 21 | #include <time.h> |
| 22 | |
| 23 | #if SAMPLER_LOWDISCREPANCYcxx . . $ `src/include/sampler.hpp:18:9`! |
| 24 | #include "lowdiscrepancy.hpp" |
| 25 | #endif |
| 26 | |
| 27 | template <uint64_tcxx . . $ uint64_t# SAMPLE_RATE> |
| 28 | class Samplercxx . . $ Sampler# { |
| 29 | private: |
| 30 | static constexpr double SAMPLE_PROBABILITYcxx . . $ Sampler#SAMPLE_PROBABILITY. = |
| 31 | (double)1.0 / (double)SAMPLE_RATE; |
| 32 | |
| 33 | uint64_tcxx . . $ uint64_t# _nextcxx . . $ Sampler#_next.; |
| 34 | #if !SAMPLER_DETERMINISTICcxx . . $ `src/include/sampler.hpp:17:9`! |
| 35 | #if !SAMPLER_LOWDISCREPANCYcxx . . $ `src/include/sampler.hpp:18:9`! |
| 36 | stdcxx . . $ std/::mt19937_64cxx . . $ std/mt19937_64# rngcxx . . $ Sampler#rng.{cxx . . $ std/mersenne_twister_engine#mersenne_twister_engine(9b289cee16747614).1234567890UL + (uint64_tcxx . . $ uint64_t#)getpid() + (uint64_tcxx . . $ uint64_t#)this + |
| 37 | (uint64_tcxx . . $ uint64_t#)pthread_self()}; |
| 38 | #else |
| 39 | LowDiscrepancy rng{1}; // 234567890UL + (uint64_t)getpid() + (uint64_t)this + |
| 40 | // (uint64_t)pthread_self()}; |
| 41 | #endif |
| 42 | #endif |
| 43 | |
| 44 | stdcxx . . $ std/::geometric_distributioncxx . . $ std/geometric_distribution#<uint64_tcxx . . $ uint64_t#> geomcxx . . $ Sampler#geom.{cxx . . $ std/geometric_distribution#geometric_distribution(ba8836b59fb42830).SAMPLE_PROBABILITYcxx . . $ Sampler#SAMPLE_PROBABILITY.}; |
| 45 | |
| 46 | public: |
| 47 | Samplercxx . . $ Sampler#`Sampler<SAMPLE_RATE>`(49f6e7a06ebc5aa8).() { |
| 48 | #if !SAMPLER_DETERMINISTICcxx . . $ `src/include/sampler.hpp:17:9`! |
| 49 | while (true) { |
| 50 | _nextcxx . . $ Sampler#_next. = geomcxx . . $ Sampler#geom.(cxx . . $ std/geometric_distribution#`operator()`(bd98775284160f6b).rngcxx . . $ Sampler#rng.); |
| 51 | if (_nextcxx . . $ Sampler#_next. != 0) { |
| 52 | break; |
| 53 | } |
| 54 | } |
| 55 | #else |
| 56 | _next = SAMPLE_RATE; |
| 57 | #endif |
| 58 | } |
| 59 | |
| 60 | inline ATTRIBUTE_ALWAYS_INLINEcxx . . $ `src/include/common.hpp:12:9`! void unsamplecxx . . $ Sampler#unsample(2c44cd906ae4e829).(uint64_tcxx . . $ uint64_t# sz) { |
| 61 | if (_nextcxx . . $ Sampler#_next. < SAMPLE_RATE / 2) { |
| 62 | _nextcxx . . $ Sampler#_next. += sz; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | inline ATTRIBUTE_ALWAYS_INLINEcxx . . $ `src/include/common.hpp:12:9`! uint64_tcxx . . $ uint64_t# samplecxx . . $ Sampler#sample(ecdaa1632f49f591).(uint64_tcxx . . $ uint64_t# sz) { |
| 67 | if (unlikelycxx . . $ `src/include/common.hpp:8:9`!(_next <= sz)) { |
| 68 | // return updateSample(sz - _next); |
| 69 | return updateSamplecxx . . $ Sampler#updateSample(ecdaa1632f49f591).(sz); |
| 70 | } |
| 71 | assertcxx . . $ `/usr/include/assert.h:50:10`!(sz < _next); |
| 72 | _nextcxx . . $ Sampler#_next. -= sz; |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | uint64_tcxx . . $ uint64_t# updateSamplecxx . . $ Sampler#updateSample(ecdaa1632f49f591).(uint64_tcxx . . $ uint64_t# sz) { |
| 77 | #if SAMPLER_DETERMINISTICcxx . . $ `src/include/sampler.hpp:17:9`! |
| 78 | _next = SAMPLE_RATE; |
| 79 | #else |
| 80 | while (true) { |
| 81 | _nextcxx . . $ Sampler#_next. = geomcxx . . $ Sampler#geom.(cxx . . $ std/geometric_distribution#`operator()`(bd98775284160f6b).rngcxx . . $ Sampler#rng.); |
| 82 | if (_nextcxx . . $ Sampler#_next. != 0) { |
| 83 | break; |
| 84 | } |
| 85 | } |
| 86 | #endif |
| 87 | if (sz >= SAMPLE_RATE) { |
| 88 | return sz; |
| 89 | } |
| 90 | return SAMPLE_RATE; |
| 91 | } |
| 92 | }; |