Skip to content

Commit

Permalink
[CSharp] fixed AdaptiveHashSet.OfListTree/OfSetTree creators being ex…
Browse files Browse the repository at this point in the history
…tensions

[FSharp] added ASet.toAMapIgnoreDuplicates
  • Loading branch information
luithefirst committed Oct 9, 2024
1 parent 8641112 commit 0837ac2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/CSharp.Data.Adaptive/ASet.fs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ type AdaptiveHashSet private() =

[<MethodImpl(MethodImplOptions.AggressiveInlining)>]
static member OfHashSet<'T>(set: HashSet<'T>) = ASet.ofHashSet set

/// Creates an AdaptiveHashSet from a tree of lists
/// NOTE: does not expect duplicates -> TODO
[<MethodImpl(MethodImplOptions.AggressiveInlining)>]
static member OfListTree(list: alist<'TNode>, getChildren : Func<'TNode, alist<'TNode>>) =
list |> ASet.ofListTree getChildren.Invoke

/// Creates an AdaptiveHashSet from a tree of sets
[<MethodImpl(MethodImplOptions.AggressiveInlining)>]
static member OfSetTree(set: aset<'TNode>, getChildren : Func<'TNode, aset<'TNode>>) =
set |> ASet.ofSetTree getChildren.Invoke

[<Extension; MethodImpl(MethodImplOptions.AggressiveInlining)>]
static member ToAdaptiveHashSet(this: seq<'T>) = ASet.ofSeq this
Expand Down Expand Up @@ -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
[<Extension; MethodImpl(MethodImplOptions.AggressiveInlining)>]
static member OfListTree(this: alist<'TNode>, getChildren : Func<'TNode, alist<'TNode>>) =
this |> ASet.ofListTree getChildren.Invoke

/// Creates an AdaptiveHashSet from tree of sets
[<Extension; MethodImpl(MethodImplOptions.AggressiveInlining)>]
static member OfSetTree(this: aset<'TNode>, getChildren : Func<'TNode, aset<'TNode>>) =
this |> ASet.ofSetTree getChildren.Invoke

[<Extension; MethodImpl(MethodImplOptions.AggressiveInlining)>]
static member ToArray(this: aset<'T>) =
this |> ASet.force |> HashSet.toArray
Expand Down
3 changes: 3 additions & 0 deletions src/FSharp.Data.Adaptive/CollectionExtensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<_>
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
Expand Down

0 comments on commit 0837ac2

Please sign in to comment.