Skip to content

Commit

Permalink
Update documentation for DensePartialSort
Browse files Browse the repository at this point in the history
  • Loading branch information
viceroypenguin committed Aug 26, 2023
1 parent 85272c5 commit a359722
Show file tree
Hide file tree
Showing 11 changed files with 630 additions and 117 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
uid: SuperLinq.SuperEnumerable.DensePartialSort``1(System.Collections.Generic.IEnumerable{``0},System.Int32)
example: [*content]
---
The following code example demonstrates how to get the top N items of a sequence using `DensePartialSort`.
[!code-csharp[](SuperLinq/DensePartialSort/DensePartialSort1.linq#L6-)]

---
uid: SuperLinq.SuperEnumerable.DensePartialSort``1(System.Collections.Generic.IEnumerable{``0},System.Int32,SuperLinq.OrderByDirection)
example: [*content]
---
The following code example demonstrates how to get the top N items of a sequence using `DensePartialSort`.
[!code-csharp[](SuperLinq/DensePartialSort/DensePartialSort2.linq#L6-)]

---
uid: SuperLinq.SuperEnumerable.DensePartialSort``1(System.Collections.Generic.IEnumerable{``0},System.Int32,System.Collections.Generic.IComparer{``0})
example: [*content]
---
The following code example demonstrates how to get the top N items of a sequence using `DensePartialSort`.
[!code-csharp[](SuperLinq/DensePartialSort/DensePartialSort3.linq#L6-)]

---
uid: SuperLinq.SuperEnumerable.DensePartialSort``1(System.Collections.Generic.IEnumerable{``0},System.Int32,System.Collections.Generic.IComparer{``0},SuperLinq.OrderByDirection)
example: [*content]
---
The following code example demonstrates how to get the top N items of a sequence using `DensePartialSort`.
[!code-csharp[](SuperLinq/DensePartialSort/DensePartialSort4.linq#L6-)]

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
uid: SuperLinq.SuperEnumerable.DensePartialSortBy``2(System.Collections.Generic.IEnumerable{``0},System.Int32,System.Func{``0,``1})
example: [*content]
---
The following code example demonstrates how to get the top N items of a sequence using `DensePartialSort`.
[!code-csharp[](SuperLinq/DensePartialSortBy/DensePartialSortBy1.linq#L6-)]

---
uid: SuperLinq.SuperEnumerable.DensePartialSortBy``2(System.Collections.Generic.IEnumerable{``0},System.Int32,System.Func{``0,``1},SuperLinq.OrderByDirection)
example: [*content]
---
The following code example demonstrates how to get the top N items of a sequence using `DensePartialSort`.
[!code-csharp[](SuperLinq/DensePartialSortBy/DensePartialSortBy2.linq#L6-)]

---
uid: SuperLinq.SuperEnumerable.DensePartialSortBy``2(System.Collections.Generic.IEnumerable{``0},System.Int32,System.Func{``0,``1},System.Collections.Generic.IComparer{``1})
example: [*content]
---
The following code example demonstrates how to get the top N items of a sequence using `DensePartialSort`.
[!code-csharp[](SuperLinq/DensePartialSortBy/DensePartialSortBy3.linq#L6-)]

---
uid: SuperLinq.SuperEnumerable.DensePartialSortBy``2(System.Collections.Generic.IEnumerable{``0},System.Int32,System.Func{``0,``1},System.Collections.Generic.IComparer{``1},SuperLinq.OrderByDirection)
example: [*content]
---
The following code example demonstrates how to get the top N items of a sequence using `DensePartialSort`.
[!code-csharp[](SuperLinq/DensePartialSortBy/DensePartialSortBy4.linq#L6-)]

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<Query Kind="Statements">
<NuGetReference>SuperLinq</NuGetReference>
<Namespace>SuperLinq</Namespace>
</Query>

var sequence = new Item[]
{
new(key: 5, text: "1"),
new(key: 5, text: "2"),
new(key: 4, text: "3"),
new(key: 4, text: "4"),
new(key: 3, text: "5"),
new(key: 3, text: "6"),
new(key: 2, text: "7"),
new(key: 2, text: "8"),
new(key: 1, text: "9"),
new(key: 1, text: "10"),
};

// Get the top N sets of items
var result = sequence.DensePartialSort(3);

Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");

// This code produces the following output:
// [(1, 9), (1, 10), (2, 7), (2, 8), (3, 5), (3, 6)]

class Item : IComparable<Item>
{
public Item(int key, string text)
{
Key = key;
Text = text;
}

public int Key { get; }
public string Text { get; }

public int CompareTo(Item other) =>
this.Key.CompareTo(other.Key);

public override string ToString() =>
$"({this.Key}, {this.Text})";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<Query Kind="Statements">
<NuGetReference>SuperLinq</NuGetReference>
<Namespace>SuperLinq</Namespace>
</Query>

var sequence = new Item[]
{
new(key: 5, text: "1"),
new(key: 5, text: "2"),
new(key: 4, text: "3"),
new(key: 4, text: "4"),
new(key: 3, text: "5"),
new(key: 3, text: "6"),
new(key: 2, text: "7"),
new(key: 2, text: "8"),
new(key: 1, text: "9"),
new(key: 1, text: "10"),
};

// Get the top N sets of items
var result = sequence.DensePartialSort(3, OrderByDirection.Descending);

Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");

// This code produces the following output:
// [(5, 1), (5, 2), (4, 3), (4, 4), (3, 5), (3, 6)]

class Item : IComparable<Item>
{
public Item(int key, string text)
{
Key = key;
Text = text;
}

public int Key { get; }
public string Text { get; }

public int CompareTo(Item other) =>
this.Key.CompareTo(other.Key);

public override string ToString() =>
$"({this.Key}, {this.Text})";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Query Kind="Statements">
<NuGetReference>SuperLinq</NuGetReference>
<Namespace>SuperLinq</Namespace>
</Query>

var sequence = new[]
{
(key: 5, text: "1"),
(key: 5, text: "2"),
(key: 4, text: "3"),
(key: 4, text: "4"),
(key: 3, text: "5"),
(key: 3, text: "6"),
(key: 2, text: "7"),
(key: 2, text: "8"),
(key: 1, text: "9"),
(key: 1, text: "10"),
};

// Get the top N sets of items
var result = sequence
.DensePartialSort(
3,
Comparer<(int key, string text)>.Create((x, y) => x.key.CompareTo(y.key)));

Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");

// This code produces the following output:
// [(1, 9), (1, 10), (2, 7), (2, 8), (3, 5), (3, 6)]
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<Query Kind="Statements">
<NuGetReference>SuperLinq</NuGetReference>
<Namespace>SuperLinq</Namespace>
</Query>

var sequence = new[]
{
(key: 5, text: "1"),
(key: 5, text: "2"),
(key: 4, text: "3"),
(key: 4, text: "4"),
(key: 3, text: "5"),
(key: 3, text: "6"),
(key: 2, text: "7"),
(key: 2, text: "8"),
(key: 1, text: "9"),
(key: 1, text: "10"),
};

// Get the top N sets of items
var result = sequence
.DensePartialSort(
3,
Comparer<(int key, string text)>.Create((x, y) => x.key.CompareTo(y.key)),
OrderByDirection.Descending);

Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");

// This code produces the following output:
// [(5, 1), (5, 2), (4, 3), (4, 4), (3, 5), (3, 6)]
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Query Kind="Statements">
<NuGetReference>SuperLinq</NuGetReference>
<Namespace>SuperLinq</Namespace>
</Query>

var sequence = new[]
{
(key: 5, text: "1"),
(key: 5, text: "2"),
(key: 4, text: "3"),
(key: 4, text: "4"),
(key: 3, text: "5"),
(key: 3, text: "6"),
(key: 2, text: "7"),
(key: 2, text: "8"),
(key: 1, text: "9"),
(key: 1, text: "10"),
};

// Get the top N sets of items
var result = sequence
.DensePartialSortBy(
3,
x => x.key);

Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");

// This code produces the following output:
// [(1, 9), (1, 10), (2, 7), (2, 8), (3, 5), (3, 6)]
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<Query Kind="Statements">
<NuGetReference>SuperLinq</NuGetReference>
<Namespace>SuperLinq</Namespace>
</Query>

var sequence = new[]
{
(key: 5, text: "1"),
(key: 5, text: "2"),
(key: 4, text: "3"),
(key: 4, text: "4"),
(key: 3, text: "5"),
(key: 3, text: "6"),
(key: 2, text: "7"),
(key: 2, text: "8"),
(key: 1, text: "9"),
(key: 1, text: "10"),
};

// Get the top N sets of items
var result = sequence
.DensePartialSortBy(
3,
x => x.key,
OrderByDirection.Descending);

Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");

// This code produces the following output:
// [(5, 1), (5, 2), (4, 3), (4, 4), (3, 5), (3, 6)]
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<Query Kind="Statements">
<NuGetReference>SuperLinq</NuGetReference>
<Namespace>SuperLinq</Namespace>
</Query>

var sequence = new[]
{
(key: 5, text: "1"),
(key: 5, text: "2"),
(key: 4, text: "3"),
(key: 4, text: "4"),
(key: 3, text: "5"),
(key: 3, text: "6"),
(key: 2, text: "7"),
(key: 2, text: "8"),
(key: 1, text: "9"),
(key: 1, text: "10"),
};

// Get the top N sets of items
var result = sequence
.DensePartialSortBy(
1,
x => x.key,
Comparer<int>.Create((x, y) => (x % 2).CompareTo(y % 2)));

Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");

// This code produces the following output:
// [(4, 3), (4, 4), (2, 7), (2, 8)]
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Query Kind="Statements">
<NuGetReference>SuperLinq</NuGetReference>
<Namespace>SuperLinq</Namespace>
</Query>

var sequence = new[]
{
(key: 5, text: "1"),
(key: 5, text: "2"),
(key: 4, text: "3"),
(key: 4, text: "4"),
(key: 3, text: "5"),
(key: 3, text: "6"),
(key: 2, text: "7"),
(key: 2, text: "8"),
(key: 1, text: "9"),
(key: 1, text: "10"),
};

// Get the top N sets of items
var result = sequence
.DensePartialSortBy(
1,
x => x.key,
Comparer<int>.Create((x, y) => (x % 2).CompareTo(y % 2)),
OrderByDirection.Descending);

Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");

// This code produces the following output:
// [(5, 1), (5, 2), (3, 5), (3, 6), (1, 9), (1, 10)]
Loading

0 comments on commit a359722

Please sign in to comment.