Oolite
Loading...
Searching...
No Matches
OOProbabilitySet.m
Go to the documentation of this file.
1/*
2
3OOProbabilitySet.m
4
5
6Copyright (C) 2008-2013 Jens Ayton
7
8Permission is hereby granted, free of charge, to any person obtaining a copy
9of this software and associated documentation files (the "Software"), to deal
10in the Software without restriction, including without limitation the rights
11to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12copies of the Software, and to permit persons to whom the Software is
13furnished to do so, subject to the following conditions:
14
15The above copyright notice and this permission notice shall be included in all
16copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24SOFTWARE.
25
26
27IMPLEMENTATION NOTES
28OOProbabilitySet is implemented as a class cluster with two abstract classes,
29two special-case implementations for immutable sets with zero or one object,
30and two general implementations (one mutable and one immutable). The general
31implementations are the only non-trivial ones.
32
33The general immutable implementation, OOConcreteProbabilitySet, consists of
34two parallel arrays, one of objects and one of cumulative weights. The
35"cumulative weight" for an entry is the sum of its weight and the cumulative
36weight of the entry to the left (i.e., with a lower index), with the implicit
37entry -1 having a cumulative weight of 0. Since weight cannot be negative,
38this means that cumulative weights increase to the right (not strictly
39increasing, though, since weights may be zero). We can thus find an object
40with a given cumulative weight through a binary search.
41
42OOConcreteMutableProbabilitySet is a naïve implementation using arrays. It
43could be optimized, but isn't expected to be used much except for building
44sets that will then be immutablized.
45
46*/
47
48#import "OOProbabilitySet.h"
51#import "legacy_random.h"
52
53static NSString* const kObjectsKey = @"objects";
54static NSString* const kWeightsKey = @"weights";
55
56@protocol OOProbabilitySetEnumerable <NSObject>
57
58- (id)privObjectAtIndex:(NSUInteger)index;
59
60@end
61
62@interface OOProbabilitySet (OOPrivate)
63
64// Designated initializer. This must be used by subclasses, since init is overriden for public use.
65- (id)initPriv;
66
67@end
68
70
72
73@end
74
76@private
78 float _weight;
79}
80
81- (id)initWithObject:(id)object weight:(float)weight;
82
83@end
84
86@private
87 NSUInteger _count;
89 float* _cumulativeWeights; // Each cumulative weight is weight of object at this index + weight of all objects to left.
91}
92@end
93
95@private
96 NSMutableArray* _objects;
97 NSMutableArray* _weights;
99}
100
101- (id)initPrivWithObjectArray:(NSMutableArray*)objects weightsArray:(NSMutableArray*)weights sum:(float)sumOfWeights;
102
103@end
104
105@interface OOProbabilitySetEnumerator : NSEnumerator {
106@private
108 NSUInteger _index;
109}
110
111- (id)initWithEnumerable:(id<OOProbabilitySetEnumerable>)enumerable;
112
113@end
114
115static void ThrowAbstractionViolationException(id obj) GCC_ATTR((noreturn));
116
117@implementation OOProbabilitySet
118
119// Abstract class just tosses allocations over to concrete class, and throws exception if you try to use it directly.
120
122{
123 return [[OOEmptyProbabilitySet singleton] autorelease];
124}
125
126+ (id)probabilitySetWithObjects:(id*)objects weights:(float*)weights count:(NSUInteger)count
127{
128 return [[[self alloc] initWithObjects:objects weights:weights count:count] autorelease];
129}
130
131+ (id)probabilitySetWithPropertyListRepresentation:(NSDictionary*)plist
132{
133 return [[[self alloc] initWithPropertyListRepresentation:plist] autorelease];
134}
135
136- (id)init
137{
138 [self release];
139 return [OOEmptyProbabilitySet singleton];
140}
141
142- (id)initWithObjects:(id*)objects weights:(float*)weights count:(NSUInteger)count
143{
144 NSZone* zone = [self zone];
145 DESTROY(self);
146
147 // Zero objects: return empty-set singleton.
148 if (count == 0)
149 return [OOEmptyProbabilitySet singleton];
150
151 // If count is not zero and one of the paramters is nil, we've got us a programming error.
152 if (objects == NULL || weights == NULL) {
153 [NSException raise:NSInvalidArgumentException format:@"Attempt to create %@ with non-zero count but nil objects or weights.", @"OOProbabilitySet"];
154 }
155
156 // Single object: simple one-object set. Expected to be quite common.
157 if (count == 1)
158 return [[OOSingleObjectProbabilitySet allocWithZone:zone] initWithObject:objects[0] weight:weights[0]];
159
160 // Otherwise, use general implementation.
161 return [[OOConcreteProbabilitySet allocWithZone:zone] initWithObjects:objects weights:weights count:count];
162}
163
164- (id)initWithPropertyListRepresentation:(NSDictionary*)plist
165{
166 NSArray* objects = nil;
167 NSArray* weights = nil;
168 NSUInteger i = 0, count = 0;
169 id* rawObjects = NULL;
170 float* rawWeights = NULL;
171
172 objects = [plist oo_arrayForKey:kObjectsKey];
173 weights = [plist oo_arrayForKey:kWeightsKey];
174
175 // Validate
176 if (objects == nil || weights == nil) {
177 [self release];
178 return nil;
179 }
180 count = [objects count];
181 if (count != [weights count]) {
182 [self release];
183 return nil;
184 }
185
186 // Extract contents.
187 rawObjects = malloc(sizeof *rawObjects * count);
188 rawWeights = malloc(sizeof *rawWeights * count);
189
190 if (rawObjects != NULL || rawWeights != NULL) {
191 // Extract objects.
192 [objects getObjects:rawObjects];
193
194 // Extract and convert weights.
195 for (i = 0; i < count; ++i) {
196 rawWeights[i] = fmax([weights oo_floatAtIndex:i], 0.0f);
197 }
198
199 self = [self initWithObjects:rawObjects weights:rawWeights count:count];
200 } else {
201 [self release];
202 self = nil;
203 }
204
205 // Clean up.
206 free(rawObjects);
207 free(rawWeights);
208
209 return self;
210}
211
213{
214 return [super init];
215}
216
218{
219 return [NSString stringWithFormat:@"count=%zu", [self count]];
220}
221
226
231
232- (float)weightForObject:(id)object
233{
235}
236
241
242- (NSUInteger)count
243{
245}
246
247- (NSArray*)allObjects
248{
250}
251
252- (id)copyWithZone:(NSZone*)zone
253{
254 if (zone == [self zone]) {
255 return [self retain];
256 } else {
257 return [[OOProbabilitySet allocWithZone:zone] initWithPropertyListRepresentation:[self propertyListRepresentation]];
258 }
259}
260
261- (id)mutableCopyWithZone:(NSZone*)zone
262{
263 return [[OOMutableProbabilitySet allocWithZone:zone] initWithPropertyListRepresentation:[self propertyListRepresentation]];
264}
265
266@end
267
268@implementation OOProbabilitySet (OOExtendedProbabilitySet)
269
270- (BOOL)containsObject:(id)object
271{
272 return [self weightForObject:object] >= 0.0f;
273}
274
275- (NSEnumerator*)objectEnumerator
276{
277 return [[self allObjects] objectEnumerator];
278}
279
280- (float)probabilityForObject:(id)object
281{
282 float weight = [self weightForObject:object];
283 if (weight > 0)
284 weight /= [self sumOfWeights];
285
286 return weight;
287}
288
289@end
290
292
294
295+ (OOEmptyProbabilitySet*)singleton
296{
298 sOOEmptyProbabilitySetSingleton = [[self alloc] init];
299 }
300
302}
303
305{
306 NSArray* empty = [NSArray array];
307 return [NSDictionary dictionaryWithObjectsAndKeys:empty, kObjectsKey, empty, kWeightsKey, nil];
308}
309
311{
312 return nil;
313}
314
315- (float)weightForObject:(id)object
316{
317 return -1.0f;
318}
319
321{
322 return 0.0f;
323}
324
325- (NSUInteger)count
326{
327 return 0;
328}
329
330- (NSArray*)allObjects
331{
332 return [NSArray array];
333}
334
335- (id)mutableCopyWithZone:(NSZone*)zone
336{
337 // A mutable copy of an empty probability set is equivalent to a new empty mutable probability set.
338 return [[OOConcreteMutableProbabilitySet allocWithZone:zone] initPriv];
339}
340
341@end
342
343@implementation OOEmptyProbabilitySet (Singleton)
344
345/* Canonical singleton boilerplate.
346 See Cocoa Fundamentals Guide: Creating a Singleton Instance.
347 See also +singleton above.
348
349 NOTE: assumes single-threaded access.
350*/
351
352+ (id)allocWithZone:(NSZone*)inZone
353{
355 sOOEmptyProbabilitySetSingleton = [super allocWithZone:inZone];
357 }
358 return nil;
359}
360
361- (id)copyWithZone:(NSZone*)inZone
362{
363 return self;
364}
365
367{
368 return self;
369}
370
371- (NSUInteger)retainCount
372{
373 return UINT_MAX;
374}
375
376- (void)release
377{
378}
379
381{
382 return self;
383}
384
385@end
386
388
389- (id)initWithObject:(id)object weight:(float)weight
390{
391 if (object == nil) {
392 [self release];
393 return nil;
394 }
395
396 if ((self = [super initPriv])) {
397 _object = [object retain];
398 _weight = fmax(weight, 0.0f);
399 }
400
401 return self;
402}
403
404- (void)dealloc
405{
406 [_object release];
407
408 [super dealloc];
409}
410
412{
413 return [NSDictionary dictionaryWithObjectsAndKeys:
414 [NSArray arrayWithObject:_object], kObjectsKey,
415 [NSArray arrayWithObject:[NSNumber numberWithFloat:_weight]], kWeightsKey,
416 nil];
417}
418
420{
421 return _object;
422}
423
424- (float)weightForObject:(id)object
425{
426 if ([_object isEqual:object])
427 return _weight;
428 else
429 return -1.0f;
430}
431
433{
434 return _weight;
435}
436
437- (NSUInteger)count
438{
439 return 1;
440}
441
442- (NSArray*)allObjects
443{
444 return [NSArray arrayWithObject:_object];
445}
446
447- (id)mutableCopyWithZone:(NSZone*)zone
448{
449 return [[OOConcreteMutableProbabilitySet allocWithZone:zone] initWithObjects:&_object weights:&_weight count:1];
450}
451
452@end
453
454@implementation OOConcreteProbabilitySet
455
456- (id)initWithObjects:(id*)objects weights:(float*)weights count:(NSUInteger)count
457{
458 NSUInteger i = 0;
459 float cuWeight = 0.0f;
460
461 assert(count > 1 && objects != NULL && weights != NULL);
462
463 if ((self = [super initPriv])) {
464 // Allocate arrays
465 _objects = malloc(sizeof *objects * count);
466 _cumulativeWeights = malloc(sizeof *_cumulativeWeights * count);
467 if (_objects == NULL || _cumulativeWeights == NULL) {
468 [self release];
469 return nil;
470 }
471
472 // Fill in arrays, retain objects, add up weights.
473 for (i = 0; i != count; ++i) {
474 _objects[i] = [objects[i] retain];
475 cuWeight += weights[i];
476 _cumulativeWeights[i] = cuWeight;
477 }
478 _count = count;
479 _sumOfWeights = cuWeight;
480 }
481
482 return self;
483}
484
485- (void)dealloc
486{
487 NSUInteger i = 0;
488
489 if (_objects != NULL) {
490 for (i = 0; i < _count; ++i) {
491 [_objects[i] release];
492 }
493 free(_objects);
494 _objects = NULL;
495 }
496
497 if (_cumulativeWeights != NULL) {
498 free(_cumulativeWeights);
499 _cumulativeWeights = NULL;
500 }
501
502 [super dealloc];
503}
504
506{
507 NSArray* objects = nil;
508 NSMutableArray* weights = nil;
509 float cuWeight = 0.0f, sum = 0.0f;
510 NSUInteger i = 0;
511
512 objects = [NSArray arrayWithObjects:_objects count:_count];
513 weights = [NSMutableArray arrayWithCapacity:_count];
514 for (i = 0; i < _count; ++i) {
515 cuWeight = _cumulativeWeights[i];
516 [weights oo_addFloat:cuWeight - sum];
517 sum = cuWeight;
518 }
519
520 return [NSDictionary dictionaryWithObjectsAndKeys:
521 objects, kObjectsKey,
522 [[weights copy] autorelease], kWeightsKey,
523 nil];
524}
525
526- (NSUInteger)count
527{
528 return _count;
529}
530
531- (id)privObjectForWeight:(float)target
532{
533 /* Select an object at random. This is a binary search in the cumulative
534 weights array. Since weights of zero are allowed, there may be several
535 objects with the same cumulative weight, in which case we select the
536 leftmost, i.e. the one where the delta is non-zero.
537 */
538
539 NSUInteger low = 0, high = _count - 1, idx = 0;
540 float weight = 0.0f;
541
542 while (low < high) {
543 idx = (low + high) / 2;
544 weight = _cumulativeWeights[idx];
545 if (weight > target) {
546 if (EXPECT_NOT(idx == 0))
547 break;
548 high = idx - 1;
549 } else if (weight < target)
550 low = idx + 1;
551 else
552 break;
553 }
554
555 if (weight > target) {
556 while (idx > 0 && _cumulativeWeights[idx - 1] >= target)
557 --idx;
558 } else {
559 while (idx < (_count - 1) && _cumulativeWeights[idx] < target)
560 ++idx;
561 }
562
563 assert(idx < _count);
564 id result = _objects[idx];
565 return result;
566}
567
569{
570 if (_sumOfWeights <= 0.0f)
571 return nil;
572 return [self privObjectForWeight:randf() * _sumOfWeights];
573}
574
575- (float)weightForObject:(id)object
576{
577 NSUInteger i;
578
579 // Can't have nil in collection.
580 if (object == nil)
581 return -1.0f;
582
583 // Perform linear search, then get weight by subtracting cumulative weight from cumulative weight to left.
584 for (i = 0; i < _count; ++i) {
585 if ([_objects[i] isEqual:object]) {
586 float leftWeight = (i != 0) ? _cumulativeWeights[i - 1] : 0.0f;
587 return _cumulativeWeights[i] - leftWeight;
588 }
589 }
590
591 // If we got here, object not found.
592 return -1.0f;
593}
594
596{
597 return _sumOfWeights;
598}
599
600- (NSArray*)allObjects
601{
602 return [NSArray arrayWithObjects:_objects count:_count];
603}
604
605- (NSEnumerator*)objectEnumerator
606{
607 return [[[OOProbabilitySetEnumerator alloc] initWithEnumerable:self] autorelease];
608}
609
610- (id)privObjectAtIndex:(NSUInteger)index
611{
612 return (index < _count) ? _objects[index] : nil;
613}
614
615- (id)mutableCopyWithZone:(NSZone*)zone
616{
617 id result = nil;
618 float* weights = NULL;
619 NSUInteger i = 0;
620 float weight = 0.0f, sum = 0.0f;
621
622 // Convert cumulative weights to "plain" weights.
623 weights = malloc(sizeof *weights * _count);
624 if (weights == NULL)
625 return nil;
626
627 for (i = 0; i < _count; ++i) {
628 weight = _cumulativeWeights[i];
629 weights[i] = weight - sum;
630 sum += weights[i];
631 }
632
633 result = [[OOConcreteMutableProbabilitySet allocWithZone:zone] initWithObjects:_objects weights:weights count:_count];
634 free(weights);
635
636 return result;
637}
638
639@end
640
641@implementation OOMutableProbabilitySet
642
644{
645 return [[[OOConcreteMutableProbabilitySet alloc] initPriv] autorelease];
646}
647
648- (id)init
649{
650 NSZone* zone = [self zone];
651 [self release];
652 return [[OOConcreteMutableProbabilitySet allocWithZone:zone] initPriv];
653}
654
655- (id)initWithObjects:(id*)objects weights:(float*)weights count:(NSUInteger)count
656{
657 NSZone* zone = [self zone];
658 [self release];
659 return [[OOConcreteMutableProbabilitySet allocWithZone:zone] initWithObjects:objects weights:weights count:count];
660}
661
662- (id)initWithPropertyListRepresentation:(NSDictionary*)plist
663{
664 NSZone* zone = [self zone];
665 [self release];
666 return [[OOConcreteMutableProbabilitySet allocWithZone:zone] initWithPropertyListRepresentation:plist];
667}
668
669- (id)copyWithZone:(NSZone*)zone
670{
671 return [[OOProbabilitySet allocWithZone:zone] initWithPropertyListRepresentation:[self propertyListRepresentation]];
672}
673
674- (void)setWeight:(float)weight forObject:(id)object
675{
677}
678
679- (void)removeObject:(id)object
680{
682}
683
684@end
685
687
689{
690 if ((self = [super initPriv])) {
691 _objects = [[NSMutableArray alloc] init];
692 _weights = [[NSMutableArray alloc] init];
693 }
694
695 return self;
696}
697
698// For internal use by mutableCopy
699- (id)initPrivWithObjectArray:(NSMutableArray*)objects weightsArray:(NSMutableArray*)weights sum:(float)sumOfWeights
700{
701 assert(objects != nil && weights != nil && [objects count] == [weights count] && sumOfWeights >= 0.0f);
702
703 if ((self = [super initPriv])) {
704 _objects = [objects retain];
705 _weights = [weights retain];
707 }
708
709 return self;
710}
711
712- (id)initWithObjects:(id*)objects weights:(float*)weights count:(NSUInteger)count
713{
714 NSUInteger i = 0;
715
716 // Validate parameters.
717 if (count != 0 && (objects == NULL || weights == NULL)) {
718 [self release];
719 [NSException raise:NSInvalidArgumentException format:@"Attempt to create %@ with non-zero count but nil objects or weights.", @"OOMutableProbabilitySet"];
720 }
721
722 // Set up & go.
723 if ((self = [self initPriv])) {
724 for (i = 0; i != count; ++i) {
725 [self setWeight:fmax(weights[i], 0.0f) forObject:objects[i]];
726 }
727 }
728
729 return self;
730}
731
732- (id)initWithPropertyListRepresentation:(NSDictionary*)plist
733{
734 BOOL OK = YES;
735 NSArray* objects = nil;
736 NSArray* weights = nil;
737 NSUInteger i = 0, count = 0;
738
739 if (!(self = [super initPriv]))
740 OK = NO;
741
742 if (OK) {
743 objects = [plist oo_arrayForKey:kObjectsKey];
744 weights = [plist oo_arrayForKey:kWeightsKey];
745
746 // Validate
747 if (objects == nil || weights == nil)
748 OK = NO;
749 count = [objects count];
750 if (count != [weights count])
751 OK = NO;
752 }
753
754 if (OK) {
755 for (i = 0; i < count; ++i) {
756 [self setWeight:[weights oo_floatAtIndex:i] forObject:[objects objectAtIndex:i]];
757 }
758 }
759
760 if (!OK) {
761 [self release];
762 self = nil;
763 }
764
765 return self;
766}
767
768- (void)dealloc
769{
770 [_objects release];
771 [_weights release];
772
773 [super dealloc];
774}
775
777{
778 return [NSDictionary dictionaryWithObjectsAndKeys:
779 _objects, kObjectsKey,
780 _weights, kWeightsKey,
781 nil];
782}
783
784- (NSUInteger)count
785{
786 return [_objects count];
787}
788
790{
791 float target = 0.0f, sum = 0.0f, sumOfWeights;
792 NSUInteger i = 0, count = 0;
793
794 sumOfWeights = [self sumOfWeights];
795 target = randf() * sumOfWeights;
796 count = [_objects count];
797 if (count == 0 || sumOfWeights <= 0.0f)
798 return nil;
799
800 for (i = 0; i < count; ++i) {
801 sum += [_weights oo_floatAtIndex:i];
802 if (sum >= target)
803 return [_objects objectAtIndex:i];
804 }
805
806 OOLog(@"probabilitySet.broken", @"%s fell off end, returning first object. Nominal sum = %f, target = %f, actual sum = %f, count = %zu. %@", __PRETTY_FUNCTION__, sumOfWeights, target, sum, count, @"This is an internal error, please report it.");
807 return [_objects objectAtIndex:0];
808}
809
810- (float)weightForObject:(id)object
811{
812 float result = -1.0f;
813
814 if (object != nil) {
815 NSUInteger index = [_objects indexOfObject:object];
816 if (index != NSNotFound) {
817 result = [_weights oo_floatAtIndex:index];
818 if (index != 0)
819 result -= [_weights oo_floatAtIndex:index - 1];
820 }
821 }
822 return result;
823}
824
826{
827 if (_sumOfWeights < 0.0f) {
828 NSUInteger i, count;
829 count = [self count];
830
831 _sumOfWeights = 0.0f;
832 for (i = 0; i < count; ++i) {
833 _sumOfWeights += [_weights oo_floatAtIndex:i];
834 }
835 }
836 return _sumOfWeights;
837}
838
839- (NSArray*)allObjects
840{
841 return [[_objects copy] autorelease];
842}
843
844- (NSEnumerator*)objectEnumerator
845{
846 return [_objects objectEnumerator];
847}
848
849- (void)setWeight:(float)weight forObject:(id)object
850{
851 if (object == nil)
852 return;
853
854 weight = fmax(weight, 0.0f);
855 NSUInteger index = [_objects indexOfObject:object];
856 if (index == NSNotFound) {
857 [_objects addObject:object];
858 [_weights oo_addFloat:weight];
859 if (_sumOfWeights >= 0) {
860 _sumOfWeights += weight;
861 }
862 // Else, _sumOfWeights is invalid and will need to be recalculated on demand.
863 } else {
864 _sumOfWeights = -1.0f; // Simply subtracting the relevant weight doesn't work if the weight is large, due to floating-point precision issues.
865 [_weights replaceObjectAtIndex:index withObject:[NSNumber numberWithFloat:weight]];
866 }
867}
868
869- (void)removeObject:(id)object
870{
871 if (object == nil)
872 return;
873
874 NSUInteger index = [_objects indexOfObject:object];
875 if (index != NSNotFound) {
876 [_objects removeObjectAtIndex:index];
877 _sumOfWeights = -1.0f; // Simply subtracting the relevant weight doesn't work if the weight is large, due to floating-point precision issues.
878 [_weights removeObjectAtIndex:index];
879 }
880}
881
882- (id)copyWithZone:(NSZone*)zone
883{
884 id result = nil;
885 id* objects = NULL;
886 float* weights = NULL;
887 NSUInteger i = 0, count = 0;
888
889 count = [_objects count];
890 if (EXPECT_NOT(count == 0))
891 return [OOEmptyProbabilitySet singleton];
892
893 objects = malloc(sizeof *objects * count);
894 weights = malloc(sizeof *weights * count);
895 if (objects != NULL && weights != NULL) {
896 [_objects getObjects:objects];
897
898 for (i = 0; i < count; ++i) {
899 weights[i] = [_weights oo_floatAtIndex:i];
900 }
901
902 result = [[OOProbabilitySet probabilitySetWithObjects:objects weights:weights count:count] retain];
903 }
904
905 if (objects != NULL)
906 free(objects);
907 if (weights != NULL)
908 free(weights);
909
910 return result;
911}
912
913- (id)mutableCopyWithZone:(NSZone*)zone
914{
915 return [[OOConcreteMutableProbabilitySet alloc] initPrivWithObjectArray:[[_objects mutableCopyWithZone:zone] autorelease]
916 weightsArray:[[_weights mutableCopyWithZone:zone] autorelease]
917 sum:_sumOfWeights];
918}
919
920@end
921
922@implementation OOProbabilitySetEnumerator
923
924- (id)initWithEnumerable:(id<OOProbabilitySetEnumerable>)enumerable
925{
926 if ((self = [super init])) {
927 _enumerable = [enumerable retain];
928 }
929
930 return self;
931}
932
933- (void)dealloc
934{
935 [_enumerable release];
936
937 [super dealloc];
938}
939
941{
942 if (_index < [_enumerable count]) {
943 return [_enumerable privObjectAtIndex:_index++];
944 } else {
945 [_enumerable release];
947 return nil;
948 }
949}
950
951@end
952
954{
955 [NSException raise:NSGenericException format:@"Attempt to use abstract class %@ - this indicates an incorrect initialization.", [obj class]];
956 abort(); // unreachable
957}
#define DESTROY(x)
#define EXPECT_NOT(x)
#define GCC_ATTR(x)
#define OOLog(class, format,...)
Definition OOLogging.h:84
unsigned count
static OOEmptyProbabilitySet * sOOEmptyProbabilitySetSingleton
static NSString *const kObjectsKey
static void ThrowAbstractionViolationException(id obj) GCC_ATTR((noreturn))
static NSString *const kWeightsKey
return nil
void setWeight:forObject:(float weight, [forObject] id object)
id privObjectForWeight:(float target)
NSDictionary * propertyListRepresentation()
NSEnumerator * objectEnumerator()
OOEmptyProbabilitySet * OO_RETURNS_RETAINED()
NSDictionary * propertyListRepresentation()
NSDictionary * propertyListRepresentation()
id probabilitySetWithObjects:weights:count:(id *objects,[weights] float *weights,[count] NSUInteger count)
id initWithObjects:weights:count:(id *objects,[weights] float *weights,[count] NSUInteger count)
NSString * descriptionComponents()
float weightForObject:(id object)
NSDictionary * propertyListRepresentation()
float randf(void)