Implement +addObjectsFromArray: on NSHashTable

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@38802 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
thebeing 2015-07-16 07:38:14 +00:00
parent a8132a27d5
commit 5c53c77757
6 changed files with 124 additions and 0 deletions

View file

@ -1,3 +1,12 @@
2015-07-16 Niels Grewe <niels.grewe@halbordnung.de>
* Headers/GNUstepBase/NSHashTable+GNUstepBase.h
* Source/Additions/GNUmakefile
* Source/Additions/NSHashTable+GNUstepBase.m
* Source/GNUmakefile
* Tests/base/NSHashTable/additions.m:
Implement -addObjectsFromArray: on NSHashTable.
2015-07-15 Richard Frith-Macdonald <rfm@gnu.org>
* Headers/GNUstepBase/GSIMap.h:

View file

@ -0,0 +1,53 @@
/** Declaration of extension methods for base additions
Copyright (C) 2015 Free Software Foundation, Inc.
Written by: Niels Grewe <niels.grewe@halbordnung.de>
This file is part of the GNUstep Base Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#ifndef INCLUDED_NSHashTable_GNUstepBase_h
#define INCLUDED_NSHashTable_GNUstepBase_h
#import <GNUstepBase/GSVersionMacros.h>
#import <Foundation/NSHashTable.h>
#if defined(__cplusplus)
extern "C" {
#endif
#if OS_API_VERSION(GS_API_NONE,GS_API_LATEST)
@interface NSHashTable (GNUstepBase)
/**
* Adds each object contained in the given array that is not already
* in the hash table.
*/
- (void)addObjectsFromArray: (NSArray*)array;
@end
#endif /* OS_API_VERSION */
#if defined(__cplusplus)
}
#endif
#endif /* INCLUDED_NSHashTable_GNUstepBase_h */

View file

@ -51,6 +51,7 @@ Additions_OBJC_FILES =\
NSData+GNUstepBase.m \
NSDebug+GNUstepBase.m \
NSError+GNUstepBase.m \
NSHashTable+GNUstepBase.m \
NSFileHandle+GNUstepBase.m \
NSLock+GNUstepBase.m \
NSMutableString+GNUstepBase.m \

View file

@ -0,0 +1,39 @@
/* Implementation of extension methods to base additions
Copyright (C) 2015 Free Software Foundation, Inc.
Written by: Niels Grewe <niels.grewe@halbordnung.de>
This file is part of the GNUstep Base Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#import "common.h"
#import "Foundation/NSArray.h"
#import "GNUstepBase/NSHashTable+GNUstepBase.h"
#import "GSPrivate.h"
#import "GSFastEnumeration.h"
@implementation NSHashTable (GNUstepBase)
- (void)addObjectsFromArray: (NSArray*)array
{
FOR_IN(id, obj, array)
NSHashInsert(self,obj);
END_FOR_IN(array)
}
@end

View file

@ -132,6 +132,7 @@ NSCalendarDate+GNUstepBase.h \
NSData+GNUstepBase.h \
NSDebug+GNUstepBase.h \
NSFileHandle+GNUstepBase.h \
NSHashTable+GNUstepBase.h
NSLock+GNUstepBase.h \
NSMutableString+GNUstepBase.h \
NSNetServices+GNUstepBase.h \

View file

@ -0,0 +1,21 @@
#import "ObjectTesting.h"
#import <GNUstepBase/NSHashTable+GNUstepBase.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSAutoreleasePool.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSHashTable *obj = [[NSHashTable new] autorelease];
NSString *strA = @"a";
NSString *strB = @"b";
NSArray *a = [NSArray arrayWithObjects: strA, strB, strA, nil];
[obj addObjectsFromArray: a];
PASS([obj count] == 2, "-addObjectsFromArray: adds objects ignoring duplicates");
PASS([obj containsObject: strA] && [obj containsObject: strB], "Table contains correct objects");
[arp release]; arp = nil;
return 0;
}