From 0837ac27d18622c56d6fa50ea653f1ec5d3fd72b Mon Sep 17 00:00:00 2001 From: Christian Luksch Date: Wed, 9 Oct 2024 18:17:40 +0200 Subject: [PATCH] [CSharp] fixed AdaptiveHashSet.OfListTree/OfSetTree creators being extensions [FSharp] added ASet.toAMapIgnoreDuplicates --- src/CSharp.Data.Adaptive/ASet.fs | 22 +++++++++---------- .../CollectionExtensions.fs | 3 +++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/CSharp.Data.Adaptive/ASet.fs b/src/CSharp.Data.Adaptive/ASet.fs index d66c765..4677231 100644 --- a/src/CSharp.Data.Adaptive/ASet.fs +++ b/src/CSharp.Data.Adaptive/ASet.fs @@ -47,6 +47,17 @@ type AdaptiveHashSet private() = [] static member OfHashSet<'T>(set: HashSet<'T>) = ASet.ofHashSet set + + /// Creates an AdaptiveHashSet from a tree of lists + /// NOTE: does not expect duplicates -> TODO + [] + static member OfListTree(list: alist<'TNode>, getChildren : Func<'TNode, alist<'TNode>>) = + list |> ASet.ofListTree getChildren.Invoke + + /// Creates an AdaptiveHashSet from a tree of sets + [] + static member OfSetTree(set: aset<'TNode>, getChildren : Func<'TNode, aset<'TNode>>) = + set |> ASet.ofSetTree getChildren.Invoke [] static member ToAdaptiveHashSet(this: seq<'T>) = ASet.ofSeq this @@ -291,17 +302,6 @@ type AdaptiveHashSet private() = static member ToAdaptiveHashMapIgnoreDuplicates(this: aset<'TValue>, getKey : Func<'TValue, 'TKey>) = this |> AMap.ofASetMappedIgnoreDuplicates getKey.Invoke - /// Creates an AdaptiveHashSet from tree of lists - /// NOTE: does not expect duplicates -> TODO - [] - static member OfListTree(this: alist<'TNode>, getChildren : Func<'TNode, alist<'TNode>>) = - this |> ASet.ofListTree getChildren.Invoke - - /// Creates an AdaptiveHashSet from tree of sets - [] - static member OfSetTree(this: aset<'TNode>, getChildren : Func<'TNode, aset<'TNode>>) = - this |> ASet.ofSetTree getChildren.Invoke - [] static member ToArray(this: aset<'T>) = this |> ASet.force |> HashSet.toArray diff --git a/src/FSharp.Data.Adaptive/CollectionExtensions.fs b/src/FSharp.Data.Adaptive/CollectionExtensions.fs index fed2c2c..7d1e525 100644 --- a/src/FSharp.Data.Adaptive/CollectionExtensions.fs +++ b/src/FSharp.Data.Adaptive/CollectionExtensions.fs @@ -594,6 +594,9 @@ module CollectionExtensions = let ofSetTree<'T> (getChildren : 'T -> aset<'T>) (nodes : aset<'T>) = ASet.ofReader (fun () -> SetTreeReader(nodes, getChildren)) + /// maps the set to amap with the given key mapping and duplicates ignored + let toAMapIgnoreDuplicates (getKey: 'T -> 'K) (set: aset<'T>) = + set |> AMap.ofASetMappedIgnoreDuplicates getKey /// Functional operators for alist<_> []