// OverlapsTimeRange returns true if the time range of the file intersect min and max.
322074
func (f FileStat) OverlapsTimeRange(min, max int64) bool {
	return f.MinTime <= max && f.MaxTime >= min
}
1197829
func (c *LeveledCompactor) selectOverlappingDirs(ds []dirMeta) []string {
	if len(ds) < 2 {
		return nil
	}
	var overlappingDirs []string
	globalMaxt := ds[0].meta.MaxTime
	for i, d := range ds[1:] {
		if d.meta.MinTime < globalMaxt {
			if len(overlappingDirs) == 0 { // When it is the first overlap, need to add the last one as well.
				overlappingDirs = append(overlappingDirs, ds[i].dir)
			}
			overlappingDirs = append(overlappingDirs, d.dir)
		} else if len(overlappingDirs) > 0 {
			break
		}
		if d.meta.MaxTime > globalMaxt {
			globalMaxt = d.meta.MaxTime
		}
	}
	return overlappingDirs
}
440730
func (r *RegionSet) overlaps(reference Region, start, end int) (ret []int) {
	for i := start; i < end; i++ {
		if reference == r.regions[i] || reference.Intersects(r.regions[i]) || reference.Covers(r.regions[i]) {
			ret = append(ret, i)
		}
	}
	return
}
1162027
func (s *HLSFragmentSelector) SetTimestampRange(v *HLSTimestampRange) *HLSFragmentSelector {
	s.TimestampRange = v
	return s
}
563289
func (c *RawKVClient) DeleteRange(startKey []byte, endKey []byte) error {
	start := time.Now()
	var err error
	defer func() {
		var label = "delete_range"
		if err != nil {
			label += "_error"
		}
		metrics.TiKVRawkvCmdHistogram.WithLabelValues(label).Observe(time.Since(start).Seconds())
	}()

	// Process each affected region respectively
	for !bytes.Equal(startKey, endKey) {
		var resp *tikvrpc.Response
		var actualEndKey []byte
		resp, actualEndKey, err = c.sendDeleteRangeReq(startKey, endKey)
		if err != nil {
			return errors.Trace(err)
		}
		cmdResp := resp.RawDeleteRange
		if cmdResp == nil {
			return errors.Trace(ErrBodyMissing)
		}
		if cmdResp.GetError() != "" {
			return errors.New(cmdResp.GetError())
		}
		startKey = actualEndKey
	}

	return nil
}
169937
func MinuteInRange(t time.Time, minMinute, maxMinute int) bool {
	return (minMinute <= t.Minute()) && (t.Minute() <= maxMinute)
}
143373
func NewTimedRotatingFileHandler(
	filepath string,
	mode int,
	bufferSize int,
	when string,
	interval uint32,
	backupCount uint32,
	utc bool) (*TimedRotatingFileHandler, error) {

	var timeInterval time.Duration
	var suffix, extMatch string
	var weekday int
	// Calculate the real rollover interval, which is just the number seconds
	// between rollovers. Also set the filename suffix used when a rollover
	// occurs. Current 'when' events supported:
	// S - Seconds
	// M - Minutes
	// H - Hours
	// D - Days
	// midnight - roll over at midnight
	// W{0-6} - roll over on a certain weekday; 0 - Monday
	// Case of the 'when' specifier is not important; lower or upper case
	// will work.
	when = strings.ToUpper(when)
	switch {
	case when == "S":
		timeInterval = time.Second
		suffix = "%Y-%m-%d_%H-%M-%S"
		extMatch = `^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}$`
	case when == "M":
		timeInterval = time.Minute
		suffix = "%Y-%m-%d_%H-%M"
		extMatch = `^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}$`
	case when == "H":
		timeInterval = time.Hour
		suffix = "%Y-%m-%d_%H"
		extMatch = `^\d{4}-\d{2}-\d{2}_\d{2}$`
	case (when == "D") || (when == "MIDNIGHT"):
		timeInterval = Day
		suffix = "%Y-%m-%d"
		extMatch = `^\d{4}-\d{2}-\d{2}$`
	case strings.HasPrefix(when, "W"):
		timeInterval = Week
		if len(when) != 2 {
			return nil, ErrorInvalidFormat
		}
		dayChar := when[1]
		if (dayChar < '0') || (dayChar > '6') {
			return nil, ErrorInvalidFormat
		}
		// cast Python style index value to Golang style index value
		weekday = (int(dayChar-'0') + 1) % 7
		suffix = "%Y-%m-%d"
		extMatch = `^\d{4}-\d{2}-\d{2}$`
	default:
		return nil, ErrorInvalidFormat
	}
	timeInterval = time.Duration(int64(timeInterval) * int64(interval))
	baseHandler, err := NewBaseRotatingHandler(filepath, mode, bufferSize)
	if err != nil {
		return nil, err
	}
	fileInfo, err := os.Stat(baseHandler.GetFilePath())
	if err != nil {
		baseHandler.Close()
		return nil, err
	}
	object := &TimedRotatingFileHandler{
		BaseRotatingHandler: baseHandler,
		when:                when,
		weekday:             weekday,
		interval:            timeInterval,
		backupCount:         backupCount,
		suffix:              suffix,
		extMatch:            extMatch,
		utc:                 utc,
	}
	object.rolloverTime = object.computeRolloverTime(fileInfo.ModTime())
	return object, nil
}
1258018
func (t *timeRangeMerger) Pop() (out TimeRange, ok bool) {
	var where *[]TimeRange
	var what []TimeRange

	if len(t.sorted) > 0 {
		where, what = &t.sorted, t.sorted[1:]
		out, ok = t.sorted[0], true
	}

	if len(t.unsorted) > 0 && (!ok || t.unsorted[0].Less(out)) {
		where, what = &t.unsorted, t.unsorted[1:]
		out, ok = t.unsorted[0], true
	}

	if !t.used && (!ok || t.single.Less(out)) {
		t.used = true
		return t.single, true
	}

	if ok {
		*where = what
	}

	return out, ok
}
1128047
func (p *Prefix) Overlaps(q *Prefix) bool {
	return p.Contains(q) || q.Contains(p) || p.Equal(q)
}
755708
func (bc *bitmapContainer) iremoveRange(firstOfRange, lastOfRange int) container {
	bc.cardinality += resetBitmapRangeAndCardinalityChange(bc.bitmap, firstOfRange, lastOfRange)
	if bc.getCardinality() <= arrayDefaultMaxSize {
		return bc.toArrayContainer()
	}
	return bc
}
822955
func Overlap(a Value, b Size, x Value, y Size) bool {
	return a.LessThan(x.Add(y)) && x.LessThan(a.Add(b))
}
42112
func (t TimeRange) Intersect(other TimeRange) TimeRange {
	if !other.Min.IsZero() {
		if t.Min.IsZero() || other.Min.After(t.Min) {
			t.Min = other.Min
		}
	}
	if !other.Max.IsZero() {
		if t.Max.IsZero() || other.Max.Before(t.Max) {
			t.Max = other.Max
		}
	}
	return t
}
1193802
func (e *IndexEntry) OverlapsTimeRange(min, max int64) bool {
	return e.MinTime <= max && e.MaxTime >= min
}
275746
func (b *EtcdBackend) DeleteRange(ctx context.Context, startKey, endKey []byte) error {
	if len(startKey) == 0 {
		return trace.BadParameter("missing parameter startKey")
	}
	if len(endKey) == 0 {
		return trace.BadParameter("missing parameter endKey")
	}
	start := b.clock.Now()
	_, err := b.client.Delete(ctx, prependPrefix(startKey), clientv3.WithRange(prependPrefix(endKey)))
	writeLatencies.Observe(time.Since(start).Seconds())
	writeRequests.Inc()
	if err != nil {
		return trace.Wrap(convertErr(err))
	}
	return nil
}
769758
func (t *TSMReader) OverlapsKeyPrefixRange(min, max []byte) bool {
	return t.index.OverlapsKeyPrefixRange(min, max)
}
1226431
func (r Rule) overlaps(o Rule) bool {
	if !(r.Layer == o.Layer || o.Layer == "") {
		return false
	}
	if !(r.Attachment == o.Attachment || o.Attachment == "") {
		return false
	}
	// if !(r.Class == o.Class || o.Class == "") {
	// 	return false
	// }
	if !(r.Zoom.combine(o.Zoom).Levels() > 0 || r.Zoom == o.Zoom) {
		return false
	}
	if !filterOverlap(o.Filters, r.Filters) {
		return false
	}
	return true
}
31176
func (t *TSMReader) OverlapsTimeRange(min, max int64) bool {
	return t.index.OverlapsTimeRange(min, max)
}