OverlappingBlocks returns all overlapping blocks from given meta files.
(bm []BlockMeta)
| 2150 | |
| 2151 | // OverlappingBlocks returns all overlapping blocks from given meta files. |
| 2152 | func OverlappingBlocks(bm []BlockMeta) Overlaps { |
| 2153 | if len(bm) <= 1 { |
| 2154 | return nil |
| 2155 | } |
| 2156 | var ( |
| 2157 | overlaps [][]BlockMeta |
| 2158 | |
| 2159 | // pending contains not ended blocks in regards to "current" timestamp. |
| 2160 | pending = []BlockMeta{bm[0]} |
| 2161 | // continuousPending helps to aggregate same overlaps to single group. |
| 2162 | continuousPending = true |
| 2163 | ) |
| 2164 | |
| 2165 | // We have here blocks sorted by minTime. We iterate over each block and treat its minTime as our "current" timestamp. |
| 2166 | // We check if any of the pending block finished (blocks that we have seen before, but their maxTime was still ahead current |
| 2167 | // timestamp). If not, it means they overlap with our current block. In the same time current block is assumed pending. |
| 2168 | for _, b := range bm[1:] { |
| 2169 | var newPending []BlockMeta |
| 2170 | |
| 2171 | for _, p := range pending { |
| 2172 | // "b.MinTime" is our current time. |
| 2173 | if b.MinTime >= p.MaxTime { |
| 2174 | continuousPending = false |
| 2175 | continue |
| 2176 | } |
| 2177 | |
| 2178 | // "p" overlaps with "b" and "p" is still pending. |
| 2179 | newPending = append(newPending, p) |
| 2180 | } |
| 2181 | |
| 2182 | // Our block "b" is now pending. |
| 2183 | pending = append(newPending, b) |
| 2184 | if len(newPending) == 0 { |
| 2185 | // No overlaps. |
| 2186 | continue |
| 2187 | } |
| 2188 | |
| 2189 | if continuousPending && len(overlaps) > 0 { |
| 2190 | overlaps[len(overlaps)-1] = append(overlaps[len(overlaps)-1], b) |
| 2191 | continue |
| 2192 | } |
| 2193 | overlaps = append(overlaps, append(newPending, b)) |
| 2194 | // Start new pendings. |
| 2195 | continuousPending = true |
| 2196 | } |
| 2197 | |
| 2198 | // Fetch the critical overlapped time range foreach overlap groups. |
| 2199 | overlapGroups := Overlaps{} |
| 2200 | for _, overlap := range overlaps { |
| 2201 | minRange := TimeRange{Min: 0, Max: math.MaxInt64} |
| 2202 | for _, b := range overlap { |
| 2203 | if minRange.Max > b.MaxTime { |
| 2204 | minRange.Max = b.MaxTime |
| 2205 | } |
| 2206 | |
| 2207 | if minRange.Min < b.MinTime { |
| 2208 | minRange.Min = b.MinTime |
| 2209 | } |
no outgoing calls
searching dependent graphs…