@@ -54,89 +54,5 @@ public static BytesRange Chunkify(this BytesRange range, ChunksData chunksData)
5454
5555 return new BytesRange ( bottom , top ) ;
5656 }
57-
58- /// <summary>
59- /// Limits one range inside the other, examples:
60- /// 0:-1 contained in range 20:30 becomes 20:30.
61- /// 0:100 contained in range 50:-1 becomes 50:100
62- /// </summary>
63- public static BytesRange ContainIn ( this BytesRange range , BytesRange outer )
64- {
65- if ( Contains ( outer , range ) )
66- {
67- return range ;
68- }
69-
70- long start = range . Start ;
71- long end = range . End ;
72-
73- if ( range . Start < outer . Start )
74- {
75- start = outer . Start ;
76- }
77-
78- if ( outer . End != - 1 )
79- {
80- if ( range . End == - 1 || range . End > outer . End )
81- {
82- end = outer . End ;
83- }
84- }
85-
86- return Make ( start , end ) ;
87- }
88-
89- /// <summary>
90- /// Localizes one range inside another, the resulting range is limited and local to the relative ("parent") range
91- /// If the ranges don't overlap, an empty range will be returned.
92- /// Examples:
93- /// 50:95 localized within 10:90 becomes 40:-1
94- /// 5:15 localized within 10:90 becomes 0:5
95- /// </summary>
96- public static BytesRange LocalizeTo ( this BytesRange range , BytesRange relative )
97- {
98- if ( ! Overlaps ( range , relative ) )
99- {
100- return Empty ( ) ;
101- }
102-
103- long localStart = range . Start >= relative . Start ? range . Start - relative . Start : 0 ;
104- long localEnd = range . End <= relative . End ? range . End - relative . Start : - 1 ;
105-
106- if ( range . End == - 1 )
107- {
108- localEnd = - 1 ;
109- }
110-
111- return Make ( localStart , localEnd ) ;
112- }
113-
114- public static bool Overlaps ( this BytesRange lhs , BytesRange rhs )
115- {
116- return Contains ( lhs , rhs )
117- || Contains ( rhs , lhs )
118- || Contains ( lhs , rhs . Start )
119- || Contains ( lhs , rhs . End ) ;
120- }
121-
122- public static bool Contains ( this BytesRange outer , BytesRange inner )
123- {
124- if ( inner . End == - 1 && outer . End != - 1 )
125- {
126- return false ;
127- }
128-
129- if ( inner . Start >= outer . Start )
130- {
131- return outer . End == - 1 || inner . End <= outer . End ;
132- }
133-
134- return false ;
135- }
136-
137- public static bool Contains ( this BytesRange range , long value )
138- {
139- return value >= range . Start && ( range . End == - 1 || value <= range . End ) ;
140- }
14157 }
14258}
0 commit comments