Skip to content

Instantly share code, notes, and snippets.

@jonpryor
Forked from chilversc/Range spec
Created March 12, 2010 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonpryor/330750 to your computer and use it in GitHub Desktop.
Save jonpryor/330750 to your computer and use it in GitHub Desktop.
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<IRange<T>>, IEquatable<IRange<T>> {
T Min { get; }
T Max { get; }
bool IsEmpty { get; }
IEnumerable<IRange<T>> SubRanges();
bool Contains(T value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment