Anonymous user
Run-length encoding/Objective-C: Difference between revisions
m
modernize
(moved from Run-length encoding) |
m (modernize) |
||
Line 12:
NSMutableArray *counters;
}
▲- (id)initWithData: (NSData *)data;
- (void)addByte: (char)aByte;
- (void)addByte: (char)aByte repeated: (int)repetitionCount;
Line 27 ⟶ 24:
@implementation RCRunLengthEncoder
+ (
{
return
}
- (
{
if ((self = [self init]) != nil) {
Line 40 ⟶ 37:
}
- (
{
if ((self = [super init]) != nil) {
Line 47 ⟶ 44:
}
return self;
}
Line 64 ⟶ 54:
{
if ( ([contents count] == 0) || ([[contents lastObject] charValue] != aByte) ) {
[contents addObject:
[counters addObject:
} else {
[counters removeLastObject];
[counters addObject:
}
}
Line 98 ⟶ 87:
for(i=0; i < [contents count]; i++) {
char c =
int n =
memset(buf, c, 256);
while ( n > 0 ) {
Line 106 ⟶ 95:
}
}
return
}
@end</lang>
Line 147 ⟶ 136:
for(i=0; i < [counters count]; i++) {
char c =
int howMany =
if ( literalCount == 128 ) {
buf[0] = 0;
Line 175 ⟶ 164:
}
}
return
}
@end</lang>
Line 185 ⟶ 174:
int main()
{
@autoreleasepool {
codecRLE *enc = [[codecRLE alloc]
initWithData: [NSData dataWithBytes: s
length: strlen(s)] ];
NSData *repr = [enc encode];
fwrite([repr bytes], 1, [repr length], stdout);
enc = [[codecRLE alloc] init];
[enc decode: repr];
NSData *d = [enc data];
fwrite([d bytes], 1, [d length], stdout);
}
return EXIT_SUCCESS;
}</lang>
|