| 1 |
/* |
| 2 |
* Copyright (C) 2013-2015, 2019 by the Konclude Developer Team. |
| 3 |
* |
| 4 |
* This file is part of the reasoning system Konclude. |
| 5 |
* For details and support, see <http://konclude.com/>. |
| 6 |
* |
| 7 |
* Konclude is free software: you can redistribute it and/or modify |
| 8 |
* it under the terms of version 3 of the GNU Lesser General Public |
| 9 |
* License (LGPLv3) as published by the Free Software Foundation. |
| 10 |
* |
| 11 |
* Konclude is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU (Lesser) General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU (Lesser) General Public |
| 17 |
* License along with Konclude. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
* This file incorporates work covered by the following copyright and |
| 20 |
* permission notice (to be compatible with LGPLv2.1, |
| 21 |
* this code is available/released under GPLv3, |
| 22 |
* see https://www.gnu.org/licenses/gpl-faq.html#AllCompatibility): |
| 23 |
* |
| 24 |
* |
| 25 |
* Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). |
| 26 |
* Contact: http://www.qt-project.org/legal |
| 27 |
* |
| 28 |
* This file is part of the QtCore module of the Qt Toolkit. |
| 29 |
* |
| 30 |
* $QT_BEGIN_LICENSE:LGPL$ |
| 31 |
* Commercial License Usage |
| 32 |
* Licensees holding valid commercial Qt licenses may use this file in |
| 33 |
* accordance with the commercial license agreement provided with the |
| 34 |
* Software or, alternatively, in accordance with the terms contained in |
| 35 |
* a written agreement between you and Digia. For licensing terms and |
| 36 |
* conditions see http://qt.digia.com/licensing. For further information |
| 37 |
* use the contact form at http://qt.digia.com/contact-us. |
| 38 |
* |
| 39 |
* GNU Lesser General Public License Usage |
| 40 |
* Alternatively, this file may be used under the terms of the GNU Lesser |
| 41 |
* General Public License version 2.1 as published by the Free Software |
| 42 |
* Foundation and appearing in the file LICENSE.LGPL included in the |
| 43 |
* packaging of this file. Please review the following information to |
| 44 |
* ensure the GNU Lesser General Public License version 2.1 requirements |
| 45 |
* will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 46 |
* |
| 47 |
* In addition, as a special exception, Digia gives you certain additional |
| 48 |
* rights. These rights are described in the Digia Qt LGPL Exception |
| 49 |
* version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 50 |
* |
| 51 |
* GNU General Public License Usage |
| 52 |
* Alternatively, this file may be used under the terms of the GNU |
| 53 |
* General Public License version 3.0 as published by the Free Software |
| 54 |
* Foundation and appearing in the file LICENSE.GPL included in the |
| 55 |
* packaging of this file. Please review the following information to |
| 56 |
* ensure the GNU General Public License version 3.0 requirements will be |
| 57 |
* met: http://www.gnu.org/copyleft/gpl.html. |
| 58 |
* |
| 59 |
* |
| 60 |
* $QT_END_LICENSE$ |
| 61 |
* |
| 62 |
* |
| 63 |
*/ |
| 64 |
|
| 65 |
#ifndef KONCLUDE_UTILITIES_CONTAINER_CQTMANAGEDRESTRICTEDMODIFICATIONHASH_CPP |
| 66 |
#define KONCLUDE_UTILITIES_CONTAINER_CQTMANAGEDRESTRICTEDMODIFICATIONHASH_CPP |
| 67 |
|
| 68 |
|
| 69 |
#include "CQtManagedRestrictedModificationHash.h" |
| 70 |
|
| 71 |
|
| 72 |
namespace Konclude { |
| 73 |
|
| 74 |
namespace Utilities { |
| 75 |
|
| 76 |
namespace Container { |
| 77 |
|
| 78 |
|
| 79 |
#ifdef KONCLUDE_EMPLOY_QT_MANAGED_RESTRICTED_MODIFICATION_HASH_CONTAINER |
| 80 |
|
| 81 |
|
| 82 |
template <class Key, class T> |
| 83 |
Q_INLINE_TEMPLATE void CQtManagedRestrictedModificationHash<Key, T>::deleteNode(Node *node) |
| 84 |
{ |
| 85 |
deleteNode2(reinterpret_cast<CQtManagedRestrictedModificationHashData::Node*>(node)); |
| 86 |
d->freeNode(node,mMemMan); |
| 87 |
} |
| 88 |
|
| 89 |
template <class Key, class T> |
| 90 |
Q_INLINE_TEMPLATE void CQtManagedRestrictedModificationHash<Key, T>::deleteNode2(CQtManagedRestrictedModificationHashData::Node *node) |
| 91 |
{ |
| 92 |
#ifdef Q_CC_BOR |
| 93 |
concrete(node)->~CQtManagedRestrictedModificationHashNode<Key, T>(); |
| 94 |
#elif defined(QT_NO_PARTIAL_TEMPLATE_SPECIALIZATION) |
| 95 |
concrete(node)->~CQtManagedRestrictedModificationHashNode(); |
| 96 |
#else |
| 97 |
concrete(node)->~Node(); |
| 98 |
#endif |
| 99 |
} |
| 100 |
|
| 101 |
template <class Key, class T> |
| 102 |
Q_INLINE_TEMPLATE void CQtManagedRestrictedModificationHash<Key, T>::duplicateNode(CQtManagedRestrictedModificationHashData::Node *node, void *newNode) |
| 103 |
{ |
| 104 |
Node *concreteNode = concrete(node); |
| 105 |
if (QTypeInfo<T>::isDummy) { |
| 106 |
(void) new (newNode) DummyNode(concreteNode->key); |
| 107 |
} else { |
| 108 |
(void) new (newNode) Node(concreteNode->key, concreteNode->value); |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
template <class Key, class T> |
| 114 |
Q_INLINE_TEMPLATE typename CQtManagedRestrictedModificationHash<Key, T>::Node * |
| 115 |
CQtManagedRestrictedModificationHash<Key, T>::createNode(uint ah, const Key &akey, const T &avalue, Node **anextNode) |
| 116 |
{ |
| 117 |
Node *node; |
| 118 |
|
| 119 |
if (QTypeInfo<T>::isDummy) { |
| 120 |
node = reinterpret_cast<Node *>(new (d->allocateNode(alignOfDummyNode(),mMemMan)) DummyNode(akey)); |
| 121 |
} else { |
| 122 |
node = new (d->allocateNode(alignOfNode(),mMemMan)) Node(akey, avalue); |
| 123 |
} |
| 124 |
|
| 125 |
node->h = ah; |
| 126 |
node->next = *anextNode; |
| 127 |
*anextNode = node; |
| 128 |
++d->size; |
| 129 |
return node; |
| 130 |
} |
| 131 |
|
| 132 |
template <class Key, class T> |
| 133 |
Q_INLINE_TEMPLATE CQtManagedRestrictedModificationHash<Key, T> &CQtManagedRestrictedModificationHash<Key, T>::unite(const CQtManagedRestrictedModificationHash<Key, T> &other) |
| 134 |
{ |
| 135 |
CQtManagedRestrictedModificationHash<Key, T> copy(other); |
| 136 |
const_iterator it = copy.constEnd(); |
| 137 |
while (it != copy.constBegin()) { |
| 138 |
--it; |
| 139 |
insertMulti(it.key(), it.value()); |
| 140 |
} |
| 141 |
return *this; |
| 142 |
} |
| 143 |
|
| 144 |
template <class Key, class T> |
| 145 |
Q_OUTOFLINE_TEMPLATE void CQtManagedRestrictedModificationHash<Key, T>::freeData(CQtManagedRestrictedModificationHashData *x) |
| 146 |
{ |
| 147 |
x->free_helper(deleteNode2,mMemMan); |
| 148 |
} |
| 149 |
|
| 150 |
template <class Key, class T> |
| 151 |
Q_INLINE_TEMPLATE void CQtManagedRestrictedModificationHash<Key, T>::clear() |
| 152 |
{ |
| 153 |
*this = CQtManagedRestrictedModificationHash<Key,T>(mContext); |
| 154 |
} |
| 155 |
|
| 156 |
template <class Key, class T> |
| 157 |
Q_OUTOFLINE_TEMPLATE void CQtManagedRestrictedModificationHash<Key, T>::detach_helper() |
| 158 |
{ |
| 159 |
CQtManagedRestrictedModificationHashData *x = d->detach_helper2(duplicateNode, deleteNode2, |
| 160 |
QTypeInfo<T>::isDummy ? sizeof(DummyNode) : sizeof(Node), |
| 161 |
QTypeInfo<T>::isDummy ? alignOfDummyNode() : alignOfNode(),this,mMemMan); |
| 162 |
//if (!d->ref.deref()) |
| 163 |
if (d->refHash == this) |
| 164 |
freeData(d); |
| 165 |
d = x; |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
template <class Key, class T> |
| 171 |
Q_INLINE_TEMPLATE bool CQtManagedRestrictedModificationHash<Key, T>::copyRestricted_helper(CQtManagedRestrictedModificationHashData::Node *node, void* assistValue) |
| 172 |
{ |
| 173 |
Node *concreteNode = concrete(node); |
| 174 |
return concreteNode->value.restrictedCopy(assistValue); |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
template <class Key, class T> |
| 179 |
Q_INLINE_TEMPLATE void CQtManagedRestrictedModificationHash<Key, T>::detach_helper_RestrictedCopy(void* assistValue) { |
| 180 |
CQtManagedRestrictedModificationHashData *x = d->restricted_detach_helper2(copyRestricted_helper,assistValue,duplicateNode, deleteNode2, |
| 181 |
QTypeInfo<T>::isDummy ? sizeof(DummyNode) : sizeof(Node), |
| 182 |
QTypeInfo<T>::isDummy ? alignOfDummyNode() : alignOfNode(),this,mMemMan); |
| 183 |
//if (!d->ref.deref()) |
| 184 |
if (d->refHash == this) |
| 185 |
freeData(d); |
| 186 |
d = x; |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
template <class Key, class T> |
| 192 |
Q_INLINE_TEMPLATE CQtManagedRestrictedModificationHash<Key, T> &CQtManagedRestrictedModificationHash<Key, T>::operator=(const CQtManagedRestrictedModificationHash<Key, T> &other) |
| 193 |
{ |
| 194 |
if (d != other.d) { |
| 195 |
//other.d->ref.ref(); |
| 196 |
//if (!d->ref.deref()) |
| 197 |
if (d->refHash == this) |
| 198 |
freeData(d); |
| 199 |
d = other.d; |
| 200 |
if (!d->sharable) |
| 201 |
detach_helper(); |
| 202 |
} |
| 203 |
return *this; |
| 204 |
} |
| 205 |
|
| 206 |
template <class Key, class T> |
| 207 |
Q_INLINE_TEMPLATE CQtManagedRestrictedModificationHash<Key, T>* CQtManagedRestrictedModificationHash<Key, T>::init(const CQtManagedRestrictedModificationHash<Key, T>& other, CContext* context) |
| 208 |
{ |
| 209 |
if (d != other.d) { |
| 210 |
if (d->refHash == this) |
| 211 |
freeData(d); |
| 212 |
mContext = context; |
| 213 |
mMemMan = CContext::getMemoryAllocationManager(mContext); |
| 214 |
d = other.d; |
| 215 |
if (!d->sharable) |
| 216 |
detach_helper(); |
| 217 |
} |
| 218 |
mContext = context; |
| 219 |
mMemMan = CContext::getMemoryAllocationManager(mContext); |
| 220 |
return this; |
| 221 |
} |
| 222 |
|
| 223 |
template <class Key, class T> |
| 224 |
Q_INLINE_TEMPLATE CQtManagedRestrictedModificationHash<Key, T>* CQtManagedRestrictedModificationHash<Key, T>::init(CContext* context) |
| 225 |
{ |
| 226 |
if (d->refHash == this) |
| 227 |
freeData(d); |
| 228 |
mContext = context; |
| 229 |
mMemMan = CContext::getMemoryAllocationManager(mContext); |
| 230 |
d = &CQtManagedRestrictedModificationHashData::shared_null; |
| 231 |
return this; |
| 232 |
} |
| 233 |
|
| 234 |
template <class Key, class T> |
| 235 |
Q_INLINE_TEMPLATE CQtManagedRestrictedModificationHash<Key, T>* CQtManagedRestrictedModificationHash<Key, T>::init(CQtManagedRestrictedModificationHash<Key, T>* other, CContext* context) |
| 236 |
{ |
| 237 |
if (other) { |
| 238 |
if (d != other->d) { |
| 239 |
if (d->refHash == this) |
| 240 |
freeData(d); |
| 241 |
mContext = context; |
| 242 |
mMemMan = CContext::getMemoryAllocationManager(mContext); |
| 243 |
if (other) { |
| 244 |
d = other->d; |
| 245 |
if (!d->sharable) |
| 246 |
detach_helper(); |
| 247 |
} |
| 248 |
} |
| 249 |
} else { |
| 250 |
if (d->refHash == this) |
| 251 |
freeData(d); |
| 252 |
d = &CQtManagedRestrictedModificationHashData::shared_null; |
| 253 |
} |
| 254 |
mContext = context; |
| 255 |
mMemMan = CContext::getMemoryAllocationManager(mContext); |
| 256 |
return this; |
| 257 |
} |
| 258 |
|
| 259 |
template <class Key, class T> |
| 260 |
Q_INLINE_TEMPLATE const T CQtManagedRestrictedModificationHash<Key, T>::value(const Key &akey) const |
| 261 |
{ |
| 262 |
Node *node; |
| 263 |
if (d->size == 0 || (node = *findNode(akey)) == e) { |
| 264 |
return T(); |
| 265 |
} else { |
| 266 |
return node->value; |
| 267 |
} |
| 268 |
} |
| 269 |
|
| 270 |
|
| 271 |
template <class Key, class T> |
| 272 |
Q_INLINE_TEMPLATE T* CQtManagedRestrictedModificationHash<Key, T>::valuePointer(const Key& akey) const { |
| 273 |
Node *node; |
| 274 |
if (d->size == 0 || (node = *findNode(akey)) == e) { |
| 275 |
return nullptr; |
| 276 |
} else { |
| 277 |
return &node->value; |
| 278 |
} |
| 279 |
} |
| 280 |
|
| 281 |
|
| 282 |
template <class Key, class T> |
| 283 |
Q_INLINE_TEMPLATE const T CQtManagedRestrictedModificationHash<Key, T>::value(const Key &akey, const T &adefaultValue) const |
| 284 |
{ |
| 285 |
Node *node; |
| 286 |
if (d->size == 0 || (node = *findNode(akey)) == e) { |
| 287 |
return adefaultValue; |
| 288 |
} else { |
| 289 |
return node->value; |
| 290 |
} |
| 291 |
} |
| 292 |
|
| 293 |
|
| 294 |
template <class Key, class T> |
| 295 |
Q_OUTOFLINE_TEMPLATE bool CQtManagedRestrictedModificationHash<Key, T>::tryGetValuePointer(const Key& akey, T*& valuePointer) const { |
| 296 |
Node *node; |
| 297 |
if (d->size == 0 || (node = *findNode(akey)) == e) { |
| 298 |
return false; |
| 299 |
} else { |
| 300 |
valuePointer = &node->value; |
| 301 |
return true; |
| 302 |
} |
| 303 |
} |
| 304 |
|
| 305 |
|
| 306 |
template <class Key, class T> |
| 307 |
Q_OUTOFLINE_TEMPLATE bool CQtManagedRestrictedModificationHash<Key, T>::tryGetValue(const Key& akey, T* value) const { |
| 308 |
Node *node; |
| 309 |
if (d->size == 0 || (node = *findNode(akey)) == e) { |
| 310 |
return false; |
| 311 |
} else { |
| 312 |
*value = node->value; |
| 313 |
return true; |
| 314 |
} |
| 315 |
} |
| 316 |
|
| 317 |
template <class Key, class T> |
| 318 |
Q_OUTOFLINE_TEMPLATE QList<Key> CQtManagedRestrictedModificationHash<Key, T>::uniqueKeys() const |
| 319 |
{ |
| 320 |
QList<Key> res; |
| 321 |
const_iterator i = begin(); |
| 322 |
if (i != end()) { |
| 323 |
for (;;) { |
| 324 |
const Key &aKey = i.key(); |
| 325 |
res.append(aKey); |
| 326 |
do { |
| 327 |
if (++i == end()) |
| 328 |
goto break_out_of_outer_loop; |
| 329 |
} while (aKey == i.key()); |
| 330 |
} |
| 331 |
} |
| 332 |
break_out_of_outer_loop: |
| 333 |
return res; |
| 334 |
} |
| 335 |
|
| 336 |
template <class Key, class T> |
| 337 |
Q_OUTOFLINE_TEMPLATE QList<Key> CQtManagedRestrictedModificationHash<Key, T>::keys() const |
| 338 |
{ |
| 339 |
QList<Key> res; |
| 340 |
const_iterator i = begin(); |
| 341 |
while (i != end()) { |
| 342 |
res.append(i.key()); |
| 343 |
++i; |
| 344 |
} |
| 345 |
return res; |
| 346 |
} |
| 347 |
|
| 348 |
template <class Key, class T> |
| 349 |
Q_OUTOFLINE_TEMPLATE QList<Key> CQtManagedRestrictedModificationHash<Key, T>::keys(const T &avalue) const |
| 350 |
{ |
| 351 |
QList<Key> res; |
| 352 |
const_iterator i = begin(); |
| 353 |
while (i != end()) { |
| 354 |
if (i.value() == avalue) |
| 355 |
res.append(i.key()); |
| 356 |
++i; |
| 357 |
} |
| 358 |
return res; |
| 359 |
} |
| 360 |
|
| 361 |
template <class Key, class T> |
| 362 |
Q_OUTOFLINE_TEMPLATE const Key CQtManagedRestrictedModificationHash<Key, T>::key(const T &avalue) const |
| 363 |
{ |
| 364 |
return key(avalue, Key()); |
| 365 |
} |
| 366 |
|
| 367 |
template <class Key, class T> |
| 368 |
Q_OUTOFLINE_TEMPLATE const Key CQtManagedRestrictedModificationHash<Key, T>::key(const T &avalue, const Key &defaultValue) const |
| 369 |
{ |
| 370 |
const_iterator i = begin(); |
| 371 |
while (i != end()) { |
| 372 |
if (i.value() == avalue) |
| 373 |
return i.key(); |
| 374 |
++i; |
| 375 |
} |
| 376 |
|
| 377 |
return defaultValue; |
| 378 |
} |
| 379 |
|
| 380 |
template <class Key, class T> |
| 381 |
Q_OUTOFLINE_TEMPLATE QList<T> CQtManagedRestrictedModificationHash<Key, T>::values() const |
| 382 |
{ |
| 383 |
QList<T> res; |
| 384 |
const_iterator i = begin(); |
| 385 |
while (i != end()) { |
| 386 |
res.append(i.value()); |
| 387 |
++i; |
| 388 |
} |
| 389 |
return res; |
| 390 |
} |
| 391 |
|
| 392 |
template <class Key, class T> |
| 393 |
Q_OUTOFLINE_TEMPLATE QList<T> CQtManagedRestrictedModificationHash<Key, T>::values(const Key &akey) const |
| 394 |
{ |
| 395 |
QList<T> res; |
| 396 |
Node *node = *findNode(akey); |
| 397 |
if (node != e) { |
| 398 |
do { |
| 399 |
res.append(node->value); |
| 400 |
} while ((node = node->next) != e && node->key == akey); |
| 401 |
} |
| 402 |
return res; |
| 403 |
} |
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
template <class Key, class T> |
| 408 |
Q_OUTOFLINE_TEMPLATE CQtManagedRestrictedModificationList<Key> CQtManagedRestrictedModificationHash<Key, T>::uniqueKeysInManagedRestrictedModificationList(CContext* context) const |
| 409 |
{ |
| 410 |
CQtManagedRestrictedModificationList<Key> res(context); |
| 411 |
const_iterator i = begin(); |
| 412 |
if (i != end()) { |
| 413 |
for (;;) { |
| 414 |
const Key &aKey = i.key(); |
| 415 |
res.append(aKey); |
| 416 |
do { |
| 417 |
if (++i == end()) |
| 418 |
goto break_out_of_outer_loop; |
| 419 |
} while (aKey == i.key()); |
| 420 |
} |
| 421 |
} |
| 422 |
break_out_of_outer_loop: |
| 423 |
return res; |
| 424 |
} |
| 425 |
|
| 426 |
template <class Key, class T> |
| 427 |
Q_OUTOFLINE_TEMPLATE CQtManagedRestrictedModificationList<Key> CQtManagedRestrictedModificationHash<Key, T>::keysInManagedRestrictedModificationList(CContext* context) const |
| 428 |
{ |
| 429 |
CQtManagedRestrictedModificationList<Key> res(context); |
| 430 |
const_iterator i = begin(); |
| 431 |
while (i != end()) { |
| 432 |
res.append(i.key()); |
| 433 |
++i; |
| 434 |
} |
| 435 |
return res; |
| 436 |
} |
| 437 |
|
| 438 |
template <class Key, class T> |
| 439 |
Q_OUTOFLINE_TEMPLATE CQtManagedRestrictedModificationList<Key> CQtManagedRestrictedModificationHash<Key, T>::keysInManagedRestrictedModificationList(const T &avalue, CContext* context) const |
| 440 |
{ |
| 441 |
CQtManagedRestrictedModificationList<Key> res(context); |
| 442 |
const_iterator i = begin(); |
| 443 |
while (i != end()) { |
| 444 |
if (i.value() == avalue) |
| 445 |
res.append(i.key()); |
| 446 |
++i; |
| 447 |
} |
| 448 |
return res; |
| 449 |
} |
| 450 |
|
| 451 |
|
| 452 |
template <class Key, class T> |
| 453 |
Q_OUTOFLINE_TEMPLATE CQtManagedRestrictedModificationList<T> CQtManagedRestrictedModificationHash<Key, T>::valuesInManagedRestrictedModificationList(CContext* context) const |
| 454 |
{ |
| 455 |
CQtManagedRestrictedModificationList<T> res(context); |
| 456 |
const_iterator i = begin(); |
| 457 |
while (i != end()) { |
| 458 |
res.append(i.value()); |
| 459 |
++i; |
| 460 |
} |
| 461 |
return res; |
| 462 |
} |
| 463 |
|
| 464 |
template <class Key, class T> |
| 465 |
Q_OUTOFLINE_TEMPLATE CQtManagedRestrictedModificationList<T> CQtManagedRestrictedModificationHash<Key, T>::valuesInManagedRestrictedModificationList(const Key &akey, CContext* context) const |
| 466 |
{ |
| 467 |
CQtManagedRestrictedModificationList<T> res(context); |
| 468 |
Node *node = *findNode(akey); |
| 469 |
if (node != e) { |
| 470 |
do { |
| 471 |
res.append(node->value); |
| 472 |
} while ((node = node->next) != e && node->key == akey); |
| 473 |
} |
| 474 |
return res; |
| 475 |
} |
| 476 |
|
| 477 |
|
| 478 |
template <class Key, class T> |
| 479 |
Q_OUTOFLINE_TEMPLATE int CQtManagedRestrictedModificationHash<Key, T>::count(const Key &akey) const |
| 480 |
{ |
| 481 |
int cnt = 0; |
| 482 |
Node *node = *findNode(akey); |
| 483 |
if (node != e) { |
| 484 |
do { |
| 485 |
++cnt; |
| 486 |
} while ((node = node->next) != e && node->key == akey); |
| 487 |
} |
| 488 |
return cnt; |
| 489 |
} |
| 490 |
|
| 491 |
template <class Key, class T> |
| 492 |
Q_INLINE_TEMPLATE const T CQtManagedRestrictedModificationHash<Key, T>::operator[](const Key &akey) const |
| 493 |
{ |
| 494 |
return value(akey); |
| 495 |
} |
| 496 |
|
| 497 |
template <class Key, class T> |
| 498 |
Q_INLINE_TEMPLATE T &CQtManagedRestrictedModificationHash<Key, T>::operator[](const Key &akey) |
| 499 |
{ |
| 500 |
detach(); |
| 501 |
|
| 502 |
uint h; |
| 503 |
Node **node = findNode(akey, &h); |
| 504 |
if (*node == e) { |
| 505 |
if (d->willGrow(mMemMan)) |
| 506 |
node = findNode(akey, &h); |
| 507 |
return createNode(h, akey, T(), node)->value; |
| 508 |
} |
| 509 |
return (*node)->value; |
| 510 |
} |
| 511 |
|
| 512 |
template <class Key, class T> |
| 513 |
Q_INLINE_TEMPLATE typename CQtManagedRestrictedModificationHash<Key, T>::iterator CQtManagedRestrictedModificationHash<Key, T>::insert(const Key &akey, |
| 514 |
const T &avalue) |
| 515 |
{ |
| 516 |
detach(); |
| 517 |
|
| 518 |
uint h; |
| 519 |
Node **node = findNode(akey, &h); |
| 520 |
if (*node == e) { |
| 521 |
if (d->willGrow(mMemMan)) |
| 522 |
node = findNode(akey, &h); |
| 523 |
return iterator(createNode(h, akey, avalue, node)); |
| 524 |
} |
| 525 |
|
| 526 |
if (!QTypeInfo<T>::isDummy) |
| 527 |
(*node)->value = avalue; |
| 528 |
return iterator(*node); |
| 529 |
} |
| 530 |
|
| 531 |
template <class Key, class T> |
| 532 |
Q_INLINE_TEMPLATE typename CQtManagedRestrictedModificationHash<Key, T>::iterator CQtManagedRestrictedModificationHash<Key, T>::insertMulti(const Key &akey, |
| 533 |
const T &avalue) |
| 534 |
{ |
| 535 |
detach(); |
| 536 |
d->willGrow(mMemMan); |
| 537 |
|
| 538 |
uint h; |
| 539 |
Node **nextNode = findNode(akey, &h); |
| 540 |
return iterator(createNode(h, akey, avalue, nextNode)); |
| 541 |
} |
| 542 |
|
| 543 |
template <class Key, class T> |
| 544 |
Q_OUTOFLINE_TEMPLATE int CQtManagedRestrictedModificationHash<Key, T>::remove(const Key &akey) |
| 545 |
{ |
| 546 |
if (isEmpty()) // prevents detaching shared null |
| 547 |
return 0; |
| 548 |
detach(); |
| 549 |
|
| 550 |
int oldSize = d->size; |
| 551 |
Node **node = findNode(akey); |
| 552 |
if (*node != e) { |
| 553 |
bool deleteNext = true; |
| 554 |
do { |
| 555 |
Node *next = (*node)->next; |
| 556 |
deleteNext = (next != e && next->key == (*node)->key); |
| 557 |
deleteNode(*node); |
| 558 |
*node = next; |
| 559 |
--d->size; |
| 560 |
} while (deleteNext); |
| 561 |
d->hasShrunk(mMemMan); |
| 562 |
} |
| 563 |
return oldSize - d->size; |
| 564 |
} |
| 565 |
|
| 566 |
template <class Key, class T> |
| 567 |
Q_OUTOFLINE_TEMPLATE T CQtManagedRestrictedModificationHash<Key, T>::take(const Key &akey) |
| 568 |
{ |
| 569 |
if (isEmpty()) // prevents detaching shared null |
| 570 |
return T(); |
| 571 |
detach(); |
| 572 |
|
| 573 |
Node **node = findNode(akey); |
| 574 |
if (*node != e) { |
| 575 |
T t = (*node)->value; |
| 576 |
Node *next = (*node)->next; |
| 577 |
deleteNode(*node); |
| 578 |
*node = next; |
| 579 |
--d->size; |
| 580 |
d->hasShrunk(mMemMan); |
| 581 |
return t; |
| 582 |
} |
| 583 |
return T(); |
| 584 |
} |
| 585 |
|
| 586 |
template <class Key, class T> |
| 587 |
Q_OUTOFLINE_TEMPLATE typename CQtManagedRestrictedModificationHash<Key, T>::iterator CQtManagedRestrictedModificationHash<Key, T>::erase(iterator it) |
| 588 |
{ |
| 589 |
if (it == iterator(e)) |
| 590 |
return it; |
| 591 |
|
| 592 |
iterator ret = it; |
| 593 |
++ret; |
| 594 |
|
| 595 |
Node *node = it; |
| 596 |
Node **node_ptr = reinterpret_cast<Node **>(&d->buckets[node->h % d->numBuckets]); |
| 597 |
while (*node_ptr != node) |
| 598 |
node_ptr = &(*node_ptr)->next; |
| 599 |
*node_ptr = node->next; |
| 600 |
deleteNode(node); |
| 601 |
--d->size; |
| 602 |
return ret; |
| 603 |
} |
| 604 |
|
| 605 |
template <class Key, class T> |
| 606 |
Q_INLINE_TEMPLATE void CQtManagedRestrictedModificationHash<Key, T>::reserve(int asize) |
| 607 |
{ |
| 608 |
detach(); |
| 609 |
d->rehash(-qMax(asize, 1),mMemMan); |
| 610 |
} |
| 611 |
|
| 612 |
template <class Key, class T> |
| 613 |
Q_INLINE_TEMPLATE typename CQtManagedRestrictedModificationHash<Key, T>::const_iterator CQtManagedRestrictedModificationHash<Key, T>::find(const Key &akey) const |
| 614 |
{ |
| 615 |
return const_iterator(*findNode(akey)); |
| 616 |
} |
| 617 |
|
| 618 |
template <class Key, class T> |
| 619 |
Q_INLINE_TEMPLATE typename CQtManagedRestrictedModificationHash<Key, T>::const_iterator CQtManagedRestrictedModificationHash<Key, T>::constFind(const Key &akey) const |
| 620 |
{ |
| 621 |
return const_iterator(*findNode(akey)); |
| 622 |
} |
| 623 |
|
| 624 |
template <class Key, class T> |
| 625 |
Q_INLINE_TEMPLATE typename CQtManagedRestrictedModificationHash<Key, T>::iterator CQtManagedRestrictedModificationHash<Key, T>::find(const Key &akey) |
| 626 |
{ |
| 627 |
detach(); |
| 628 |
return iterator(*findNode(akey)); |
| 629 |
} |
| 630 |
|
| 631 |
template <class Key, class T> |
| 632 |
Q_INLINE_TEMPLATE bool CQtManagedRestrictedModificationHash<Key, T>::contains(const Key &akey) const |
| 633 |
{ |
| 634 |
return *findNode(akey) != e; |
| 635 |
} |
| 636 |
|
| 637 |
template <class Key, class T> |
| 638 |
Q_OUTOFLINE_TEMPLATE typename CQtManagedRestrictedModificationHash<Key, T>::Node **CQtManagedRestrictedModificationHash<Key, T>::findNode(const Key &akey, |
| 639 |
uint *ahp) const |
| 640 |
{ |
| 641 |
Node **node; |
| 642 |
uint h = qHash(akey); |
| 643 |
|
| 644 |
if (d->numBuckets) { |
| 645 |
node = reinterpret_cast<Node **>(&d->buckets[h % d->numBuckets]); |
| 646 |
Q_ASSERT(*node == e || (*node)->next); |
| 647 |
while (*node != e && !(*node)->same_key(h, akey)) |
| 648 |
node = &(*node)->next; |
| 649 |
} else { |
| 650 |
node = const_cast<Node **>(reinterpret_cast<const Node * const *>(&e)); |
| 651 |
} |
| 652 |
if (ahp) |
| 653 |
*ahp = h; |
| 654 |
return node; |
| 655 |
} |
| 656 |
|
| 657 |
template <class Key, class T> |
| 658 |
Q_OUTOFLINE_TEMPLATE bool CQtManagedRestrictedModificationHash<Key, T>::operator==(const CQtManagedRestrictedModificationHash<Key, T> &other) const |
| 659 |
{ |
| 660 |
if (size() != other.size()) |
| 661 |
return false; |
| 662 |
if (d == other.d) |
| 663 |
return true; |
| 664 |
|
| 665 |
const_iterator it = begin(); |
| 666 |
|
| 667 |
while (it != end()) { |
| 668 |
const Key &akey = it.key(); |
| 669 |
|
| 670 |
const_iterator it2 = other.find(akey); |
| 671 |
do { |
| 672 |
if (it2 == other.end() || !(it2.key() == akey)) |
| 673 |
return false; |
| 674 |
if (!QTypeInfo<T>::isDummy && !(it.value() == it2.value())) |
| 675 |
return false; |
| 676 |
++it; |
| 677 |
++it2; |
| 678 |
} while (it != end() && it.key() == akey); |
| 679 |
} |
| 680 |
return true; |
| 681 |
} |
| 682 |
|
| 683 |
|
| 684 |
#endif // KONCLUDE_EMPLOY_QT_MANAGED_RESTRICTED_MODIFICATION_HASH_CONTAINER |
| 685 |
|
| 686 |
|
| 687 |
}; // end namespace Container |
| 688 |
|
| 689 |
}; // end namespace Utilities |
| 690 |
|
| 691 |
}; // end namespace Konclude |
| 692 |
|
| 693 |
#endif // KONCLUDE_UTILITIES_CONTAINER_CQTMANAGEDRESTRICTEDMODIFICATIONHASH_CPP |
| 694 |
|