Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaning pc #113

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static double ReadDouble(this IBitReader reader, int bitCount, IFloatingP
{
if (reader == null) throw new ArgumentNullException(nameof(reader));
if (bitCount < IFloatingPointBitReader.MIN_BIT_COUNT) throw new ArgumentOutOfRangeException(nameof(bitCount));
if ((ulong)bitCount > reader.RemainingLength) throw new ArgumentOutOfRangeException(nameof(bitCount));
if (!Enum.IsDefined(floatingPointEncoding)) throw new ArgumentOutOfRangeException(nameof(floatingPointEncoding));

switch (floatingPointEncoding)
Expand Down
25 changes: 23 additions & 2 deletions JBSnorro/Collections/Bits/Internals/BitReaderWithAlongTagger.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace JBSnorro.Collections.Bits.Internals;
using JBSnorro.Diagnostics;

namespace JBSnorro.Collections.Bits.Internals;

/// <summary>
/// A bit reader that reads floating point numbers assuming they're particularly encoded.
Expand All @@ -10,6 +12,19 @@ internal class BitReaderWithAlongTagger : BitReader
public BitReaderWithAlongTagger(BitArray data, ulong position, ulong length, BitReader alongTagger)
: base(data, position, length)
{
Contract.Requires(alongTagger is not null);
#if DEBUG
var set = new HashSet<BitReader>();
for (var a = alongTagger; a != null; a = (a as BitReaderWithAlongTagger)?.alongTagger)
{
if (set.Contains(a))
{
throw new ArgumentException("Infinite loop");
}
set.Add(a);
}
#endif

this.alongTagger = alongTagger;
}

Expand All @@ -21,12 +36,18 @@ protected internal override ulong current
}
set
{
if (this.alongTagger is null)
{
// we're called from the base constructor
base.current = value;
return;
}
unchecked
{
var delta = value - current;
if (delta != 0)
{
this.current = value;
base.current = value;
alongTagger.current += delta;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ internal static double ReadDouble(IBitReader reader, int bitCount)
{
if (bitCount < IFloatingPointBitReader.MIN_BIT_COUNT || bitCount > 64)
throw new ArgumentOutOfRangeException(nameof(bitCount));
if ((ulong)bitCount > reader.RemainingLength)
throw new ArgumentOutOfRangeException(nameof(bitCount));

ulong value = reader.ReadUInt64(bitCount);
if (value == 0)
Expand Down
Loading