00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 @import "CPSet.j"
00024
00031 @implementation CPCountedSet : CPMutableSet
00032 {
00033 Object _counts;
00034 }
00035
00036 - (void)addObject:(id)anObject
00037 {
00038 if (!_counts)
00039 _counts = {};
00040
00041 [super addObject:anObject];
00042
00043 var UID = [anObject UID];
00044
00045 if (_counts[UID] === undefined)
00046 _counts[UID] = 1;
00047 else
00048 ++_counts[UID];
00049 }
00050
00051 - (void)removeObject:(id)anObject
00052 {
00053 if (!_counts)
00054 return;
00055
00056 var UID = [anObject UID];
00057
00058 if (_counts[UID] === undefined)
00059 return;
00060
00061 else
00062 {
00063 --_counts[UID];
00064
00065 if (_counts[UID] === 0)
00066 {
00067 delete _counts[UID];
00068 [super removeObject:anObject];
00069 }
00070 }
00071 }
00072
00073 - (void)removeAllObjects
00074 {
00075 [super removeAllObjects];
00076 _counts = {};
00077 }
00078
00079
00080
00081
00082
00083 - (unsigned)countForObject:(id)anObject
00084 {
00085 if (!_counts)
00086 _counts = {};
00087
00088 var UID = [anObject UID];
00089
00090 if (_counts[UID] === undefined)
00091 return 0;
00092
00093 return _counts[UID];
00094 }
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 @end