-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to produce correct output for platform based generation. (#8)
- Loading branch information
1 parent
8a49eb7
commit 388e2c7
Showing
23 changed files
with
65,424 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Pharmacist.Core.Utilities | ||
{ | ||
/// <summary> | ||
/// Extension methods for stack based operations. | ||
/// </summary> | ||
internal static class StackExtensions | ||
{ | ||
public static void PushRange<T>(this Stack<T> stack, IEnumerable<T> items) | ||
{ | ||
foreach (var item in items) | ||
{ | ||
stack.Push(item); | ||
} | ||
} | ||
|
||
public static int TryPopRange<T>(this Stack<T> stack, T[] items) | ||
{ | ||
return TryPopRange(stack, items, 0, items.Length); | ||
} | ||
|
||
public static int TryPopRange<T>(this Stack<T> stack, T[] items, int startIndex, int count) | ||
{ | ||
if (items == null) | ||
{ | ||
throw new ArgumentNullException(nameof(items)); | ||
} | ||
|
||
if (count < 0) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(count), "The count must be greater than 0."); | ||
} | ||
|
||
int length = items.Length; | ||
if (startIndex >= length || startIndex < 0) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(startIndex), "The start index is out of range. It must between 0 and less than the length of the array."); | ||
} | ||
|
||
if (length - count < startIndex) | ||
{ | ||
// instead of (startIndex + count > items.Length) to prevent overflow | ||
throw new ArgumentException("The start index is out of range. It must between 0 and less than the length of the array."); | ||
} | ||
|
||
if (count == 0) | ||
{ | ||
return 0; | ||
} | ||
|
||
int nodesCount = stack.Count > count ? count : stack.Count; | ||
|
||
for (int i = startIndex; i < startIndex + nodesCount; i++) | ||
{ | ||
items[i] = stack.Pop(); | ||
} | ||
|
||
return nodesCount; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.