Skip to content

Instantly share code, notes, and snippets.

@chilversc
Created March 12, 2010 20:03
Show Gist options
  • Save chilversc/330722 to your computer and use it in GitHub Desktop.
Save chilversc/330722 to your computer and use it in GitHub Desktop.
Range spec
Range:
Min/Max rather than Start/End, better naming when dealing with non-contiguous ranges.
Start and end values are inclusive.
How enumeration works for stepping, etc is left to the class to decide, provide a static class with some standard implementations that use Math<T>.
Assumption is the main IRange<T> can be either contiguous or non-contiguous
Assumptions for SubRanges():
No two sub-ranges overlap.
Each sub-range is atomic (ie contiguous).
Sub-ranges are returned in order of their Min value.
No sub-range is ever empty.
Min/Max throw an InvalidOperationException if IsEmpty == true.
interface IRange<T> : ISet<T>, IEquatable<IRange<T>> {
T Min();
T Max();
bool IsEmpty { get; }
IEnumerable<IRange<T>> SubRanges();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment