According to the .NET documentation,
HashSet<T> does not maintain order when enumerated so I implemented my own using F#.
Can anyone help review if this is threadsafe and correct?
open System open System.Collections open System.Collections.Generic type LinkedHashSet<'a when 'a : equality> () = let mutable index = 0 let indexed = SortedDictionary<int, 'a> () let hash = HashSet<'a> () let theLock = obj () interface ICollection<'a> with member __.Count = lock theLock (fun () -> hash.Count) member __.IsReadOnly = false member __.Add e = lock theLock (fun () -> if hash.Add e then indexed.[index] <- e index <- index + 1 ) member __.Clear () = lock theLock (fun () -> index <- 0 indexed.Clear () hash.Clear () ) member __.Contains e = lock theLock (fun () -> hash.Contains e) member __.CopyTo (array, arrayIndex) = lock theLock (fun () -> let kvps = Seq.toArray indexed let kvpLength = Array.length kvps for i in arrayIndex..kvpLength - 1 do array.[i - arrayIndex] <- kvps.[i].Value ) member __.GetEnumerator () = let values = lock theLock (fun () -> indexed |> Seq.map (fun kvp -> kvp.Value) ) values.GetEnumerator () member this.GetEnumerator () : IEnumerator = (this :> IEnumerable).GetEnumerator () member __.Remove e = let matcher (kvp: KeyValuePair<int, 'a>) = kvp.Value = e lock theLock (fun () -> if hash.Remove e then let kvps = indexed :> seq<KeyValuePair<int, 'a>> match Seq.tryFind matcher kvps with | Some x -> indexed.Remove x.Key | None -> false else false )
distinctChar takes a string
aabbb and returns
let distinctChars (s: string) = s.ToCharArray () |> Array.fold (fun (set: ICollection<char>) e -> set.Add e; set) (LinkedHashSet () :> ICollection<char>) |> Seq.toArray |> String
✓ Extra quality
ExtraProxies brings the best proxy quality for you with our private and reliable proxies
✓ Extra anonymity
Top level of anonymity and 100% safe proxies – this is what you get with every proxy package
✓ Extra speed
1,ooo mb/s proxy servers speed – we are way better than others – just enjoy our proxies!
USA proxy location
We offer premium quality USA private proxies – the most essential proxies you can ever want from USA
Our proxies have TOP level of anonymity + Elite quality, so you are always safe and secure with your proxies
Use your proxies as much as you want – we have no limits for data transfer and bandwidth, unlimited usage!
Superb fast proxy servers with 1,000 mb/s speed – sit back and enjoy your lightning fast private proxies!
99,9% servers uptime
Alive and working proxies all the time – we are taking care of our servers so you can use them without any problems
No usage restrictions
You have freedom to use your proxies with every software, browser or website you want without restrictions
Perfect for SEO
We are 100% friendly with all SEO tasks as well as internet marketing – feel the power with our proxies
Buy more proxies and get better price – we offer various proxy packages with great deals and discounts
We are working 24/7 to bring the best proxy experience for you – we are glad to help and assist you!