public void GetSimpleBufferRangeTest() { this.Cache.RangeCollection.AddRange(0, 500); LongRange range_actual = this.Cache.GetNextBufferRange(0); LongRange range_expected = new LongRange(500, this.RemoteFile.Size); Assert.AreEqual(0, range_actual.CompareTo(range_expected)); }
public void GetBufferRangeTest() { this.Cache.RangeCollection.AddRange(0, 500); this.Cache.RangeCollection.AddRange(750, 1500); this.Cache.RangeCollection.AddRange(14323, 15630); LongRange range_actual; LongRange range_expected; range_actual = this.Cache.GetNextBufferRange(500); range_expected = new LongRange(500, 750); Assert.AreEqual(0, range_actual.CompareTo(range_expected)); range_actual = this.Cache.GetNextBufferRange(560); range_expected = new LongRange(560, 750); Assert.AreEqual(0, range_actual.CompareTo(range_expected)); range_actual = this.Cache.GetNextBufferRange(1120); range_expected = new LongRange(1500, 14323); Assert.AreEqual(0, range_actual.CompareTo(range_expected)); range_actual = this.Cache.GetNextBufferRange(14859); range_expected = new LongRange(15630, this.RemoteFile.Size); Assert.AreEqual(0, range_actual.CompareTo(range_expected)); range_actual = this.Cache.GetNextBufferRange(20000); range_expected = new LongRange(20000, this.RemoteFile.Size); Assert.AreEqual(0, range_actual.CompareTo(range_expected)); }
public LongRange GetNextBufferRange(long offset) { if (offset >= this.PutioFile.Size) return null; lock (this.RangeCollection) { LongRange BufferThis = new LongRange(0, this.PutioFile.Size); int index = this.RangeCollection.BinaryIndexSearch(offset); if (index < 0) { BufferThis.Start = offset; index = this.RangeCollection.Bisect(offset); if (index < this.RangeCollection.RangeSet.Count) BufferThis.End = this.RangeCollection.RangeSet.ElementAt(index).Start; else BufferThis.End = this.PutioFile.Size; } else { return this.GetNextBufferRange(this.RangeCollection.RangeSet.ElementAt(index).End); } return BufferThis; } }
/// <summary> /// Return how much is buffered after offset. /// </summary> /// <param name="offset"></param> /// <returns></returns> public long CacheRange(long offset) { LongRange r = this.RangeCollection.BinarySearch(offset); if (r == null) { return(0); } else { return(r.End - offset); } }
/// <summary> /// Check if this object intersects with the given range. /// Start positions are inclusive and End positions are /// exclusive. /// </summary> /// <param name="range"></param> /// <returns></returns> public Boolean Intersects(LongRange range) { if (this.Start == range.Start || this.End == range.End) { return(true); } if (this.Start < range.Start) { return(this.End > range.Start); } else { return(this.Start < range.End); } }
/// <summary> /// Check if this objects comes RIGHT AFTER or RIGHT /// BEFORE the given range. That is. this.Start is equal /// to range.End or vice versa. /// </summary> /// <param name="range"></param> /// <returns></returns> public Boolean IsConsequent(LongRange range) { return(this.End == range.Start || this.Start == range.End); }
/// <summary> /// Try to merge two Ranges. Do nothing if they are /// not consecutive or intersecting ranges. Return true /// if merged, false otherwise. /// </summary> /// <param name="range"></param> public Boolean TryMerge(LongRange range) { if (this.Intersects(range) || this.IsConsequent(range)) { this.Merge(range); return true; } return false; }
/// <summary> /// Merge this LongRange with a one that intersects it. /// </summary> /// <param name="range"></param> public void Merge(LongRange range) { if (!this.Intersects(range) && !this.IsConsequent(range)) throw new Exception("Can't merge two LongRange objects that don't intersect"); this.Start = Math.Min(this.Start, range.Start); this.End = Math.Max(this.End, range.End); }
/// <summary> /// Check if this objects comes RIGHT AFTER or RIGHT /// BEFORE the given range. That is. this.Start is equal /// to range.End or vice versa. /// </summary> /// <param name="range"></param> /// <returns></returns> public Boolean IsConsequent(LongRange range) { return this.End == range.Start || this.Start == range.End; }
/// <summary> /// Check if this object intersects with the given range. /// Start positions are inclusive and End positions are /// exclusive. /// </summary> /// <param name="range"></param> /// <returns></returns> public Boolean Intersects(LongRange range) { if (this.Start == range.Start || this.End == range.End) return true; if (this.Start < range.Start) return this.End > range.Start; else return this.Start < range.End; }
public Boolean IsClosetoHandle(LongRange range, long position) { if (this.Handle.BufferPosition < range.Start) return false; return this.Handle.BufferPosition <= (position + Constants.CHUNK_TOLERANCE); }
public void RangeConstructorTest() { LongRange range = new LongRange(697080622, 697080622 + 1); range.End = 697080622; }