public static IEnumerable <SegmentStream> GetStreams(this SparseClusteredArray <byte> sca) { sca.Lock.EnterReadLock(); try { foreach (Segment seg in sca.Segments) { using (var stream = new SegmentStream(seg)) yield return(stream); } } finally { sca.Lock.ExitReadLock(); } }
public static RelativePosition PositionOf <T>( this SparseClusteredArray <T> .IBounds bounds, SparseClusteredArray <T> .IBounds oBounds) { //TODO: Simplify with substraction if (oBounds.Upper < bounds.Lower) { if (oBounds.Upper == bounds.Lower - 1) { return(RelativePosition.BeforeContiguous); } return(RelativePosition.BeforeNoOverlap); } else if (oBounds.Lower > bounds.Upper) { if (oBounds.Lower == bounds.Upper + 1) { return(RelativePosition.AfterContiguous); } return(RelativePosition.AfterNoOverlap); } //!Simplify //TODO: Simplify with substraction else if (oBounds.Lower > bounds.Lower && oBounds.Upper <= bounds.Upper || oBounds.Lower >= bounds.Lower && oBounds.Upper < bounds.Upper) { return(RelativePosition.Within); } else if (oBounds.Lower > bounds.Lower) { return(RelativePosition.AfterOverlap); } else if (oBounds.Upper < bounds.Upper) { return(RelativePosition.BeforeOverlap); } //!Simplify return(RelativePosition.Super); }
public static SegmentStream GetSubsetStream( this SparseClusteredArray <byte> sca, SparseClusteredArray <byte> .IBounds bounds) { (int idx, List <Segment> localSegs) = sca.AcquireReadLock((allSegs) => { (int superIdx, Segment superSeg) = SparseClusteredArray <byte> .FindSuperSegment(allSegs, bounds); return(superIdx, new List <Segment>() { superSeg }); } ); return(idx < 0 ? null : new SegmentStream(localSegs[0], false)); }
public static RelativePosition IsWithin <T>( this SparseClusteredArray <T> .IBounds bounds, int position) { if (position < bounds.Lower) { return(RelativePosition.BeforeNoOverlap); } else if (position > bounds.Upper) { return(RelativePosition.AfterNoOverlap); } else { return(RelativePosition.Within); } }
public static int Length <T>( this SparseClusteredArray <T> .IBounds bounds) { return(bounds.Upper - bounds.Lower + 1); }