c# - What's the difference between `ImmutableSortedSet` and fsharp `Set`? -


bcl has introduced group of immutable collections

i wondering what's difference between immutablesortedset , native fsharp set? seems performance signatures of both similar. saw somewhere sortedset implemented red black tree, guess immutablesortedset same.

what internal implementation of fsharp map? is red black tree claimed here or avl tree found out here?

in addition, why msdn documents don't state clear actual data structure library collection? know these implementation details , change. point if don't want bind library data type type of known data structure, should @ least offer summery of methods performance signatures in terms of complexity?

i wondering what's difference between immutablesortedset , native fsharp set?

they similar. main difference f# set supports fast set theoretic operations (union, intersection , difference).

here simple f# program measures performance of common operations:

open system.collections.immutable  while true       let timer = system.diagnostics.stopwatch.startnew()     let cmp = languageprimitives.fastgenericcomparer<int>     let mutable s1 = immutablesortedset.create<int>(cmp)     let mutable s2 = immutablesortedset.create<int>(cmp)     in 1..1000000       s1 <- s1.add     in 1000000..2000000       s2 <- s2.add     printfn "bcl immutablesortedset: add in %fs" timer.elapsed.totalseconds     timer.restart()     _ in 1..10       in 1..1000000         ignore(s1.contains i)     printfn "bcl immutablesortedset: contains in %fs" timer.elapsed.totalseconds     timer.restart()     let s = s1.union s2     printfn "bcl immutablesortedset: union in %fs" timer.elapsed.totalseconds        let timer = system.diagnostics.stopwatch.startnew()     let mutable s1 = set.empty     let mutable s2 = set.empty     in 1..1000000       s1 <- s1.add     in 1000000..2000000       s2 <- s2.add     printfn "f# set: %fs" timer.elapsed.totalseconds     timer.restart()     _ in 1..10       in 1..1000000         ignore(s1.contains i)     printfn "f# set: contains in %fs" timer.elapsed.totalseconds     timer.restart()     let s = set.union s1 s2     printfn "f# set: union in %fs" timer.elapsed.totalseconds 

on machine, get:

         bcl immutablesortedset  f# set add                2.6s          3.0s contains           2.1s          1.9s union              1.1s          0.00004s 

so f# set slower construct , faster search orders of magnitude faster set theoretic union operation.

what internal implementation of fsharp map? is red black tree claimed here or avl tree found out here?

as both of links state, f# uses avl trees.

this relevant in context of performance figures above. avl trees contain maximum height of subtree in each branch and, therefore, allow subtrees rebalanced without examining entire subtree. in contrast, red-black trees contain single bit of data in each branch rebalancing subtrees requires entire trees traversed asymptotically slower. in layman's terms, union of 2 same-sized non-overlapping sets entails little more creating new branch containing 2 existing trees. note union in bcl api cannot express this: handles abstract ienumerable rather concrete set.

in addition, why msdn documents don't state clear actual data structure library collection? know these implementation details , change. point if don't want bind library data type type of known data structure, should @ least offer summery of methods performance signatures in terms of complexity?

i agree complexities in docs good.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -