if (root & 1) {
typename Details::FlatTree* flatTree = (typename Details::FlatTree*) (root & ~ureg(1));
for (;;) {
- ureg leafIdx = (hash >> flatTree->safeShift);
+ ureg leafIdx = ureg(hash >> flatTree->safeShift);
table = flatTree->getTables()[leafIdx].load(turf::Relaxed);
if (ureg(table) != Details::RedirectFlatTree) {
sizeMask = (Details::LeafSize - 1);
// Retry the loop.
} else {
ureg repeat = ureg(1) << (migration->m_safeShift - flatTree->safeShift);
- ureg dstStartIndex = migration->m_baseHash >> flatTree->safeShift;
+ ureg dstStartIndex = ureg(migration->m_baseHash >> flatTree->safeShift);
// The subtree we're about to publish fits inside the flattree.
TURF_ASSERT(dstStartIndex + migration->m_numDestinations * repeat - 1 <= Hash(-1) >> flatTree->safeShift);
// If a previous attempt to publish got redirected, resume publishing into the new flattree,
turf::Atomic<typename Details::Table*> m_root;
public:
- ConcurrentMap_LeapFrog(ureg capacity) : m_root(Details::Table::create(capacity)) {
+ ConcurrentMap_LeapFrog(ureg capacity = Details::InitialSize) : m_root(Details::Table::create(capacity)) {
}
~ConcurrentMap_LeapFrog() {
turf::Atomic<typename Details::Table*> m_root;
public:
- ConcurrentMap_Linear(ureg capacity) {
+ ConcurrentMap_Linear(ureg capacity = Details::InitialSize) {
ureg limitNumValues = capacity * 3 / 4;
m_root.storeNonatomic(Details::Table::create(capacity, limitNumValues));
}
: sizeMask(sizeMask), baseHash(baseHash), unsafeRangeShift(unsafeRangeShift) {
}
- static Table* create(ureg tableSize, ureg baseHash, ureg unsafeShift) {
+ static Table* create(ureg tableSize, Hash baseHash, ureg unsafeShift) {
TURF_ASSERT(turf::util::isPowerOf2(tableSize));
TURF_ASSERT(unsafeShift > 0 && unsafeShift <= sizeof(Hash) * 8);
TURF_ASSERT(tableSize >= 4);
TURF_TRACE(Grampa, 3, "[insert] called", uptr(table), hash);
TURF_ASSERT(table);
TURF_ASSERT(hash != KeyTraits::NullHash);
- ureg idx = hash;
+ ureg idx = ureg(hash);
// Check hashed cell first, though it may not even belong to the bucket.
CellGroup* group = table->getCellGroups() + ((idx & sizeMask) >> 2);
TURF_ASSERT(table);
TURF_ASSERT(hash != KeyTraits::NullHash);
ureg sizeMask = table->sizeMask;
- ureg idx = hash;
+ ureg idx = ureg(hash);
// Check hashed cell first, though it may not even belong to the bucket.
CellGroup* group = table->getCellGroups() + ((idx & sizeMask) >> 2);
TURF_ASSERT(table);
TURF_ASSERT(hash != KeyTraits::NullHash);
ureg sizeMask = table->sizeMask;
- for (ureg idx = hash;; idx++) {
+ for (ureg idx = ureg(hash);; idx++) {
idx &= sizeMask;
Cell* cell = table->getCells() + idx;
// Load the hash that was there.
- uptr probeHash = cell->hash.load(turf::Relaxed);
+ Hash probeHash = cell->hash.load(turf::Relaxed);
if (probeHash == hash) {
TURF_TRACE(Linear, 1, "[find] found existing cell", uptr(table), idx);
return cell;
TURF_ASSERT(hash != KeyTraits::NullHash);
ureg sizeMask = table->sizeMask;
- for (ureg idx = hash;; idx++) {
+ for (ureg idx = ureg(hash);; idx++) {
idx &= sizeMask;
cell = table->getCells() + idx;
// Load the existing hash.
- uptr probeHash = cell->hash.load(turf::Relaxed);
+ Hash probeHash = cell->hash.load(turf::Relaxed);
if (probeHash == hash) {
TURF_TRACE(Linear, 3, "[insert] found existing cell", uptr(table), idx);
return InsertResult_AlreadyFound; // Key found in table. Return the existing cell.
return InsertResult_Overflow;
}
// Try to reserve this cell.
- uptr prevHash = cell->hash.compareExchange(KeyTraits::NullHash, hash, turf::Relaxed);
+ Hash prevHash = cell->hash.compareExchange(KeyTraits::NullHash, hash, turf::Relaxed);
if (prevHash == KeyTraits::NullHash) {
// Success. We reserved a new cell.
TURF_TRACE(Linear, 5, "[insert] reserved cell", prevCellsRemaining, idx);