-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathD2PGenerationManager.m
More file actions
75 lines (55 loc) · 1.16 KB
/
D2PGenerationManager.m
File metadata and controls
75 lines (55 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// D2PGenerationManager.m
// D2Patch
//
// Created by Andrey on 23/02/2017.
//
#import "D2PGenerationManager.h"
@implementation D2PGenerationManager
- (instancetype) initWithGenerationsCount:(NSUInteger)count
{
self = [super init];
if (self)
{
if (count >= 2)
{
_data = [NSMutableArray arrayWithCapacity:count];
for (NSUInteger i = 0; i < count; i++)
{
[_data addObject:[NSMutableSet set]];
}
}
else
{
return nil;
}
}
return self;
}
- (void) addFreshObject:(id)object
{
[self removeObject:object];
[_data.lastObject addObject:object];
}
- (void) removeObject:(id)object
{
for (NSMutableSet *s in _data)
{
[s removeObject:object];
}
}
- (void) shiftDownGenerations
{
for (NSUInteger i = 0; i < (_data.count - 1); i++)
{
NSMutableSet *oldSet = _data[i];
NSMutableSet *youngSet = _data[i+1];
[oldSet unionSet:youngSet];
[youngSet removeAllObjects];
}
}
- (id) anyOldestObject
{
return [_data[0] anyObject];
}
@end