swap

sql swap primary key values

走远了吗. 提交于 2019-11-26 21:48:56
问题 is it possible to swap primary key values between two datasets? If so, how would one do that? 回答1: Let's for the sake of simplicity assume you have two records id name --------- 1 john id name --------- 2 jim both from table t (but they can come from different tables) You could do UPDATE t, t as t2 SET t.id = t2.id, t2.id = t.id WHERE t.id = 1 AND t2.id = 2 Note: Updating primary keys has other side effects and maybe the preferred approach would be to leave the primary keys as they are and

Move semantics == custom swap function obsolete?

吃可爱长大的小学妹 提交于 2019-11-26 20:20:17
问题 Recently, many questions pop up on how to provide your own swap function. With C++11, std::swap will use std::move and move semantics to swap the given values as fast as possible. This, of course, only works if you provide a move constructor and a move assignment operator (or one that uses pass-by-value). Now, with that given, is it actually necessary to write your own swap functions in C++11? I could only think of non-movable types, but then again, the custom swap s usually work through some

How does the standard library implement std::swap?

本秂侑毒 提交于 2019-11-26 19:45:31
How is the swap function implemented in the STL? Is it as simple as this: template<typename T> void swap(T& t1, T& t2) { T tmp(t1); t1=t2; t2=tmp; } In other posts, they talk about specializing this function for your own class. Why would I need to do this? Why can't I use the std::swap function? Niall How is std::swap implemented? Yes, the implementation presented in the question is the classic C++03 one. A more modern (C++11) implementation of std::swap looks like this: template<typename T> void swap(T& t1, T& t2) { T temp = std::move(t1); // or T temp(std::move(t1)); t1 = std::move(t2); t2 =

How to find out which processes are using swap space in Linux?

南笙酒味 提交于 2019-11-26 19:10:53
Under Linux, how do I find out which process is using the swap space more? David Holm Run top then press O p Enter . Now processes should be sorted by their swap usage. Here is an update as my original answer does not provide an exact answer to the problem as pointed out in the comments. From the htop FAQ : It is not possible to get the exact size of used swap space of a process. Top fakes this information by making SWAP = VIRT - RES, but that is not a good metric, because other stuff such as video memory counts on VIRT as well (for example: top says my X process is using 81M of swap, but it

iter_swap() versus swap() — what's the difference?

╄→гoц情女王★ 提交于 2019-11-26 18:13:01
问题 MSDN says: swap should be used in preference to iter_swap , which was included in the C++ Standard for backward compatibility. But comp.std.c++ says: Most STL algorithms operate on iterator ranges. It therefore makes sense to use iter_swap when swapping elements within those ranges, since that is its intended purpose --- swapping the elements pointed to by two iterators. This allows optimizations for node-based sequences such as std::list , whereby the nodes are just relinked, rather than the

Swap slices of Numpy arrays

杀马特。学长 韩版系。学妹 提交于 2019-11-26 17:43:22
I love the way python is handling swaps of variables: a, b, = b, a and I would like to use this functionality to swap values between arrays as well, not only one at a time, but a number of them (without using a temp variable). This does not what I expected (I hoped both entries along the third dimension would swap for both): import numpy as np a = np.random.randint(0, 10, (2, 3,3)) b = np.random.randint(0, 10, (2, 5,5)) # display before a[:,0, 0] b[:,0,0] a[:,0,0], b[:, 0, 0] = b[:, 0, 0], a[:,0,0] #swap # display after a[:,0, 0] b[:,0,0] Does anyone have an idea? Of course I can always

Replace Div with another Div

亡梦爱人 提交于 2019-11-26 17:33:23
问题 I have this thing I m trying to do. I have a main picture of a map and within that map there are regions. These regions have hot spots on them so you can click them and it will replace the whole map with only the region. (just a simple div swap). I need it as a div because in this div i have the hot spots listed. There are a total of 4 div s that I am going to need to do this with. If anyone could help me that would be awesome! So links that are listed in a table need to replace the image in

Is it possible to write swap method in Java? [duplicate]

懵懂的女人 提交于 2019-11-26 17:23:50
This question already has an answer here: How to write a basic swap function in Java [duplicate] 19 answers Java method to swap primitives 7 answers Here is the question: write a method that swaps two variables. These two variables should be primitives. It doesn't need to be generic e.g. two int variables. Is there a way?! Without using an array or objects, no, it is not possible to do it within a method. While it is not possible to write a function that simply swaps two variables, it is possible to write a helper function that allows you to: Swap two variables using only one statement Without

How do you swap two integer variables without using any if conditions, casting, or additional variables? [closed]

a 夏天 提交于 2019-11-26 17:18:45
问题 There are two integer variables. Can you swap those integer variables without using any if conditions, without casting, and without using additional variables? For example: int a = 10; int b = 5; a > b always. The answer should be a == 5 and b == 10 回答1: If you think you are being clever by not using 3rd variable then do some performance tests and you see that the much faster way is to use 3rd int to store the variable temporarily. Anyways, i solved the problem with XOR bitwise operator: a ^=

Swapping Nodes on a single linked list

不想你离开。 提交于 2019-11-26 16:55:56
问题 I am trying to make a swapNode function that can take any two nodes and swap them. I've made an algorithm that works if they're at least 2 nodes away, but I can't seem to come up with an algorithm that will work if they are closer to each other. Here's what I wrote so far: void swapNode(call * &head, call * &first, call * &second){ call * firstPrev = NULL; call * secPrev = NULL; call * current = head; //set previous for first while((current->next != first) ){ current = current->next; }