| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/jsruntime/qv4sparsearray_p.h |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | namespace QV4 { | - | ||||||||||||
| 4 | - | |||||||||||||
| 5 | struct SparseArray; | - | ||||||||||||
| 6 | - | |||||||||||||
| 7 | struct SparseArrayNode | - | ||||||||||||
| 8 | { | - | ||||||||||||
| 9 | quintptr p; | - | ||||||||||||
| 10 | SparseArrayNode *left; | - | ||||||||||||
| 11 | SparseArrayNode *right; | - | ||||||||||||
| 12 | uint size_left; | - | ||||||||||||
| 13 | uint value; | - | ||||||||||||
| 14 | - | |||||||||||||
| 15 | enum Color { Red = 0, Black = 1 }; | - | ||||||||||||
| 16 | enum { Mask = 3 }; | - | ||||||||||||
| 17 | - | |||||||||||||
| 18 | const SparseArrayNode *nextNode() const; | - | ||||||||||||
| 19 | SparseArrayNode *nextNode() { return executed 1549 times by 2 tests: const_cast<SparseArrayNode *>(const_cast<const SparseArrayNode *>(this)->nextNode());return const_cast<SparseArrayNode *>(const_cast<const SparseArrayNode *>(this)->nextNode());Executed by:
executed 1549 times by 2 tests: }return const_cast<SparseArrayNode *>(const_cast<const SparseArrayNode *>(this)->nextNode());Executed by:
| 1549 | ||||||||||||
| 20 | const SparseArrayNode *previousNode() const; | - | ||||||||||||
| 21 | SparseArrayNode *previousNode() { return executed 362 times by 1 test: const_cast<SparseArrayNode *>(const_cast<const SparseArrayNode *>(this)->previousNode());return const_cast<SparseArrayNode *>(const_cast<const SparseArrayNode *>(this)->previousNode());Executed by:
executed 362 times by 1 test: }return const_cast<SparseArrayNode *>(const_cast<const SparseArrayNode *>(this)->previousNode());Executed by:
| 362 | ||||||||||||
| 22 | - | |||||||||||||
| 23 | Color color() const { return executed 5531 times by 2 tests: Color(p & 1);return Color(p & 1);Executed by:
executed 5531 times by 2 tests: }return Color(p & 1);Executed by:
| 5531 | ||||||||||||
| 24 | void setColor(Color c) { if (c == Black
executed 8308 times by 2 tests: else p &= ~Black;p |= Black;Executed by:
executed 7823 times by 2 tests: }p &= ~Black;Executed by:
| 7821-8309 | ||||||||||||
| 25 | SparseArrayNode *parent() const { return executed 28724 times by 2 tests: reinterpret_cast<SparseArrayNode *>(p & ~Mask);return reinterpret_cast<SparseArrayNode *>(p & ~Mask);Executed by:
executed 28724 times by 2 tests: }return reinterpret_cast<SparseArrayNode *>(p & ~Mask);Executed by:
| 28724 | ||||||||||||
| 26 | void setParent(SparseArrayNode *pp) { p = (p & Mask) | quintptr(pp); } executed 8948 times by 2 tests: end of blockExecuted by:
| 8948 | ||||||||||||
| 27 | - | |||||||||||||
| 28 | uint key() const { | - | ||||||||||||
| 29 | uint k = size_left; | - | ||||||||||||
| 30 | const SparseArrayNode *n = this; | - | ||||||||||||
| 31 | while (SparseArrayNode *p = n->parent()
| 1004-1459 | ||||||||||||
| 32 | if (p
| 0-1459 | ||||||||||||
| 33 | k += p->size_left; executed 240 times by 2 tests: k += p->size_left;Executed by:
| 240 | ||||||||||||
| 34 | n = p; | - | ||||||||||||
| 35 | } executed 1460 times by 2 tests: end of blockExecuted by:
| 1460 | ||||||||||||
| 36 | return executed 1005 times by 2 tests: k;return k;Executed by:
executed 1005 times by 2 tests: return k;Executed by:
| 1005 | ||||||||||||
| 37 | } | - | ||||||||||||
| 38 | - | |||||||||||||
| 39 | SparseArrayNode *copy(SparseArray *d) const; | - | ||||||||||||
| 40 | - | |||||||||||||
| 41 | SparseArrayNode *lowerBound(uint key); | - | ||||||||||||
| 42 | SparseArrayNode *upperBound(uint key); | - | ||||||||||||
| 43 | }; | - | ||||||||||||
| 44 | - | |||||||||||||
| 45 | - | |||||||||||||
| 46 | inline SparseArrayNode *SparseArrayNode::lowerBound(uint akey) | - | ||||||||||||
| 47 | { | - | ||||||||||||
| 48 | SparseArrayNode *n = this; | - | ||||||||||||
| 49 | SparseArrayNode *last = nullptr; | - | ||||||||||||
| 50 | while (n
| 158-352 | ||||||||||||
| 51 | if (akey <= n->size_left
| 170-182 | ||||||||||||
| 52 | last = n; | - | ||||||||||||
| 53 | n = n->left; | - | ||||||||||||
| 54 | } executed 170 times by 1 test: else {end of blockExecuted by:
| 170 | ||||||||||||
| 55 | akey -= n->size_left; | - | ||||||||||||
| 56 | n = n->right; | - | ||||||||||||
| 57 | } executed 182 times by 1 test: end of blockExecuted by:
| 182 | ||||||||||||
| 58 | } | - | ||||||||||||
| 59 | return executed 158 times by 1 test: last;return last;Executed by:
executed 158 times by 1 test: return last;Executed by:
| 158 | ||||||||||||
| 60 | } | - | ||||||||||||
| 61 | - | |||||||||||||
| 62 | - | |||||||||||||
| 63 | inline SparseArrayNode *SparseArrayNode::upperBound(uint akey) | - | ||||||||||||
| 64 | { | - | ||||||||||||
| 65 | SparseArrayNode *n = this; | - | ||||||||||||
| 66 | SparseArrayNode *last = nullptr; | - | ||||||||||||
| 67 | while (n
| 0 | ||||||||||||
| 68 | if (akey < n->size_left
| 0 | ||||||||||||
| 69 | last = n; | - | ||||||||||||
| 70 | n = n->left; | - | ||||||||||||
| 71 | } never executed: else {end of block | 0 | ||||||||||||
| 72 | akey -= n->size_left; | - | ||||||||||||
| 73 | n = n->right; | - | ||||||||||||
| 74 | } never executed: end of block | 0 | ||||||||||||
| 75 | } | - | ||||||||||||
| 76 | return never executed: last;return last;never executed: return last; | 0 | ||||||||||||
| 77 | } | - | ||||||||||||
| 78 | - | |||||||||||||
| 79 | - | |||||||||||||
| 80 | - | |||||||||||||
| 81 | struct __attribute__((visibility("default"))) SparseArray | - | ||||||||||||
| 82 | { | - | ||||||||||||
| 83 | SparseArray(); | - | ||||||||||||
| 84 | ~SparseArray() { | - | ||||||||||||
| 85 | if (root()
| 262-2944 | ||||||||||||
| 86 | freeTree(header.left, alignof(SparseArrayNode)); executed 2944 times by 2 tests: freeTree(header.left, alignof(SparseArrayNode));Executed by:
| 2944 | ||||||||||||
| 87 | } executed 3206 times by 2 tests: end of blockExecuted by:
| 3206 | ||||||||||||
| 88 | - | |||||||||||||
| 89 | SparseArray(const SparseArray &other); | - | ||||||||||||
| 90 | - | |||||||||||||
| 91 | Value freeList; | - | ||||||||||||
| 92 | private: | - | ||||||||||||
| 93 | SparseArray &operator=(const SparseArray &other); | - | ||||||||||||
| 94 | - | |||||||||||||
| 95 | int numEntries; | - | ||||||||||||
| 96 | SparseArrayNode header; | - | ||||||||||||
| 97 | SparseArrayNode *mostLeftNode; | - | ||||||||||||
| 98 | - | |||||||||||||
| 99 | void rotateLeft(SparseArrayNode *x); | - | ||||||||||||
| 100 | void rotateRight(SparseArrayNode *x); | - | ||||||||||||
| 101 | void rebalance(SparseArrayNode *x); | - | ||||||||||||
| 102 | void recalcMostLeftNode(); | - | ||||||||||||
| 103 | - | |||||||||||||
| 104 | SparseArrayNode *root() const { return executed 27376298 times by 2 tests: header.left;return header.left;Executed by:
executed 27376298 times by 2 tests: }return header.left;Executed by:
| 27376298 | ||||||||||||
| 105 | - | |||||||||||||
| 106 | void deleteNode(SparseArrayNode *z); | - | ||||||||||||
| 107 | - | |||||||||||||
| 108 | - | |||||||||||||
| 109 | public: | - | ||||||||||||
| 110 | SparseArrayNode *createNode(uint sl, SparseArrayNode *parent, bool left); | - | ||||||||||||
| 111 | void freeTree(SparseArrayNode *root, int alignment); | - | ||||||||||||
| 112 | - | |||||||||||||
| 113 | SparseArrayNode *findNode(uint akey) const; | - | ||||||||||||
| 114 | - | |||||||||||||
| 115 | uint nEntries() const { return never executed: numEntries;return numEntries;never executed: }return numEntries; | 0 | ||||||||||||
| 116 | - | |||||||||||||
| 117 | uint pop_front(); | - | ||||||||||||
| 118 | void push_front(uint at); | - | ||||||||||||
| 119 | uint pop_back(uint len); | - | ||||||||||||
| 120 | void push_back(uint at, uint len); | - | ||||||||||||
| 121 | - | |||||||||||||
| 122 | QList<int> keys() const; | - | ||||||||||||
| 123 | - | |||||||||||||
| 124 | const SparseArrayNode *end() const { return never executed: &header;return &header;never executed: }return &header; | 0 | ||||||||||||
| 125 | SparseArrayNode *end() { return executed 13756 times by 2 tests: &header;return &header;Executed by:
executed 13756 times by 2 tests: }return &header;Executed by:
| 13756 | ||||||||||||
| 126 | const SparseArrayNode *begin() const { if (root()
never executed: mostLeftNode;return mostLeftNode;never executed: returnreturn mostLeftNode;never executed: end();return end();never executed: }return end(); | 0 | ||||||||||||
| 127 | SparseArrayNode *begin() { if (root()
executed 613 times by 2 tests: mostLeftNode;return mostLeftNode;Executed by:
executed 613 times by 2 tests: returnreturn mostLeftNode;Executed by:
executed 38 times by 1 test: end();return end();Executed by:
executed 38 times by 1 test: }return end();Executed by:
| 38-613 | ||||||||||||
| 128 | - | |||||||||||||
| 129 | SparseArrayNode *erase(SparseArrayNode *n); | - | ||||||||||||
| 130 | - | |||||||||||||
| 131 | SparseArrayNode *lowerBound(uint key); | - | ||||||||||||
| 132 | const SparseArrayNode *lowerBound(uint key) const; | - | ||||||||||||
| 133 | SparseArrayNode *upperBound(uint key); | - | ||||||||||||
| 134 | const SparseArrayNode *upperBound(uint key) const; | - | ||||||||||||
| 135 | SparseArrayNode *insert(uint akey); | - | ||||||||||||
| 136 | - | |||||||||||||
| 137 | - | |||||||||||||
| 138 | typedef uint key_type; | - | ||||||||||||
| 139 | typedef int mapped_type; | - | ||||||||||||
| 140 | typedef qptrdiff difference_type; | - | ||||||||||||
| 141 | typedef int size_type; | - | ||||||||||||
| 142 | - | |||||||||||||
| 143 | - | |||||||||||||
| 144 | - | |||||||||||||
| 145 | - | |||||||||||||
| 146 | }; | - | ||||||||||||
| 147 | - | |||||||||||||
| 148 | inline SparseArrayNode *SparseArray::findNode(uint akey) const | - | ||||||||||||
| 149 | { | - | ||||||||||||
| 150 | SparseArrayNode *n = root(); | - | ||||||||||||
| 151 | - | |||||||||||||
| 152 | while (n
| 27363093-101893349 | ||||||||||||
| 153 | if (akey == n->size_left
| 23275-101877363 | ||||||||||||
| 154 | return executed 23278 times by 2 tests: n;return n;Executed by:
executed 23278 times by 2 tests: return n;Executed by:
| 23278 | ||||||||||||
| 155 | } else if (akey < n->size_left
| 27676901-74260435 | ||||||||||||
| 156 | n = n->left; | - | ||||||||||||
| 157 | } executed 27679471 times by 2 tests: else {end of blockExecuted by:
| 27679471 | ||||||||||||
| 158 | akey -= n->size_left; | - | ||||||||||||
| 159 | n = n->right; | - | ||||||||||||
| 160 | } executed 74263779 times by 2 tests: end of blockExecuted by:
| 74263779 | ||||||||||||
| 161 | } | - | ||||||||||||
| 162 | - | |||||||||||||
| 163 | return executed 27369006 times by 2 tests: nullptr;return nullptr;Executed by:
executed 27369006 times by 2 tests: return nullptr;Executed by:
| 27369006 | ||||||||||||
| 164 | } | - | ||||||||||||
| 165 | - | |||||||||||||
| 166 | inline uint SparseArray::pop_front() | - | ||||||||||||
| 167 | { | - | ||||||||||||
| 168 | uint idx = | - | ||||||||||||
| 169 | (0x7fffffff * 2U + 1U) | - | ||||||||||||
| 170 | ; | - | ||||||||||||
| 171 | - | |||||||||||||
| 172 | SparseArrayNode *n = findNode(0); | - | ||||||||||||
| 173 | if (n
| 0 | ||||||||||||
| 174 | idx = n->value; | - | ||||||||||||
| 175 | deleteNode(n); | - | ||||||||||||
| 176 | - | |||||||||||||
| 177 | SparseArrayNode *n = root(); | - | ||||||||||||
| 178 | while (n
| 0 | ||||||||||||
| 179 | n->size_left -= 1; | - | ||||||||||||
| 180 | n = n->left; | - | ||||||||||||
| 181 | } never executed: end of block | 0 | ||||||||||||
| 182 | } never executed: end of block | 0 | ||||||||||||
| 183 | return never executed: idx;return idx;never executed: return idx; | 0 | ||||||||||||
| 184 | } | - | ||||||||||||
| 185 | - | |||||||||||||
| 186 | inline void SparseArray::push_front(uint value) | - | ||||||||||||
| 187 | { | - | ||||||||||||
| 188 | - | |||||||||||||
| 189 | SparseArrayNode *n = root(); | - | ||||||||||||
| 190 | while (n
| 0 | ||||||||||||
| 191 | n->size_left += 1; | - | ||||||||||||
| 192 | n = n->left; | - | ||||||||||||
| 193 | } never executed: end of block | 0 | ||||||||||||
| 194 | n = insert(0); | - | ||||||||||||
| 195 | n->value = value; | - | ||||||||||||
| 196 | } never executed: end of block | 0 | ||||||||||||
| 197 | - | |||||||||||||
| 198 | inline uint SparseArray::pop_back(uint len) | - | ||||||||||||
| 199 | { | - | ||||||||||||
| 200 | uint idx = | - | ||||||||||||
| 201 | (0x7fffffff * 2U + 1U) | - | ||||||||||||
| 202 | ; | - | ||||||||||||
| 203 | if (!len
| 0 | ||||||||||||
| 204 | return never executed: idx;return idx;never executed: return idx; | 0 | ||||||||||||
| 205 | - | |||||||||||||
| 206 | SparseArrayNode *n = findNode(len - 1); | - | ||||||||||||
| 207 | if (n
| 0 | ||||||||||||
| 208 | idx = n->value; | - | ||||||||||||
| 209 | deleteNode(n); | - | ||||||||||||
| 210 | } never executed: end of block | 0 | ||||||||||||
| 211 | return never executed: idx;return idx;never executed: return idx; | 0 | ||||||||||||
| 212 | } | - | ||||||||||||
| 213 | - | |||||||||||||
| 214 | inline void SparseArray::push_back(uint index, uint len) | - | ||||||||||||
| 215 | { | - | ||||||||||||
| 216 | SparseArrayNode *n = insert(len); | - | ||||||||||||
| 217 | n->value = index; | - | ||||||||||||
| 218 | } never executed: end of block | 0 | ||||||||||||
| 219 | inline SparseArrayNode *SparseArray::erase(SparseArrayNode *n) | - | ||||||||||||
| 220 | { | - | ||||||||||||
| 221 | if (n == end()
| 0-600 | ||||||||||||
| 222 | return never executed: n;return n;never executed: return n; | 0 | ||||||||||||
| 223 | - | |||||||||||||
| 224 | SparseArrayNode *next = n->nextNode(); | - | ||||||||||||
| 225 | deleteNode(n); | - | ||||||||||||
| 226 | return executed 599 times by 2 tests: next;return next;Executed by:
executed 599 times by 2 tests: return next;Executed by:
| 599 | ||||||||||||
| 227 | } | - | ||||||||||||
| 228 | - | |||||||||||||
| 229 | inline QList<int> SparseArray::keys() const | - | ||||||||||||
| 230 | { | - | ||||||||||||
| 231 | QList<int> res; | - | ||||||||||||
| 232 | res.reserve(numEntries); | - | ||||||||||||
| 233 | SparseArrayNode *n = mostLeftNode; | - | ||||||||||||
| 234 | while (n != end()
| 0 | ||||||||||||
| 235 | res.append(n->key()); | - | ||||||||||||
| 236 | n = n->nextNode(); | - | ||||||||||||
| 237 | } never executed: end of block | 0 | ||||||||||||
| 238 | return never executed: res;return res;never executed: return res; | 0 | ||||||||||||
| 239 | } | - | ||||||||||||
| 240 | - | |||||||||||||
| 241 | inline const SparseArrayNode *SparseArray::lowerBound(uint akey) const | - | ||||||||||||
| 242 | { | - | ||||||||||||
| 243 | const SparseArrayNode *lb = root()->lowerBound(akey); | - | ||||||||||||
| 244 | if (!lb
| 0 | ||||||||||||
| 245 | lb = end(); never executed: lb = end(); | 0 | ||||||||||||
| 246 | return never executed: lb;return lb;never executed: return lb; | 0 | ||||||||||||
| 247 | } | - | ||||||||||||
| 248 | - | |||||||||||||
| 249 | - | |||||||||||||
| 250 | inline SparseArrayNode *SparseArray::lowerBound(uint akey) | - | ||||||||||||
| 251 | { | - | ||||||||||||
| 252 | SparseArrayNode *lb = root()->lowerBound(akey); | - | ||||||||||||
| 253 | if (!lb
| 0-158 | ||||||||||||
| 254 | lb = end(); never executed: lb = end(); | 0 | ||||||||||||
| 255 | return executed 158 times by 1 test: lb;return lb;Executed by:
executed 158 times by 1 test: return lb;Executed by:
| 158 | ||||||||||||
| 256 | } | - | ||||||||||||
| 257 | - | |||||||||||||
| 258 | - | |||||||||||||
| 259 | inline const SparseArrayNode *SparseArray::upperBound(uint akey) const | - | ||||||||||||
| 260 | { | - | ||||||||||||
| 261 | const SparseArrayNode *ub = root()->upperBound(akey); | - | ||||||||||||
| 262 | if (!ub
| 0 | ||||||||||||
| 263 | ub = end(); never executed: ub = end(); | 0 | ||||||||||||
| 264 | return never executed: ub;return ub;never executed: return ub; | 0 | ||||||||||||
| 265 | } | - | ||||||||||||
| 266 | - | |||||||||||||
| 267 | - | |||||||||||||
| 268 | inline SparseArrayNode *SparseArray::upperBound(uint akey) | - | ||||||||||||
| 269 | { | - | ||||||||||||
| 270 | SparseArrayNode *ub = root()->upperBound(akey); | - | ||||||||||||
| 271 | if (!ub
| 0 | ||||||||||||
| 272 | ub = end(); never executed: ub = end(); | 0 | ||||||||||||
| 273 | return never executed: ub;return ub;never executed: return ub; | 0 | ||||||||||||
| 274 | } | - | ||||||||||||
| 275 | - | |||||||||||||
| 276 | } | - | ||||||||||||
| 277 | - | |||||||||||||
| 278 | - | |||||||||||||
| Switch to Source code | Preprocessed file |