-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jack Dermody
committed
Dec 13, 2024
1 parent
ebe9fcc
commit 9392b75
Showing
13 changed files
with
1,061 additions
and
386 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
|
||
namespace BrightData.Buffer | ||
{ | ||
/// <summary> | ||
/// A range (with an offset and size) of a buffer | ||
/// </summary> | ||
/// <param name="StartOffset">Start position within the buffer</param> | ||
/// <param name="Size">Length within the buffer</param> | ||
public readonly record struct OffsetAndSize(uint StartOffset, uint Size) : IHaveOffset, IHaveSize, IComparable<OffsetAndSize> | ||
{ | ||
/// <summary> | ||
/// Returns the section referenced by this offset and length | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="span">Base buffer</param> | ||
/// <returns></returns> | ||
public ReadOnlySpan<T> GetSpan<T>(ReadOnlySpan<T> span) => span.Slice((int)StartOffset, (int)Size); | ||
|
||
/// <summary> | ||
/// The end offset | ||
/// </summary> | ||
public uint EndOffset => StartOffset + Size; | ||
|
||
/// <summary> | ||
/// Checks if a position is within the range | ||
/// </summary> | ||
/// <param name="position"></param> | ||
/// <returns></returns> | ||
public bool Intersects(uint position) => position >= StartOffset && position < EndOffset; | ||
|
||
/// <summary> | ||
/// Checks if another range intersects | ||
/// </summary> | ||
/// <param name="other"></param> | ||
/// <returns></returns> | ||
public bool Intersects(in OffsetAndSize other) => Intersects(other.StartOffset) || Intersects(other.EndOffset); | ||
|
||
/// <inheritdoc /> | ||
public int CompareTo(OffsetAndSize other) | ||
{ | ||
var ret = StartOffset.CompareTo(other.StartOffset); | ||
if(ret != 0) return ret; | ||
return Size.CompareTo(other.Size); | ||
} | ||
|
||
uint IHaveOffset.Offset => StartOffset; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.