1
2
3
4
5
6
7
8
9
|
/*
* Copyright (c) 2008-2023 Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
|
|
|
1
2
3
4
5
6
7
8
9
|
/*
* Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
|
︙ | | | ︙ | |
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#import "OFMapTable+Private.h"
#import "OFEnumerator.h"
#import "OFEnumerationMutationException.h"
#import "OFInvalidArgumentException.h"
#import "OFOutOfRangeException.h"
extern uint32_t OFHashSeed;
static const uint32_t minCapacity = 16;
struct OFMapTableBucket {
void *key, *object;
uint32_t hash;
};
|
|
|
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#import "OFMapTable+Private.h"
#import "OFEnumerator.h"
#import "OFEnumerationMutationException.h"
#import "OFInvalidArgumentException.h"
#import "OFOutOfRangeException.h"
extern unsigned long OFHashSeed;
static const uint32_t minCapacity = 16;
struct OFMapTableBucket {
void *key, *object;
uint32_t hash;
};
|
︙ | | | ︙ | |
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
|
for (i = rotatedHash & (_capacity - 1);
i < last && _buckets[i] != NULL; i++) {
if (_buckets[i] == &deletedBucket)
continue;
if (_keyFunctions.equal(_buckets[i]->key, key)) {
_mutations++;
_keyFunctions.release(_buckets[i]->key);
_objectFunctions.release(_buckets[i]->object);
OFFreeMemory(_buckets[i]);
_buckets[i] = &deletedBucket;
_count--;
resizeForCount(self, _count);
return;
}
}
if (i < last)
|
<
<
>
|
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
|
for (i = rotatedHash & (_capacity - 1);
i < last && _buckets[i] != NULL; i++) {
if (_buckets[i] == &deletedBucket)
continue;
if (_keyFunctions.equal(_buckets[i]->key, key)) {
_keyFunctions.release(_buckets[i]->key);
_objectFunctions.release(_buckets[i]->object);
OFFreeMemory(_buckets[i]);
_buckets[i] = &deletedBucket;
_count--;
_mutations++;
resizeForCount(self, _count);
return;
}
}
if (i < last)
|
︙ | | | ︙ | |
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
|
#ifdef OF_HAVE_BLOCKS
- (void)enumerateKeysAndObjectsUsingBlock: (OFMapTableEnumerationBlock)block
{
bool stop = false;
unsigned long mutations = _mutations;
for (size_t i = 0; i < _capacity && !stop; i++) {
if (_mutations != mutations)
@throw [OFEnumerationMutationException
exceptionWithObject: self];
if (_buckets[i] != NULL && _buckets[i] != &deletedBucket)
block(_buckets[i]->key, _buckets[i]->object, &stop);
}
}
- (void)replaceObjectsUsingBlock: (OFMapTableReplaceBlock)block
{
unsigned long mutations = _mutations;
|
>
>
>
<
<
<
|
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
|
#ifdef OF_HAVE_BLOCKS
- (void)enumerateKeysAndObjectsUsingBlock: (OFMapTableEnumerationBlock)block
{
bool stop = false;
unsigned long mutations = _mutations;
for (size_t i = 0; i < _capacity && !stop; i++) {
if (_buckets[i] != NULL && _buckets[i] != &deletedBucket)
block(_buckets[i]->key, _buckets[i]->object, &stop);
if (_mutations != mutations)
@throw [OFEnumerationMutationException
exceptionWithObject: self];
}
}
- (void)replaceObjectsUsingBlock: (OFMapTableReplaceBlock)block
{
unsigned long mutations = _mutations;
|
︙ | | | ︙ | |