forked from Abc-Arbitrage/Disruptor-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil.h
More file actions
63 lines (50 loc) · 1.71 KB
/
Util.h
File metadata and controls
63 lines (50 loc) · 1.71 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#pragma once
#include <cstdint>
#include <limits>
#include <memory>
#include <vector>
#include "Disruptor/IEventProcessor.h"
#include "Disruptor/ISequence.h"
namespace Disruptor
{
class IEventProcessor;
class ISequence;
namespace Util
{
/**
* Calculate the next power of 2, greater than or equal to x.
*
* \param x Value to round up
* \returns The next power of 2 from x inclusive
*/
std::int32_t ceilingNextPowerOfTwo(std::int32_t x);
/**
* Test whether a given integer is a power of 2
*
* \param x
*/
bool isPowerOf2(std::int32_t x);
/**
* Calculate the log base 2 of the supplied integer, essentially reports the location of the highest bit.
*
* \param i Value to calculate log2 for.
* \returns The log2 value
*/
std::int32_t log2(std::int32_t i);
/**
* Get the minimum sequence from an array of Sequences.
*
* \param sequences sequences to compare.
* \param minimum an initial default minimum. If the array is empty this value will returned.
* \returns the minimum sequence found or lon.MaxValue if the array is empty.
*/
std::int64_t getMinimumSequence(const std::vector< std::shared_ptr< ISequence > >& sequences, std::int64_t minimum = std::numeric_limits< std::int64_t >::max());
/**
* Get an array of Sequences for the passed IEventProcessors
*
* \param processors processors for which to get the sequences
* \returns the array of\returns <see cref="Sequence"/>\returns s
*/
std::vector< std::shared_ptr< ISequence > > getSequencesFor(const std::vector< std::shared_ptr< IEventProcessor > >& processors);
} // namespace Util
} // namespace Disruptor