@@ -14,6 +14,7 @@ val interval: IntInterval = interval( 0, 10, isEndIncluded = false )
1414val areIncluded = 0 in interval && 5 in interval // true
1515val areExcluded = 10 !in interval && 15 !in interval // true
1616val size: UInt = interval.size // 10
17+ val shifted = interval shr 10u // Shifted right by 10: [10, 20)
1718```
1819
1920This protects against overflows (e.g. if ` size > Int.MAX_VALUE ` ) but also offers better semantics.
@@ -24,6 +25,7 @@ val now = Clock.System.now()
2425val interval: InstantInterval = interval( now, now + 100 .seconds )
2526val areIncluded = now + 50 .seconds in interval // true
2627val size: Duration = interval.size // 100 seconds
28+ val shifted = interval shr 24 .hours // 100 seconds 24 hours from now
2729```
2830
2931## Interval Unions
@@ -36,6 +38,7 @@ Since operations are generally defined on the base interface, you can easily cha
3638val start = interval( 0 , 100 ) // Interval: [0, 100]
3739val areIncluded = 50 in start && 100 in start // true
3840val splitInTwo = start - interval( 25 , 85 ) // Union: [[0, 25), (85, 100]]
41+ val shiftBackAndForth = splitInTwo shr 100u shl 100u // == splitInTwo
3942val areExcluded = 50 !in splitInTwo && 85 !in splitInTwo // true
4043val unite = splitInTwo + interval( 10 , 90 ) // Interval: [0, 100]
4144val backToStart = start == unite // true
@@ -63,18 +66,18 @@ Instead, new instances are returned if the operation results in a different set
6366
6467The following operations are available for any ` IntervalUnion<T, TSize> ` :
6568
66- | Operation | Description |
67- | :-------------------:| :--------------------------------------------------------------------------------------------:|
68- | ` isEmpty() ` | Determines whether this is an empty set. |
69- | ` getBounds() ` | Gets the upper and lower bound of the set. |
70- | ` contains() ` (` in ` ) | Determines whether a value lies in the set. |
71- | ` minus() ` (` - ` ) | Subtract an interval from the set. |
72- | ` plus() ` (` + ` ) | Add an interval to the set. |
73- | ` shift() ` | Move the interval by a specified offset. |
74- | ` intersects() ` | Determines whether another interval intersects with this set. |
75- | ` setEquals() ` | Determines whether a set represents the same values. |
76- | ` iterator() ` | Iterate over all intervals in the union, in order. |
77- | ` toString() ` | Output as a string using common interval notation, e.g., ` [0, 10] ` or ` [[0, 10), (10, 20]] ` . |
69+ | Operation | Description |
70+ | :----------------------- :| :--------------------------------------------------------------------------------------------:|
71+ | ` isEmpty() ` | Determines whether this is an empty set. |
72+ | ` getBounds() ` | Gets the upper and lower bound of the set. |
73+ | ` contains() ` (` in ` ) | Determines whether a value lies in the set. |
74+ | ` minus() ` (` - ` ) | Subtract an interval from the set. |
75+ | ` plus() ` (` + ` ) | Add an interval to the set. |
76+ | ` shift() ` ( ` shl ` / ` shr ` ) | Move the interval by a specified offset. |
77+ | ` intersects() ` | Determines whether another interval intersects with this set. |
78+ | ` setEquals() ` | Determines whether a set represents the same values. |
79+ | ` iterator() ` | Iterate over all intervals in the union, in order. |
80+ | ` toString() ` | Output as a string using common interval notation, e.g., ` [0, 10] ` or ` [[0, 10), (10, 20]] ` . |
7881
7982The following operations are specific to ` Interval<T, TSize> ` :
8083
0 commit comments