This repository was archived by the owner on Sep 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathMask.cs
More file actions
59 lines (45 loc) · 1.46 KB
/
Copy pathMask.cs
File metadata and controls
59 lines (45 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Runtime.CompilerServices;
namespace Foster.Framework;
/// <summary>
/// A Struct for managing Masks
/// </summary>
public struct Mask
{
public const ulong All = 0xFFFFFFFFFFFFFFFF;
public const ulong None = 0;
public const ulong Default = (1 << 0);
public ulong Value;
public Mask(ulong value)
{
Value = value;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Add(Mask mask)
{
Value |= mask.Value;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Remove(Mask mask)
{
Value &= ~mask.Value;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Has(Mask mask)
{
return (Value & mask.Value) > 0;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mask Make(int index)
{
if (index < 0 || index > 63)
throw new ArgumentOutOfRangeException(nameof(index), "Index must be between 0 and 63");
return new Mask(((ulong)1 << index));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mask operator |(Mask a, Mask b) => new Mask(a.Value | b.Value);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mask operator &(Mask a, Mask b) => new Mask(a.Value & b.Value);
public static implicit operator ulong(Mask mask) => mask.Value;
public static implicit operator Mask(ulong val) => new Mask(val);
}