Skip to content

Commit

Permalink
Change new Slice() so C# compiler can infer type arguments
Browse files Browse the repository at this point in the history
Also fix something resembling a bug in BList/BDictionary/BMultiMap
  • Loading branch information
qwertie committed Mar 30, 2020
1 parent 5bdce68 commit bb719c1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Core/AssemblyVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
// command to change the version number which, I guess, produces an incompatible
// assembly in the presence of strong names (strong naming prevents two assemblies
// from linking together without an exact match.)
[assembly: AssemblyVersion("2.7.1.4")]
[assembly: AssemblyFileVersion("2.7.1.4")]
[assembly: AssemblyVersion("2.7.1.5")]
[assembly: AssemblyFileVersion("2.7.1.5")]
18 changes: 17 additions & 1 deletion Core/Loyc.Collections/ALists/BListInner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ protected BListInner(BListInner<K, T> original, uint index, uint count, AListBas
#endregion

/// <summary>Stores the highest key that applies to the node with the same index.</summary>
/// <remarks>The highest key of the rightmost node is not tracked (can't remember
/// why not - maybe just because it is traditional not to track it in B+ trees.)</remarks>
protected K[] _highestKey;

public override long CountSizeInBytes(int sizeOfT, int sizeOfK) =>
Expand Down Expand Up @@ -140,12 +142,26 @@ internal override int DoSingleOperation(ref AListSingleOperation<K, T> op, out A
flagParent = true;
}
}
else if (i + 1 == LocalCount && i > 0 && _children[i].Node.LocalCount == 0)
{ // (2020/03 fix) The last item in the last node was removed, so the highest
// key of this node may have decreased. AssertValid() failed in the parent
// on rare occasions when the max node size was 3, because the parent node
// could have a _highestKey value that was too high. No malfunctions were
// observed as a result, and I'm hard pressed to think of anything that
// could go wrong when the highest-key value is too high but lower than the
// next sibling. Note: don't update _highestKey[i] here because the highest
// key of the final node is never tracked.
Debug.Assert(sizeChange == -1);
flagParent = true;
op.AggregateChanged |= 1;
op.AggregateKey = GetHighestKey(_children[i - 1].Node);
}

if (splitLeft.IsUndersized)
flagParent |= HandleUndersized(i, tob);

if (flagParent)
splitLeft = this;
splitLeft = this; // inform parent about highest-key change or undersized node
else
splitLeft = null;
}
Expand Down
7 changes: 5 additions & 2 deletions Core/Loyc.Essentials/Collections/Adapters/ROLSlice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ namespace Loyc.Collections
{
public static partial class ListExt
{
public static ROLSlice<TList, T> Slice<TList, T>(this TList list, int start, int count = int.MaxValue) where TList : IReadOnlyList<T>
=> new ROLSlice<TList, T>(list, start, count);
// C# generally can't infer the arguments
//public static ROLSlice<TList, T> Slice<TList, T>(this TList list, int start, int count = int.MaxValue) where TList : IReadOnlyList<T>
// => new ROLSlice<TList, T>(list, start, count);
public static ROLSlice<IReadOnlyList<T>, T> Slice<T>(this IReadOnlyList<T> list, int start, int count = int.MaxValue)
=> new ROLSlice<IReadOnlyList<T>, T>(list, start, count);
}

/// <summary>Adapter: a random-access range for a slice of an <see cref="IReadOnlyList{T}"/>.</summary>
Expand Down
4 changes: 2 additions & 2 deletions Main/LeMP/MacroProcessorTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -770,15 +770,15 @@ private void GetApplicableMacros(LNode curNode, List<InternalMacroInfo> foundMac
for (j = i + 1; j < foundMacros.Count; j++)
if (foundMacros[j].Attr.Priority != p)
break;
var newNode = ApplyMacrosFound2(s, foundMacros.Slice(i, j - i));
var newNode = ApplyMacrosFound2(s, ((IList<InternalMacroInfo>)foundMacros).Slice(i, j - i));
if (newNode != null)
return newNode;
}
return null;
}
}
}
return ApplyMacrosFound2(s, foundMacros.Slice(0));
return ApplyMacrosFound2(s, ((IList<InternalMacroInfo>)foundMacros).Slice(0));
}

private MacroResult? ApplyMacrosFound2(CurNodeState s, ListSlice<InternalMacroInfo> foundMacros)
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ before_build:
build_script:
# First, set some environment variables.
# SEMVER is set manually. Not sure how this can be automated.
- set SEMVER=27.1.4
- set SEMVER=27.1.5
- echo %APPVEYOR_REPO_TAG%
# Build packages as SEMVER-ci{build}
- ps: if ($env:APPVEYOR_REPO_TAG -eq $True) { $env:PKG_VERSION = $env:SEMVER; } else { $env:PKG_VERSION = "$($env:SEMVER)-ci$($env:APPVEYOR_BUILD_NUMBER)"; }
Expand Down

0 comments on commit bb719c1

Please sign in to comment.