public Boolean Overlaps(IVirtualRange <TValue, TOffset> other) { if (!this.Sync(this.From, other.From, this.Offset, other.Offset)) { throw new ArgumentOutOfRangeException("Ranges is not sync."); } return(!((this.From.CompareTo(other.From) == 1 && this.From.CompareTo(other.To) == 1) || (this.To.CompareTo(other.From) == -1 && this.To.CompareTo(other.To) == -1))); }
public Boolean Contains(IVirtualRange <TValue, TOffset> other) { if (!this.Sync(this.From, other.From, this.Offset, other.Offset)) { throw new ArgumentOutOfRangeException("Ranges is not sync."); } return(this.From.CompareTo(other.From) < 1 && this.To.CompareTo(other.To) > -1); }
public virtual Boolean Overlaps(IVirtualRange <TValue, TOffset> range) { if (range == null) { throw new ArgumentNullException("range"); } Int32 index; for (index = 0; index < this.list.Count && this.list[index].To.CompareTo(range.From) == -1; index++) { } return(this.list.Count == index ? false : this.list[index].Overlaps(range)); }
public virtual void Add(IVirtualRange <TValue, TOffset> range) { if (range == null) { throw new ArgumentNullException("range"); } if (this.list.Count == 0) { this.list.Add(range); return; } Int32 fromIndex = 0; Int32 toIndex = 0; for (int i = 0; i < this.list.Count; i++) { if (this.list[i].To.CompareTo(range.From) < 1) { fromIndex = toIndex = i; } if (this.list[i].To.CompareTo(range.To) < 1) { toIndex = i + 1 == this.list.Count ? i : i + 1; } else { break; } } var ranges = new List <IVirtualRange <TValue, TOffset> >() { range }; for (int i = fromIndex; i <= toIndex; i++) { var insertRanges = this.list[i].UnionWith(ranges[ranges.Count - 1]); ranges.RemoveAt(ranges.Count - 1); ranges.AddRange(insertRanges); } for (int i = fromIndex; i <= toIndex; i++) { this.list.RemoveAt(fromIndex); } this.list.InsertRange(fromIndex, ranges); }
public List <IVirtualRange <TValue, TOffset> > ExceptWith(IVirtualRange <TValue, TOffset> other) { if (!this.Sync(this.From, other.From, this.Offset, other.Offset)) { throw new ArgumentOutOfRangeException("Ranges is not sync."); } if (((this.From.CompareTo(other.From) == 1 && this.From.CompareTo(other.To) == 1) || (this.To.CompareTo(other.From) == -1 && this.To.CompareTo(other.To) == -1))) { return(new List <IVirtualRange <TValue, TOffset> >() { this }); } if (this.From.CompareTo(other.From) == -1) { if (other.To.CompareTo(this.To) == -1) { return(new List <IVirtualRange <TValue, TOffset> >() { new VirtualRange <TValue, TOffset>(this.From, (dynamic)other.From - this.offset, this.Offset), new VirtualRange <TValue, TOffset>((dynamic)other.To + this.offset, this.To, this.Offset) }); } else { return(new List <IVirtualRange <TValue, TOffset> >() { new VirtualRange <TValue, TOffset>(this.From, (dynamic)other.From - this.offset, this.Offset) }); } } else { if (other.To.CompareTo(this.To) == -1) { return(new List <IVirtualRange <TValue, TOffset> >() { new VirtualRange <TValue, TOffset>((dynamic)other.To + this.offset, this.To, this.Offset) }); } else { return(new List <IVirtualRange <TValue, TOffset> >()); } } }
public List <IVirtualRange <TValue, TOffset> > IntersectWith(IVirtualRange <TValue, TOffset> other) { if (!this.Sync(this.From, other.From, this.Offset, other.Offset)) { throw new ArgumentOutOfRangeException("Ranges is not sync."); } if (((this.From.CompareTo(other.From) == 1 && this.From.CompareTo(other.To) == 1) || (this.To.CompareTo(other.From) == -1 && this.To.CompareTo(other.To) == -1))) { return(new List <IVirtualRange <TValue, TOffset> >()); } return(new List <IVirtualRange <TValue, TOffset> >() { new VirtualRange <TValue, TOffset>( other.From.CompareTo(this.From) == 1 ? other.From : this.From, other.To.CompareTo(this.To) == 1 ? this.To : other.To, this.Offset) }); }
public List <IVirtualRange <TValue, TOffset> > SymmetricExceptWith(IVirtualRange <TValue, TOffset> other) { if (!this.Sync(this.From, other.From, this.Offset, other.Offset)) { throw new ArgumentOutOfRangeException("Ranges is not sync."); } if (this.From.CompareTo(other.From) == 1 && this.From.CompareTo(other.To) == 1) { return(new List <IVirtualRange <TValue, TOffset> >() { other, this }); } if (this.To.CompareTo(other.From) == -1 && this.To.CompareTo(other.To) == -1) { return(new List <IVirtualRange <TValue, TOffset> >() { this, other }); } switch (this.From.CompareTo(other.From)) { case -1: switch (other.To.CompareTo(this.To)) { case -1: return(new List <IVirtualRange <TValue, TOffset> >() { new VirtualRange <TValue, TOffset>(this.From, (dynamic)other.From - this.offset, this.Offset), new VirtualRange <TValue, TOffset>((dynamic)other.To + this.offset, this.To, this.Offset) }); case 0: return(new List <IVirtualRange <TValue, TOffset> >() { new VirtualRange <TValue, TOffset>(this.From, (dynamic)other.From - this.offset, this.Offset) }); default: return(new List <IVirtualRange <TValue, TOffset> >() { new VirtualRange <TValue, TOffset>(this.From, (dynamic)other.From - this.offset, this.Offset), new VirtualRange <TValue, TOffset>(this.to + this.offset, other.To, this.Offset) }); } case 0: switch (other.To.CompareTo(this.To)) { case -1: return(new List <IVirtualRange <TValue, TOffset> >() { new VirtualRange <TValue, TOffset>((dynamic)other.To + this.offset, this.To, this.Offset) }); case 0: return(new List <IVirtualRange <TValue, TOffset> >()); default: return(new List <IVirtualRange <TValue, TOffset> >() { new VirtualRange <TValue, TOffset>(this.to + this.offset, other.To, this.Offset) }); } default: switch (other.To.CompareTo(this.To)) { case -1: return(new List <IVirtualRange <TValue, TOffset> >() { new VirtualRange <TValue, TOffset>(other.From, this.from - this.offset, this.Offset), new VirtualRange <TValue, TOffset>((dynamic)other.To + this.offset, this.To, this.Offset) }); case 0: return(new List <IVirtualRange <TValue, TOffset> >() { new VirtualRange <TValue, TOffset>(other.From, this.from - this.offset, this.Offset) }); default: return(new List <IVirtualRange <TValue, TOffset> >() { new VirtualRange <TValue, TOffset>(other.From, this.from - this.offset, this.Offset), new VirtualRange <TValue, TOffset>(this.to + this.offset, other.To, this.Offset) }); } } }
public List <IVirtualRange <TValue, TOffset> > UnionWith(IVirtualRange <TValue, TOffset> other) { if (!this.Sync(this.From, other.From, this.Offset, other.Offset)) { throw new ArgumentOutOfRangeException("Ranges is not sync."); } if (this.From.CompareTo(other.From) == -1) { if (other.From.CompareTo(this.To) == 1) { if (this.to + this.offset == (dynamic)other.From) { return(new List <IVirtualRange <TValue, TOffset> >() { new VirtualRange <TValue, TOffset>(this.From, other.To, this.Offset) }); } else { return(new List <IVirtualRange <TValue, TOffset> >() { this, other }); } } else { if (this.To.CompareTo(other.To) == -1) { return(new List <IVirtualRange <TValue, TOffset> >() { new VirtualRange <TValue, TOffset>(this.From, other.To, this.Offset) }); } else { return(new List <IVirtualRange <TValue, TOffset> >() { this }); } } } else { if (this.From.CompareTo(other.To) == 1) { if ((dynamic)other.To + this.offset == this.from) { return(new List <IVirtualRange <TValue, TOffset> >() { new VirtualRange <TValue, TOffset>(other.From, this.To, this.Offset) }); } else { return(new List <IVirtualRange <TValue, TOffset> >() { other, this }); } } else { if (this.To.CompareTo(other.To) == -1) { return(new List <IVirtualRange <TValue, TOffset> >() { other }); } else { return(new List <IVirtualRange <TValue, TOffset> >() { new VirtualRange <TValue, TOffset>(other.From, this.To, this.Offset) }); } } } }
public Int32 CompareTo(IVirtualRange <TValue, TOffset> other) { return(this.comparer(this, other)); }