2024-05-25 11:16:37 +02:00
|
|
|
using ServicePoint.BindGen;
|
2024-05-13 00:17:40 +02:00
|
|
|
|
2024-05-25 11:16:37 +02:00
|
|
|
namespace ServicePoint;
|
2024-05-13 00:17:40 +02:00
|
|
|
|
2024-10-16 21:59:35 +02:00
|
|
|
public sealed class BitVec : SpNativeInstance<SPBitVec>
|
2024-05-13 00:17:40 +02:00
|
|
|
{
|
2024-10-16 20:56:55 +02:00
|
|
|
public static BitVec New(nuint size)
|
2024-05-13 00:17:40 +02:00
|
|
|
{
|
|
|
|
unsafe
|
|
|
|
{
|
2024-10-16 21:59:35 +02:00
|
|
|
return new BitVec(BitVecNative.sp_bitvec_new(size));
|
2024-05-13 00:17:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static BitVec Load(Span<byte> bytes)
|
|
|
|
{
|
|
|
|
unsafe
|
|
|
|
{
|
|
|
|
fixed (byte* bytesPtr = bytes)
|
|
|
|
{
|
2024-10-16 21:59:35 +02:00
|
|
|
return new BitVec(BitVecNative.sp_bitvec_load(bytesPtr, (nuint)bytes.Length));
|
2024-05-13 00:17:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public BitVec Clone()
|
|
|
|
{
|
|
|
|
unsafe
|
|
|
|
{
|
2024-10-16 21:59:35 +02:00
|
|
|
return new BitVec(BitVecNative.sp_bitvec_clone(Instance));
|
2024-05-13 00:17:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-16 20:56:55 +02:00
|
|
|
public bool this[nuint index]
|
2024-05-13 00:17:40 +02:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
unsafe
|
|
|
|
{
|
2024-10-16 21:59:35 +02:00
|
|
|
return BitVecNative.sp_bitvec_get(Instance, index);
|
2024-05-13 00:17:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
unsafe
|
|
|
|
{
|
2024-10-16 21:59:35 +02:00
|
|
|
BitVecNative.sp_bitvec_set(Instance, index, value);
|
2024-05-13 00:17:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Fill(bool value)
|
|
|
|
{
|
|
|
|
unsafe
|
|
|
|
{
|
2024-10-16 21:59:35 +02:00
|
|
|
BitVecNative.sp_bitvec_fill(Instance, value);
|
2024-05-13 00:17:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-16 20:56:55 +02:00
|
|
|
public nuint Length
|
2024-05-13 00:17:40 +02:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
unsafe
|
|
|
|
{
|
2024-10-16 21:59:35 +02:00
|
|
|
return BitVecNative.sp_bitvec_len(Instance);
|
2024-05-13 00:17:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-15 20:34:51 +02:00
|
|
|
public Span<byte> Data
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
unsafe
|
|
|
|
{
|
2024-10-16 21:59:35 +02:00
|
|
|
var slice = BitVecNative.sp_bitvec_unsafe_data_ref(Instance);
|
2024-05-15 20:34:51 +02:00
|
|
|
return new Span<byte>(slice.start, (int)slice.length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-16 21:59:35 +02:00
|
|
|
private unsafe BitVec(SPBitVec* instance) : base(instance)
|
2024-05-13 00:17:40 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-10-16 21:59:35 +02:00
|
|
|
private protected override unsafe void Free() => BitVecNative.sp_bitvec_free(Instance);
|
2024-05-13 00:17:40 +02:00
|
|
|
}
|