Skip to content

Commit

Permalink
code style preferences, EnforceCodeStyleInBuild, GenerateDocumentatio…
Browse files Browse the repository at this point in the history
…nFile, embedded DebugType,
  • Loading branch information
k-wojcik committed Aug 29, 2024
1 parent ca17f44 commit d524a1e
Show file tree
Hide file tree
Showing 46 changed files with 1,210 additions and 1,171 deletions.
34 changes: 31 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@
# Code files
[*.{cs}]
root = true

[*.cs]

# Organize usings
dotnet_sort_system_directives_first = true
dotnet_separate_import_directive_groups = false


# Simplify name (IDE0001)
dotnet_diagnostic.IDE0001.severity = warning

# 'var' preferences (IDE0007 and IDE0008)
dotnet_diagnostic.IDE0008.severity = warning
csharp_style_var_elsewhere = false:warning
csharp_style_var_for_built_in_types = true:warning
csharp_style_var_when_type_is_apparent = true:warning

# Add braces (IDE0011)
dotnet_diagnostic.IDE0011.severity = warning

# Add accessibility modifiers (IDE0040)
dotnet_diagnostic.IDE0040.severity = warning

# Formatting rule (IDE0055)
dotnet_diagnostic.IDE0055.severity = warning

# Use simple 'using' statement (IDE0063)
dotnet_diagnostic.IDE0063.severity = warning

# Simplify new expression (IDE0090)
dotnet_diagnostic.IDE0090.severity = warning

# Namespace declaration preferences (IDE0160 and IDE0161)
dotnet_diagnostic.IDE0161.severity = warning
csharp_style_namespace_declarations = file_scoped:warning

# Use LibraryImportAttribute instead of DllImportAttribute to generate p/invoke marshalling code at compile time. (SYSLIB1054)
dotnet_diagnostic.SYSLIB1054.severity = warning
dotnet_diagnostic.SYSLIB1054.severity = warning

