union

Collapsing a discriminated union - derive an umbrella type with all possible key-value combinations from the union

北城以北 提交于 2021-02-20 19:23:52
问题 I have a discriminated union, for example: type Union = { a: "foo", b: string, c: number } | {a: "bar", b: boolean } I need to derive a type that includes all potential properties, assigned with types that may be found on any member of Union , even if only defined on some - in my example: type CollapsedUnion = { a: "foo" | "bar", b: string | boolean, c: number | undefined } How can I make a generic that derives such collapsed unions? I need a generic that supports unions of any size. Similar

Collapsing a discriminated union - derive an umbrella type with all possible key-value combinations from the union

﹥>﹥吖頭↗ 提交于 2021-02-20 19:23:07
问题 I have a discriminated union, for example: type Union = { a: "foo", b: string, c: number } | {a: "bar", b: boolean } I need to derive a type that includes all potential properties, assigned with types that may be found on any member of Union , even if only defined on some - in my example: type CollapsedUnion = { a: "foo" | "bar", b: string | boolean, c: number | undefined } How can I make a generic that derives such collapsed unions? I need a generic that supports unions of any size. Similar

Call member function of non-active union member

送分小仙女□ 提交于 2021-02-16 20:18:37
问题 Does calling foo in the following code leads to UB? using vec = std::array<int, 1>; struct field0 { vec data; operator int() { return data[0]; } }; union a { struct { vec data; } data; field0 x; }; void foo() { a bar; std::cin >> bar.data.data[0]; std::cout << bar.x; } According to standard, x and data have the same address, so it should be safe to cast this to vec* . Also, field0 and vec are layout-compatible, so it should be safe to inspect data via x.data or vice-versa. However, we not

Mysql index on view not working

六眼飞鱼酱① 提交于 2021-02-16 13:28:09
问题 I created a view named 'myview' as below. create view myview as select 'a' source,col1,col2 from table_a union select source,col1,col2 from table_b ; table_a has an index on col1 , table_b has an index on source , col1 . When I query on myview as below, no index is used. select * from myview where source = a and col1 = 'xxx' ; How do I make the indexes work on this query? Create Code CREATE TABLE `table_a` ( `col1` VARCHAR(50) NULL DEFAULT NULL, `col2` VARCHAR(50) NULL DEFAULT NULL, INDEX

HQL unexpected token “(” subquery select

五迷三道 提交于 2021-02-11 13:50:21
问题 I have this query. Translate it from my sql query to hql. I have this error "unexpected token: ( near line 2, column" String query = "SELECT MAX(number)\n" + " FROM (SELECT number FROM EmployeeTripCard \n" + " WHERE EXTRACT(YEAR FROM issueDate) = '2015'\n" + " UNION ALL\n" + " SELECT trip_card_number FROM PostgraduateTripCard\n" + " WHERE EXTRACT(YEAR FROM issueDate) = '2015'\n" + " UNION ALL\n" + " SELECT trip_card_number FROM StudentTripCard \n" + " WHERE EXTRACT(YEAR FROM issueDate) =

Combine two for loops and union results in XQuery

谁说我不能喝 提交于 2021-02-08 10:01:51
问题 Let's say we have this folders not_my_files collections collection1.xml collection2.xml collection3.xml etc... my_files my_documents mydoc1.xml mydoc2.xml mydoc3.xml etc... There are the structure of xml files collection1.xml (same structure for collection2.xml, collection3.xml, etc...) <collection xml:id="name_of_collection_1"> <ref id="id_of_ref_1"> <title>This is title 1 of first document in this collection</title> </ref> <ref id="id_of_ref_2"> <title>This is title 2 of second document in

how to fix mysql error number #1250 Table 'a1' from one of the SELECTs cannot be used in field list?

拟墨画扇 提交于 2021-02-08 04:41:07
问题 I am doing following way to sorting data by date and time select b.app_user_id,b.username,a.message_content,a.message_to,a.message_date from app_messages a left join app_users b on a.message_from = b.app_user_id where a.message_to=1 and b.app_user_id= 4 UNION select b1.app_user_id,b1.username,a1.message_content,a1.message_to,a1.message_date from app_messages a1 left join app_users b1 on a1.message_from = b1.app_user_id where a1.message_to=4 and b.app_user_id= 1 order by a1.message_date,a

Whats the best algorithm for Non Disjoint Set Union?

♀尐吖头ヾ 提交于 2021-02-08 03:32:25
问题 Lets say there are two (non disjoint) sets of points (cartesian space), what is the best case complexity algorithm to perform the union of the two sets ? 回答1: Since the point coordinates are arbitrary and there is no special relation between them, I don't see this problem as a geometric specific problem. It is the generic problem of efficiently merging S1 and S2 into a new set S. I know about two options: 1) When the sets are stored in a hash table (actually a hash set), the union takes O(|S1

Whats the best algorithm for Non Disjoint Set Union?

…衆ロ難τιáo~ 提交于 2021-02-08 03:31:28
问题 Lets say there are two (non disjoint) sets of points (cartesian space), what is the best case complexity algorithm to perform the union of the two sets ? 回答1: Since the point coordinates are arbitrary and there is no special relation between them, I don't see this problem as a geometric specific problem. It is the generic problem of efficiently merging S1 and S2 into a new set S. I know about two options: 1) When the sets are stored in a hash table (actually a hash set), the union takes O(|S1

Shallow copy of a hashset

社会主义新天地 提交于 2021-02-04 11:54:02
问题 Whats the best way of doing it? var set2 = new HashSet<reference_type>(); Traverse the set with a foreach like this. foreach (var n in set) set2.Add(n); Or use something like union like this. set2 = set.UnionWith(set); // all the elements 回答1: 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