blob: 36c7720cd82f8979924663c128e4d34b57101a01 (
plain)
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
75
76
77
78
79
80
81
|
//
// MCORange.c
// mailcore2
//
// Created by DINH Viêt Hoà on 3/24/13.
// Copyright (c) 2013 MailCore. All rights reserved.
//
#import "MCORange.h"
#import "MCOIndexSet.h"
#import "MCOIndexSet+Private.h"
#include <string.h>
MCORange MCORangeEmpty = {UINT64_MAX, 0};
MCORange MCORangeMake(uint64_t location, uint64_t length)
{
MCORange result;
result.location = location;
result.length = length;
return result;
}
MCOIndexSet * MCORangeRemoveRange(MCORange range1, MCORange range2)
{
mailcore::Range mcRange1 = MCORangeToMCRange(range1);
mailcore::Range mcRange2 = MCORangeToMCRange(range2);
mailcore::IndexSet * indexSet = mailcore::RangeRemoveRange(mcRange1, mcRange2);
return [[[MCOIndexSet alloc] initWithMCIndexSet:indexSet] autorelease];
}
MCOIndexSet * MCORangeUnion(MCORange range1, MCORange range2)
{
mailcore::Range mcRange1 = MCORangeToMCRange(range1);
mailcore::Range mcRange2 = MCORangeToMCRange(range2);
mailcore::IndexSet * indexSet = mailcore::RangeUnion(mcRange1, mcRange2);
return [[[MCOIndexSet alloc] initWithMCIndexSet:indexSet] autorelease];
}
mailcore::Range MCORangeToMCRange(MCORange range)
{
return mailcore::RangeMake(range.location, range.length);
}
MCORange MCORangeWithMCRange(mailcore::Range range)
{
MCORange result;
result.location = range.location;
result.length = range.length;
return result;
}
MCORange MCORangeIntersection(MCORange range1, MCORange range2)
{
mailcore::Range mcRange1 = MCORangeToMCRange(range1);
mailcore::Range mcRange2 = MCORangeToMCRange(range2);
mailcore::Range mcResult = mailcore::RangeIntersection(mcRange1, mcRange2);
return MCORangeWithMCRange(mcResult);
}
BOOL MCORangeHasIntersection(MCORange range1, MCORange range2)
{
mailcore::Range mcRange1 = MCORangeToMCRange(range1);
mailcore::Range mcRange2 = MCORangeToMCRange(range2);
return mailcore::RangeHasIntersection(mcRange1, mcRange2);
}
uint64_t MCORangeLeftBound(MCORange range)
{
mailcore::Range mcRange = MCORangeToMCRange(range);
return mailcore::RangeLeftBound(mcRange);
}
uint64_t MCORangeRightBound(MCORange range)
{
mailcore::Range mcRange = MCORangeToMCRange(range);
return mailcore::RangeRightBound(mcRange);
}
|