From a5ff3f6970377f9abc1d03a575018952788c228d Mon Sep 17 00:00:00 2001 From: Alexey Kulakov Date: Tue, 21 Nov 2023 16:49:47 +0500 Subject: [PATCH 1/3] Returns results as expected --- Orm/Xtensive.Orm/Sorting/TopologicalSorter.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Orm/Xtensive.Orm/Sorting/TopologicalSorter.cs b/Orm/Xtensive.Orm/Sorting/TopologicalSorter.cs index 0a30a6b5e0..7f5b097afb 100644 --- a/Orm/Xtensive.Orm/Sorting/TopologicalSorter.cs +++ b/Orm/Xtensive.Orm/Sorting/TopologicalSorter.cs @@ -183,7 +183,13 @@ public static IReadOnlyList SortToList( /// In this case will contain only the loop edges. public static IEnumerable Sort( List> nodes, - out List> loops) => SortInternal(nodes, out loops).sorted ?? Array.Empty(); + out List> loops) + { + var (sorted, count) = SortInternal(nodes, out loops) /* ?? Array.Empty()*/; + return (sorted is not null && count == 0) + ? Array.Empty() + : sorted; + } /// /// Sorts the specified oriented graph of the nodes in their topological order @@ -199,9 +205,11 @@ public static IReadOnlyList SortToList( out List> loops) { var (sorted, count) = SortInternal(nodes, out loops); - return (sorted is null || count == 0) - ? Array.Empty() - : sorted.ToArray(count); + return (sorted is null) + ? null + : count == 0 + ? Array.Empty() + : sorted.ToArray(count); } /// From 01b28dcf1d27ad2077a58a545538cdc00bc4aad4 Mon Sep 17 00:00:00 2001 From: Alexey Kulakov Date: Tue, 21 Nov 2023 16:59:51 +0500 Subject: [PATCH 2/3] TopologicalSorter:Added annotations to return types --- Orm/Xtensive.Orm/Sorting/TopologicalSorter.cs | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Orm/Xtensive.Orm/Sorting/TopologicalSorter.cs b/Orm/Xtensive.Orm/Sorting/TopologicalSorter.cs index 7f5b097afb..282ee03543 100644 --- a/Orm/Xtensive.Orm/Sorting/TopologicalSorter.cs +++ b/Orm/Xtensive.Orm/Sorting/TopologicalSorter.cs @@ -9,7 +9,9 @@ using Xtensive.Collections; using System.Linq; using Xtensive.Core; - +using DotNetNotNullAttribute = System.Diagnostics.CodeAnalysis.NotNullAttribute; +using JBNotNullAttribute = JetBrains.Annotations.NotNullAttribute; +using JBCanBeNullAttribute = JetBrains.Annotations.CanBeNullAttribute; namespace Xtensive.Sorting { @@ -29,6 +31,7 @@ public static class TopologicalSorter /// Sorting result, if there were no loops; /// otherwise, . /// + [JBCanBeNull] public static IEnumerable Sort(IEnumerable items, Predicate connector) => Sort(items, connector, out List> loops); @@ -43,6 +46,7 @@ public static IEnumerable Sort(IEnumerable item /// Sorting result, if there were no loops; /// otherwise, . /// + [JBCanBeNull] public static IReadOnlyList SortToList(IEnumerable items, Predicate connector) => SortToList(items, connector, out List> loops); @@ -59,6 +63,7 @@ public static IReadOnlyList SortToList(IEnumerable. /// In this case will contain only the loop edges. /// + [JBCanBeNull] public static IEnumerable Sort( IEnumerable items, Predicate connector, @@ -83,6 +88,7 @@ public static IEnumerable Sort( /// otherwise, . /// In this case will contain only the loop edges. /// + [JBCanBeNull] public static IReadOnlyList SortToList( IEnumerable items, Predicate connector, @@ -105,6 +111,8 @@ public static IReadOnlyList SortToList( /// /// Sorting result /// + [return: DotNetNotNull] + [JBNotNull] public static IEnumerable Sort( IEnumerable items, Predicate connector, @@ -121,6 +129,8 @@ public static IEnumerable Sort( /// /// Sorting result /// + [return: DotNetNotNull] + [JBNotNull] public static IReadOnlyList SortToList( IEnumerable items, Predicate connector, @@ -138,6 +148,8 @@ public static IReadOnlyList SortToList( /// /// Sorting result /// + [return: DotNetNotNull] + [JBNotNull] public static IEnumerable Sort( IEnumerable items, Predicate connector, @@ -161,6 +173,8 @@ public static IEnumerable Sort( /// /// Sorting result /// + [return: DotNetNotNull] + [JBNotNull] public static IReadOnlyList SortToList( IEnumerable items, Predicate connector, @@ -181,6 +195,7 @@ public static IReadOnlyList SortToList( /// Sorting result, if there were no loops; /// otherwise, . /// In this case will contain only the loop edges. + [JBCanBeNull] public static IEnumerable Sort( List> nodes, out List> loops) @@ -200,6 +215,7 @@ public static IEnumerable Sort( /// Sorting result, if there were no loops; /// otherwise, . /// In this case will contain only the loop edges. + [JBCanBeNull] public static IReadOnlyList SortToList( List> nodes, out List> loops) @@ -219,6 +235,8 @@ public static IReadOnlyList SortToList( /// The nodes. /// Edges removed to make graph non-cyclic. /// Sorting result. + [return: DotNetNotNull] + [JBNotNull] public static IEnumerable Sort( IEnumerable> nodes, out List> removedEdges) => @@ -231,6 +249,8 @@ public static IEnumerable Sort( /// The nodes. /// Edges removed to make graph non-cyclic. /// Sorting result. + [return: DotNetNotNull] + [JBNotNull] public static IReadOnlyList SortToList( IEnumerable> nodes, out List> removedEdges) => @@ -244,6 +264,8 @@ public static IReadOnlyList SortToList( /// Edges removed to make graph non-cyclic. /// If removes whole node in the case of loop, otherwise removes only one edge. /// Sorting result. + [return: DotNetNotNull] + [JBNotNull] public static IEnumerable Sort( IEnumerable> nodes, out List> removedEdges, @@ -258,6 +280,8 @@ public static IEnumerable Sort( /// Edges removed to make graph non-cyclic. /// If removes whole node in the case of loop, otherwise removes only one edge. /// Sorting result. + [return: DotNetNotNull] + [JBNotNull] public static IReadOnlyList SortToList( IEnumerable> nodes, out List> removedEdges, From 44069b369d7e34d5b3997b57d1e493fedd9e9a91 Mon Sep 17 00:00:00 2001 From: Alexey Kulakov Date: Wed, 22 Nov 2023 19:16:25 +0500 Subject: [PATCH 3/3] Improve changelog --- ChangeLog/7.1.2_dev.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog/7.1.2_dev.txt b/ChangeLog/7.1.2_dev.txt index e69de29bb2..78b15d4fc6 100644 --- a/ChangeLog/7.1.2_dev.txt +++ b/ChangeLog/7.1.2_dev.txt @@ -0,0 +1 @@ +[main] Addressed issue when cycles in Entity dependency graph were not detected \ No newline at end of file