mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-23 21:52:13 +00:00
Refactored last two commits so that all of the real code is in GSIMap.h and is just called from the relevant classes, rather than copied and pasted everywhere. Also added fast enumeration support to GSCountedSet.
I think that's all of the classes that use GSIMaps for their implementation now fully supporting fast enumeration. If there are any that I've missed, then just copy the methods from GSSet to implement them. You just need to set the mutations pointer to something sensible (i.e. something that will change if the collection mutates) and then call the new GSIMapCountByEnumeratingWithStateObjectsCount() function. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@29181 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
9e003700b4
commit
c5103403f6
5 changed files with 97 additions and 201 deletions
|
@ -50,6 +50,8 @@ static GC_descr nodeDesc; // Type descriptor for map node.
|
|||
{
|
||||
@public
|
||||
GSIMapTable_t map;
|
||||
@private
|
||||
NSUInteger _version;
|
||||
}
|
||||
@end
|
||||
|
||||
|
@ -127,6 +129,7 @@ static GC_descr nodeDesc; // Type descriptor for map node.
|
|||
format: @"Tried to nil value to counted set"];
|
||||
}
|
||||
|
||||
_version++;
|
||||
node = GSIMapNodeForKey(&map, (GSIMapKey)anObject);
|
||||
if (node == 0)
|
||||
{
|
||||
|
@ -136,6 +139,7 @@ static GC_descr nodeDesc; // Type descriptor for map node.
|
|||
{
|
||||
node->value.uint++;
|
||||
}
|
||||
_version++;
|
||||
}
|
||||
|
||||
- (unsigned) count
|
||||
|
@ -296,8 +300,10 @@ static GC_descr nodeDesc; // Type descriptor for map node.
|
|||
{
|
||||
if (node->value.uint <= (unsigned int)level)
|
||||
{
|
||||
_version++;
|
||||
GSIMapRemoveNodeFromMap(&map, bucket, node);
|
||||
GSIMapFreeNode(&map, node);
|
||||
_version++;
|
||||
}
|
||||
bucket = GSIMapEnumeratorBucket(&enumerator);
|
||||
node = GSIMapEnumeratorNextNode(&enumerator);
|
||||
|
@ -308,7 +314,9 @@ static GC_descr nodeDesc; // Type descriptor for map node.
|
|||
|
||||
- (void) removeAllObjects
|
||||
{
|
||||
_version++;
|
||||
GSIMapCleanMap(&map);
|
||||
_version++;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -326,6 +334,7 @@ static GC_descr nodeDesc; // Type descriptor for map node.
|
|||
NSWarnMLog(@"attempt to remove nil object");
|
||||
return;
|
||||
}
|
||||
_version++;
|
||||
bucket = GSIMapBucketForKey(&map, (GSIMapKey)anObject);
|
||||
if (bucket != 0)
|
||||
{
|
||||
|
@ -341,12 +350,14 @@ static GC_descr nodeDesc; // Type descriptor for map node.
|
|||
}
|
||||
}
|
||||
}
|
||||
_version++;
|
||||
}
|
||||
|
||||
- (id) unique: (id)anObject
|
||||
{
|
||||
GSIMapNode node;
|
||||
id result;
|
||||
_version++;
|
||||
|
||||
if (anObject == nil)
|
||||
{
|
||||
|
@ -372,6 +383,14 @@ static GC_descr nodeDesc; // Type descriptor for map node.
|
|||
}
|
||||
#endif
|
||||
}
|
||||
_version++;
|
||||
return result;
|
||||
}
|
||||
- (NSUInteger) countByEnumeratingWithState: (NSFastEnumerationState*)state
|
||||
objects: (id*)stackbuf
|
||||
count: (NSUInteger)len
|
||||
{
|
||||
state->mutationsPtr = (unsigned long *)&_version;
|
||||
return GSIMapCountByEnumeratingWithStateObjectsCount(&map, state, stackbuf, len);
|
||||
}
|
||||
@end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue