]> git.saurik.com Git - apple/system_cmds.git/blobdiff - CPPUtil/UtilAbsInterval.hpp
system_cmds-643.30.1.tar.gz
[apple/system_cmds.git] / CPPUtil / UtilAbsInterval.hpp
diff --git a/CPPUtil/UtilAbsInterval.hpp b/CPPUtil/UtilAbsInterval.hpp
new file mode 100644 (file)
index 0000000..4fe9c31
--- /dev/null
@@ -0,0 +1,92 @@
+//
+//  UtilAbsInterval.h
+//  CPPUtil
+//
+//  Created by James McIlree on 4/14/13.
+//  Copyright (c) 2013 Apple. All rights reserved.
+//
+
+#ifndef __CPPUtil__UtilAbsInterval__
+#define __CPPUtil__UtilAbsInterval__
+
+typedef TRange<AbsTime> AbsInterval;
+
+struct AbsIntervalLocationVsAbsTimeComparator {
+       bool operator()(const AbsInterval& activity, const AbsTime& time) const {
+               return activity.location() < time;
+       }
+
+       bool operator()(const AbsTime& time, const AbsInterval& activity) const {
+               return time < activity.location();
+       }
+};
+
+struct AbsIntervalMaxVsAbsTimeComparator {
+       bool operator()(const AbsInterval& activity, const AbsTime& time) const {
+               return activity.max() < time;
+       }
+
+       bool operator()(const AbsTime& time, const AbsInterval& activity) const {
+               return time < activity.max();
+       }
+};
+
+//
+// Takes a vector of sorted non overlapping AbsInterval(s), and a timespan. Returns a pointer to the
+// youngest AbsInterval that intersects the timespan. Returns NULL if no interval intersects.
+//
+// vec: XXXXXXX XXXXXXXX XXXXX XXXXXX
+//  ts:      MMMMMMMMMMMMMMM
+// ret: XXXXXXX
+//
+// ----------------------------------
+//
+// vec:         XXXXXXXX XXXXX XXXXXX
+//  ts:      MMMMMMMMMMMMMMM
+// ret:         XXXXXXXX
+//
+// ----------------------------------
+//
+// vec:                  XXXXX XXXXXX
+//  ts:      MMMMMMMMMMMMMMM
+// ret:                  XXXXX
+//
+// ----------------------------------
+//
+// vec:                        XXXXXX
+//  ts:      MMMMMMMMMMMMMMM
+// ret: NULL
+//
+
+const AbsInterval* interval_beginning_timespan(const std::vector<AbsInterval>& intervals, AbsInterval timespan);
+
+//
+// Takes a vector of sorted non overlapping AbsInterval(s), and a timespan. Returns a pointer to the
+// oldest AbsInterval that intersects the timespan. Returns NULL if no interval intersects.
+//
+// vec: XXXXXXX XXXXXXXX XXXXX XXXXXX
+//  ts:      MMMMMMMMMMMMMMM
+// ret: XXXXXXX
+//
+// ----------------------------------
+//
+// vec:         XXXXXXXX XXXXX XXXXXX
+//  ts:      MMMMMMMMMMMMMMM
+// ret:         XXXXXXXX
+//
+// ----------------------------------
+//
+// vec:                  XXXXX XXXXXX
+//  ts:      MMMMMMMMMMMMMMM
+// ret:                  XXXXX
+//
+// ----------------------------------
+//
+// vec:                        XXXXXX
+//  ts:      MMMMMMMMMMMMMMM
+// ret: NULL
+//
+
+const AbsInterval* interval_ending_timespan(const std::vector<AbsInterval>& intervals, AbsInterval timespan);
+
+#endif /* defined(__CPPUtil__UtilAbsInterval__) */