-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwe.h
More file actions
29 lines (24 loc) · 674 Bytes
/
we.h
File metadata and controls
29 lines (24 loc) · 674 Bytes
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
/*
* An implementation of Wong and Easton's tree-based method for sampling
* categorical random variables. The original algorithm was specified in
* "An Efficient Method for Weighted Sampling without Replacement". This
* implementation uses a fixed size, flattened tree representation.
*/
#ifndef WE_H
#define WE_H
#include <random>
#include <vector>
class we {
private:
uint64_t levels;
uint64_t round_size;
std::vector<uint64_t> tree;
std::random_device rd;
std::mt19937_64 gen;
public:
we(const std::vector<uint64_t>& dist);
int sample();
void update(int idx, int value);
void delta_update(int idx, int delta);
};
#endif