/usr/include/hphp/util/multibitset.h is in hhvm-dev 3.21.0+dfsg-2ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | /*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#ifndef incl_HPHP_UTIL_MULTIBITSET_H_
#define incl_HPHP_UTIL_MULTIBITSET_H_
#include <cstddef>
#include <cstdint>
#include <limits>
#include <unordered_map>
namespace HPHP {
///////////////////////////////////////////////////////////////////////////////
/*
* Like a bitset, but we have N bits at each position instead of 1.
*/
template<size_t N>
struct multibitset {
/*
* Create an empty multibitset with no bits allocated.
*/
multibitset();
/*
* Allocate a multibitset with room for `nelms' N-bits, and zero it.
*/
explicit multibitset(size_t nelms);
/*
* Free the allocated bits.
*/
~multibitset();
/*
* Make room for `nelms' N-bits in the set, shrinking it if `nelms' is
* smaller than the current size.
*/
void resize(size_t nelms);
/*
* Set all N-bits to zero.
*/
void reset();
/////////////////////////////////////////////////////////////////////////////
/*
* Reference to an N-bit.
*
* Behaves analogously to std::bitset::reference.
*/
struct reference {
/* implicit */ operator uint64_t() const;
reference& operator=(uint64_t);
friend struct multibitset<N>;
private:
reference(multibitset<N>& mbs, size_t pos);
private:
multibitset<N>& m_mbs;
size_t m_word;
uint8_t m_bit;
};
static constexpr size_t npos = std::numeric_limits<uint64_t>::max();
/////////////////////////////////////////////////////////////////////////////
/*
* Access a specific N-bit.
*
* This asserts that `pos <= N'; as such, we do not implement a test().
*/
uint64_t operator[](size_t pos) const;
reference operator[](size_t pos);
/*
* Returns the number of N-bits the multibitset can hold.
*/
size_t size() const;
/*
* Find the position of the first or last N-bit set to a nonzero value,
* starting at `pos'. Note that `pos' is an inclusive bound, so `pos' itself
* may be returned.
*
* Returns `npos' if no set N-bit is found.
*/
size_t ffs(size_t pos = 0) const;
size_t fls(size_t pos = npos) const;
/////////////////////////////////////////////////////////////////////////////
private:
static_assert(N > 0 && N < 64, "must have 0 < N < 64");
private:
uint64_t* m_bits{nullptr};
size_t m_size{0};
size_t m_nwords{0};
};
template<size_t N>
constexpr size_t multibitset<N>::npos;
///////////////////////////////////////////////////////////////////////////////
/*
* An alternate multibitset interface intended for use patterns with sparse
* clusters of marked bits.
*
* Has roughly the same interface as multibitset, with exceptions noted.
*/
template<size_t N>
struct chunked_multibitset {
/*
* Create an empty multibitset.
*
* chunked_multibitset automatically expands storage as bits are set. Thus,
* it does not accept a size restriction; instead, it takes a chunk size.
*/
explicit chunked_multibitset(size_t chunk_sz);
/////////////////////////////////////////////////////////////////////////////
struct reference {
/* implicit */ operator uint64_t() const;
reference& operator=(uint64_t);
friend struct chunked_multibitset<N>;
private:
reference(chunked_multibitset<N>& cmbs, size_t pos);
private:
chunked_multibitset<N>& m_cmbs;
size_t m_pos;
};
static constexpr size_t npos = std::numeric_limits<uint64_t>::max();
/////////////////////////////////////////////////////////////////////////////
void reset();
/*
* Return a reference to an N-bit.
*
* Setting an N-bit may cause new chunks to be allocated.
*/
uint64_t operator[](size_t pos) const;
reference operator[](size_t pos);
/*
* Find set bit; see multibitset::f{f,l}s().
*
* The time complexity of these routines is linearly bounded by the number of
* chunks in which bits have been touched during the lifetime of the object.
* No other guarantees are made.
*/
size_t ffs(size_t pos = 0) const;
size_t fls(size_t pos = npos) const;
/////////////////////////////////////////////////////////////////////////////
private:
static_assert(N > 0 && N <= 64, "must have 0 < N <= 64");
multibitset<N>& chunk_for(size_t pos);
private:
std::unordered_map<size_t,multibitset<N>> m_chunks;
const size_t m_chunk_sz;
size_t m_highwater{0};
size_t m_lowwater{npos};
};
template<size_t N>
constexpr size_t chunked_multibitset<N>::npos;
///////////////////////////////////////////////////////////////////////////////
}
#include "hphp/util/multibitset-inl.h"
#endif
|