# Missing XML comment for publicly visible type or member 'Type_or_Member'
dotnet_diagnostic.CS1591.severity = suggestion
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<PropertyGroup>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
Expand Down
6 changes: 3 additions & 3 deletions src/Roaring.Net/CRoaring/BulkContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Roaring.Net.CRoaring;
public sealed unsafe class BulkContext : IDisposable
{
internal Roaring32BitmapBase Bitmap { get; }

internal readonly IntPtr Pointer;

private bool _isDisposed;
Expand All @@ -28,9 +28,9 @@ private void Dispose(bool disposing)
{
return;
}

Marshal.FreeHGlobal(Pointer);

_isDisposed = true;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Roaring.Net/CRoaring/BulkContextInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace Roaring.Net.CRoaring;
internal struct BulkContextInternal
{
public readonly IntPtr container;

public readonly int idx;

public readonly ushort key;

public readonly byte typecode;
}
77 changes: 38 additions & 39 deletions src/Roaring.Net/CRoaring/FrozenRoaring32Bitmap.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.InteropServices;

namespace Roaring.Net.CRoaring;

public unsafe class FrozenRoaring32Bitmap : Roaring32BitmapBase, IReadOnlyRoaring32Bitmap
{
internal Roaring32BitmapMemory Memory { get; }

private readonly Roaring32Bitmap _bitmap;
private bool _isDisposed;

Expand All @@ -19,89 +17,90 @@ public unsafe class FrozenRoaring32Bitmap : Roaring32BitmapBase, IReadOnlyRoarin

internal FrozenRoaring32Bitmap(Roaring32Bitmap bitmap)
{
var size = bitmap.GetSerializationBytes(SerializationFormat.Frozen);
nuint size = bitmap.GetSerializationBytes(SerializationFormat.Frozen);
Memory = new Roaring32BitmapMemory(size);
_bitmap = bitmap.GetFrozenView(size, Memory.MemoryPtr);

Pointer = _bitmap.Pointer;
}

internal FrozenRoaring32Bitmap(IntPtr pointer, Roaring32BitmapMemory memory)
{
Pointer = pointer;
Memory = memory;

_bitmap = new Roaring32Bitmap(pointer);
}

protected override void Dispose(bool disposing)
{
if (_isDisposed)
{
return;
}

_bitmap.Dispose();
Memory.Release(this);

_isDisposed = true;
}

~FrozenRoaring32Bitmap() => Dispose(false);

public bool Contains(uint value) => _bitmap.Contains(value);

public bool ContainsBulk(BulkContext context, uint value)
{
if (context.Bitmap != this)
{
throw new ArgumentException(ExceptionMessages.BulkContextBelongsToOtherBitmap, nameof(context));
}

return NativeMethods.roaring_bitmap_contains_bulk(Pointer, context.Pointer, value);
}

public bool ContainsRange(uint start, uint end) => _bitmap.ContainsRange(start, end);

public bool ValueEquals(Roaring32BitmapBase? bitmap) => _bitmap.ValueEquals(bitmap);

public bool IsSubsetOf(Roaring32BitmapBase? bitmap) => _bitmap.IsSubsetOf(bitmap);

public bool IsProperSubsetOf(Roaring32BitmapBase? bitmap) => _bitmap.IsProperSubsetOf(bitmap);

public bool IsSupersetOf(Roaring32BitmapBase? bitmap) => _bitmap.IsSupersetOf(bitmap);
public bool IsProperSupersetOf(Roaring32BitmapBase? bitmap) => _bitmap.IsProperSupersetOf(bitmap);

public bool IsProperSupersetOf(Roaring32BitmapBase? bitmap) => _bitmap.IsProperSupersetOf(bitmap);

public bool TryGetValue(uint index, out uint value) => _bitmap.TryGetValue(index, out value);

public long GetIndex(uint value) => _bitmap.GetIndex(value);

public ulong CountLessOrEqualTo(uint value) => _bitmap.CountLessOrEqualTo(value);

public ulong[] CountManyLessOrEqualTo(uint[] values) => _bitmap.CountManyLessOrEqualTo(values);

public ulong CountRange(uint start, uint end) => _bitmap.CountRange(start, end);

public Roaring32Bitmap Not() => _bitmap.Not();

public Roaring32Bitmap NotRange(uint start, uint end) => _bitmap.NotRange(start, end);

public Roaring32Bitmap And(Roaring32BitmapBase bitmap) => _bitmap.And(bitmap);

public ulong AndCount(Roaring32BitmapBase bitmap) => _bitmap.AndCount(bitmap);

public Roaring32Bitmap AndNot(Roaring32BitmapBase bitmap) => _bitmap.AndNot(bitmap);

public ulong AndNotCount(Roaring32BitmapBase bitmap) => _bitmap.AndNotCount(bitmap);

public Roaring32Bitmap Or(Roaring32BitmapBase bitmap) => _bitmap.Or(bitmap);

public ulong OrCount(Roaring32BitmapBase bitmap) => _bitmap.OrCount(bitmap);

public Roaring32Bitmap OrMany(Roaring32BitmapBase[] bitmaps) => _bitmap.OrMany(bitmaps);

public Roaring32Bitmap OrManyHeap(Roaring32BitmapBase[] bitmaps) => _bitmap.OrManyHeap(bitmaps);

public Roaring32Bitmap LazyOr(Roaring32BitmapBase bitmap, bool bitsetConversion) => _bitmap.LazyOr(bitmap, bitsetConversion);

public Roaring32Bitmap Xor(Roaring32BitmapBase bitmap) => _bitmap.Xor(bitmap);
Expand All @@ -113,30 +112,30 @@ public bool ContainsBulk(BulkContext context, uint value)
public Roaring32Bitmap LazyXor(Roaring32BitmapBase bitmap) => _bitmap.LazyXor(bitmap);

public bool Overlaps(Roaring32BitmapBase bitmap) => _bitmap.Overlaps(bitmap);

public bool OverlapsRange(uint start, uint end) => _bitmap.OverlapsRange(start, end);

public double GetJaccardIndex(Roaring32BitmapBase bitmap) => _bitmap.GetJaccardIndex(bitmap);

public void CopyTo(uint[] buffer) => _bitmap.CopyTo(buffer);

public IEnumerable<uint> Values => _bitmap.Values;

public uint[] ToArray() => _bitmap.ToArray();

public Roaring32Bitmap ToBitmap() => _bitmap.Clone();

public Roaring32Bitmap ToBitmapWithOffset(long offset) => _bitmap.CloneWithOffset(offset);

public nuint GetSerializationBytes(SerializationFormat format = SerializationFormat.Normal) => _bitmap.GetSerializationBytes(format);

public byte[] Serialize(SerializationFormat format = SerializationFormat.Normal) => _bitmap.Serialize(format);

public uint[] Take(ulong count) => _bitmap.Take(count);

public Statistics GetStatistics() => _bitmap.GetStatistics();

public bool IsValid() => _bitmap.IsValid();

public bool IsValid(out string? reason) => _bitmap.IsValid(out reason);
}
28 changes: 14 additions & 14 deletions src/Roaring.Net/CRoaring/IReadOnlyRoaring32Bitmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ namespace Roaring.Net.CRoaring;
internal interface IReadOnlyRoaring32Bitmap : IDisposable
{
ulong Count { get; }

bool IsEmpty { get; }

uint? Min { get; }

uint? Max { get; }

Roaring32Bitmap Not();

Roaring32Bitmap NotRange(uint start, uint end);

Roaring32Bitmap And(Roaring32BitmapBase bitmap);

ulong AndCount(Roaring32BitmapBase bitmap);

Roaring32Bitmap AndNot(Roaring32BitmapBase bitmap);

ulong AndNotCount(Roaring32BitmapBase bitmap);

Roaring32Bitmap Or(Roaring32BitmapBase bitmap);
Expand Down Expand Up @@ -52,19 +52,19 @@ internal interface IReadOnlyRoaring32Bitmap : IDisposable
bool Contains(uint value);

bool ContainsBulk(BulkContext context, uint value);

bool ContainsRange(uint start, uint end);

bool ValueEquals(Roaring32BitmapBase? bitmap);

bool IsSubsetOf(Roaring32BitmapBase? bitmap);

bool IsProperSubsetOf(Roaring32BitmapBase? bitmap);

bool IsSupersetOf(Roaring32BitmapBase? bitmap);

bool IsProperSupersetOf(Roaring32BitmapBase? bitmap);

bool TryGetValue(uint index, out uint value);

long GetIndex(uint value);
Expand All @@ -76,7 +76,7 @@ internal interface IReadOnlyRoaring32Bitmap : IDisposable
ulong CountRange(uint start, uint end);

void CopyTo(uint[] buffer);

IEnumerable<uint> Values { get; }

uint[] ToArray();
Expand All @@ -86,9 +86,9 @@ internal interface IReadOnlyRoaring32Bitmap : IDisposable
nuint GetSerializationBytes(SerializationFormat format = SerializationFormat.Normal);

byte[] Serialize(SerializationFormat format = SerializationFormat.Normal);

Statistics GetStatistics();

bool IsValid();

bool IsValid(out string? reason);
Expand Down
Loading

0 comments on commit d524a1e

Please sign in to comment.