Definition at line 104 of file OOProbabilitySet.m.
◆ allObjects
◆ copyWithZone:
- (id) copyWithZone: |
|
(NSZone *) | zone |
|
|
implementation |
Reimplemented from OOMutableProbabilitySet.
Definition at line 458 of file OOProbabilitySet.m.
997{
999 id *objects = NULL;
1000 float *weights = NULL;
1001 NSUInteger i = 0,
count = 0;
1002
1003 count = [_objects count];
1005
1006 objects = malloc(
sizeof *objects *
count);
1007 weights = malloc(
sizeof *weights *
count);
1008 if (objects != NULL && weights != NULL)
1009 {
1010 [_objects getObjects:objects];
1011
1012 for (i = 0; i <
count; ++i)
1013 {
1014 weights[i] = [_weights oo_floatAtIndex:i];
1015 }
1016
1018 }
1019
1020 if (objects != NULL) free(objects);
1021 if (weights != NULL) free(weights);
1022
1023 return result;
1024}
1025
id probabilitySetWithObjects:weights:count:(id *objects,[weights] float *weights,[count] NSUInteger count)
◆ count
◆ dealloc
Definition at line 458 of file OOProbabilitySet.m.
868{
869 [_objects release];
870 [_weights release];
871
872 [super dealloc];
873}
874
◆ initPriv
Reimplemented from OOProbabilitySet.
Definition at line 458 of file OOProbabilitySet.m.
778{
780 {
781 _objects = [[NSMutableArray alloc] init];
782 _weights = [[NSMutableArray alloc] init];
783 }
784
785 return self;
786}
787
NSMutableArray * _objects
NSMutableArray * _weights
◆ initPrivWithObjectArray:weightsArray:sum:
- (id) initPrivWithObjectArray: |
|
(NSMutableArray *) | objects |
weightsArray: |
|
(NSMutableArray *) | weights |
sum: |
|
(float) | sumOfWeights |
◆ initWithObjects:weights:count:
- (id) initWithObjects: |
|
(id *) | objects |
weights: |
|
(float *) | weights |
count: |
|
(NSUInteger) | count |
|
implementation |
Reimplemented from OOMutableProbabilitySet.
Definition at line 458 of file OOProbabilitySet.m.
806{
807 NSUInteger i = 0;
808
809
810 if (
count != 0 && (objects == NULL || weights == NULL))
811 {
812 [self release];
813 [NSException raise:NSInvalidArgumentException format:@"Attempt to create %@ with non-zero count but nil objects or weights.", @"OOMutableProbabilitySet"];
814 }
815
816
818 {
819 for (i = 0; i !=
count; ++i)
820 {
821 [self setWeight:fmax(weights[i], 0.0f) forObject:objects[i]];
822 }
823 }
824
825 return self;
826}
827
◆ initWithPropertyListRepresentation:
- (id) initWithPropertyListRepresentation: |
|
(NSDictionary *) | plist |
|
|
implementation |
Reimplemented from OOMutableProbabilitySet.
Definition at line 458 of file OOProbabilitySet.m.
830{
831 BOOL OK = YES;
832 NSArray *objects =
nil;
833 NSArray *weights =
nil;
834 NSUInteger i = 0,
count = 0;
835
836 if (!(
self = [super
initPriv])) OK = NO;
837
838 if (OK)
839 {
840 objects = [plist oo_arrayForKey:kObjectsKey];
841 weights = [plist oo_arrayForKey:kWeightsKey];
842
843
844 if (objects ==
nil || weights ==
nil) OK = NO;
845 count = [objects count];
847 }
848
849 if (OK)
850 {
851 for (i = 0; i <
count; ++i)
852 {
853 [self setWeight:[weights oo_floatAtIndex:i] forObject:[objects objectAtIndex:i]];
854 }
855 }
856
857 if (!OK)
858 {
859 [self release];
861 }
862
863 return self;
864}
865
◆ mutableCopyWithZone:
- (id) mutableCopyWithZone: |
|
(NSZone *) | zone |
|
|
implementation |
Reimplemented from OOProbabilitySet.
Definition at line 458 of file OOProbabilitySet.m.
1028{
1030 weightsArray:[[_weights mutableCopyWithZone:zone] autorelease]
1031 sum:_sumOfWeights];
1032}
1033
◆ objectEnumerator
- (NSEnumerator *) objectEnumerator |
|
|
|
|
implementation |
◆ propertyListRepresentation
- (NSDictionary *) propertyListRepresentation |
|
|
|
|
implementation |
Reimplemented from OOProbabilitySet.
Definition at line 458 of file OOProbabilitySet.m.
877{
878 return [NSDictionary dictionaryWithObjectsAndKeys:
879 _objects, kObjectsKey,
880 _weights, kWeightsKey,
881 nil];
882}
883
◆ randomObject
Reimplemented from OOProbabilitySet.
Definition at line 458 of file OOProbabilitySet.m.
892{
894 NSUInteger i = 0,
count = 0;
895
898 count = [_objects count];
900
901 for (i = 0; i <
count; ++i)
902 {
903 sum += [
_weights oo_floatAtIndex:i];
904 if (sum >= target)
return [
_objects objectAtIndex:i];
905 }
906
907 OOLog(
@"probabilitySet.broken",
@"%s fell off end, returning first object. Nominal sum = %f, target = %f, actual sum = %f, count = %lu. %@", __PRETTY_FUNCTION__,
sumOfWeights, target, sum,
count,
@"This is an internal error, please report it.");
908 return [_objects objectAtIndex:0];
909}
910
#define OOLog(class, format,...)
◆ removeObject:
- (void) removeObject: |
|
(id) | object |
|
|
implementation |
Reimplemented from OOMutableProbabilitySet.
Definition at line 458 of file OOProbabilitySet.m.
983{
984 if (
object ==
nil)
return;
985
986 NSUInteger index = [_objects indexOfObject:object];
987 if (index != NSNotFound)
988 {
989 [_objects removeObjectAtIndex:index];
991 [_weights removeObjectAtIndex:index];
992 }
993}
994
◆ setWeight:forObject:
- (void) setWeight: |
|
(float) | weight |
forObject: |
|
(id) | object |
|
implementation |
Reimplemented from OOMutableProbabilitySet.
Definition at line 458 of file OOProbabilitySet.m.
959{
960 if (
object ==
nil)
return;
961
962 weight = fmax(weight, 0.0f);
963 NSUInteger index = [_objects indexOfObject:object];
964 if (index == NSNotFound)
965 {
966 [_objects addObject:object];
967 [_weights oo_addFloat:weight];
969 {
971 }
972
973 }
974 else
975 {
977 [_weights replaceObjectAtIndex:index withObject:[NSNumber numberWithFloat:weight]];
978 }
979}
980
◆ sumOfWeights
◆ weightForObject:
- (float) weightForObject: |
|
(id) | object |
|
|
implementation |
Reimplemented from OOProbabilitySet.
Definition at line 458 of file OOProbabilitySet.m.
913{
914 float result = -1.0f;
915
917 {
918 NSUInteger index = [_objects indexOfObject:object];
919 if (index != NSNotFound)
920 {
921 result = [_weights oo_floatAtIndex:index];
922 if (index != 0) result -= [
_weights oo_floatAtIndex:index - 1];
923 }
924 }
925 return result;
926}
927
◆ _objects
- (NSMutableArray*) _objects |
|
private |
◆ _sumOfWeights
◆ _weights
- (NSMutableArray*) _weights |
|
private |
The documentation for this class was generated from the following file: