How can I insert all values of one HashSet into another HashSet?

You don’t want union — as you said, it will create a new HashSet. Instead you can use Extend::extend: use std::collections::HashSet; fn main() { let mut a: HashSet<u16> = [1, 2, 3].iter().copied().collect(); let b: HashSet<u16> = [1, 3, 7, 8, 9].iter().copied().collect(); a.extend(&b); println!(“{:?}”, a); // {8, 3, 2, 1, 7, 9} } (Playground) Extend::extend is … Read more

MYSQL UNION DISTINCT

No. You cannot specify which exact field you need to distinct with. It only works with the whole row. As of your problem – just make your query a subquery and in outer one GROUP BY user_id SELECT * FROM (SELECT a.user_id,a.updatecontents as city,b.country FROM userprofiletemp AS a LEFT JOIN userattributes AS b ON a.user_id=b.user_id … Read more

how to convert sql union to linq

Three useful Linq concepts operating on sets. Given set c and set e: Concat gives you everything in c or e: (From c In db.Customers Select c.Phone).Concat( _ From c In db.Customers Select c.Fax).Concat( _ From e In db.Employees Select e.HomePhone) (From c In db.Customers _ Select Name = c.CompanyName, Phone = c.Phone).Concat(From e In … Read more

Shallow copy of a hashset

Use the constructor: HashSet<type> set2 = new HashSet<type>(set1); Personally I wish LINQ to Objects had a ToHashSet extension method as it does for List and Dictionary. It’s easy to create your own of course: public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source) { if (source == null) { throw new ArgumentNullException(“source”); } return new HashSet<T>(source); } (With … Read more

What’s a good, generic algorithm for collapsing a set of potentially-overlapping ranges?

This seems to works and is easy to understand. public static IEnumerable<Range<T>> Collapse<T>(this IEnumerable<Range<T>> me, IComparer<T> comparer) { List<Range<T>> orderdList = me.OrderBy(r => r.Start).ToList(); List<Range<T>> newList = new List<Range<T>>(); T max = orderdList[0].End; T min = orderdList[0].Start; foreach (var item in orderdList.Skip(1)) { if (comparer.Compare(item.End, max) > 0 && comparer.Compare(item.Start, max) > 0) { newList.Add(new … Read more