vector

Diffie-Hellman -- Primitive root mod n -- cryptography question.

In the below snippet, please explain starting with the first "for" loop what is happening and why. Why is 0 added, why is 1 added in the second loop. What is going on in the "if" statement under bigi. Finally explain the modPow method. Thank you in advance for meaningful replies. public static boolean isPrimitive(BigInteger m, BigInteg...

Variable Scoping in a method and its persistence in C++

Consider the following public method that adds an integer variable to a vector of ints(private member) in a class in C++. KoolMethod() { int x; x = 10; KoolList.Add(x); } Vector<int>KoolList; But is this a valid addition to a vector ??? Upon calling the method, it creates a local variable. The scope of this local variable ends t...

C# 2D Vector Graphics Game using DirectX or OpenGL?

Hey Guys, So it has been a while since I have done any game programming in C#, but I have had a recent bug to get back into it, and I wanted some opinions on what configuration I should use. I wanted to use C# as that is what I use for work, and have become vary familiar with. I have worked with both DirectX and OpenGL in the past, bu...

NumPy: how to quickly normalize many vectors?

How can a list of vectors be elegantly normalized, in NumPy? Here is an example that does not work: from numpy import * vectors = array([arange(10), arange(10)]) # All x's, then all y's norms = apply_along_axis(linalg.norm, 0, vectors) # Now, what I was expecting would work: print vectors.T / norms # vectors.T has 10 elements, as d...

Need to calculate rotation-vector from Sensor.TYPE_ORIENTATION data

I need to calculate a rotation vector out of the data i get from Sensor.TYPE_ORIENTATION. The sensor data is defined like this: the values have to be recalculated to become a correct 3d position: values[0]: Azimuth, angle between the magnetic north direction and the Y axis, around the Z axis (0 to 359). 0=North, 90=East, 180=South, 27...

Initializing a C++ vector to random values... fast

Hey, id like to make this as fast as possible because it gets called A LOT in a program i'm writing, so is there any faster way to initialize a C++ vector to random values than: double range;//set to the range of a particular function i want to evaluate. std::vector<double> x(30, 0.0); for (int i=0;i<x.size();i++) { x.at(i) = (rand(...

A question on vectors, pointers and iterators

Guys, I have a midterm examination tomorrow, and I was looking over the sample paper, and I'm not sure about this question. Any help would be appreciated. Let v be a vector<Thingie*>, so that each element v[i] contains a pointer to a Thingie. If p is a vector<Thingie*>::iterator, answer the following questions: what type is p? what ty...

what happens when you copy vector<boost::share_ptr> to another vector

Do we get multiple copies of the pointers yet the data members are still being shared? boost::shared_ptr<string> a1(new string("Hello")); vector<boost::shared_ptr<string> > a; a.push_back(a1); vector<boost::shared_ptr<string> > b; b = a; cout<<a[0]->c_str()<<b[0]->c_str()<<endl; a1->append(" World"); cout<...

c++ : list(vector) definition with array

I have Class Email, there is parameter "bcc" in her constructor. Its actually list of emails for copies. There is no fixed number of these emails and later i have to have possibility to extend this list. //constructor prototype Email::Email(vector<string> bcc) So i want to use type vector or list for that and function push_back(). H...

Optimizing Vector elements swaps using CUDA

Hi all, Since I am new to cuda .. I need your kind help I have this long vector, for each group of 24 elements, I need to do the following: for the first 12 elements, the even numbered elements are multiplied by -1, for the second 12 elements, the odd numbered elements are multiplied by -1 then the following swap takes place: Graph: b...

Pointing class property to another class with vectors

I've got a simple class, and another class that has a property that points to the first class: #include <iostream> #include <vector> using namespace std; class first{ public: int var1; }; class second{ public: first* classvar; }; Then, i've got a void that's supposed to point "classvar" to the intended iteration of the clas...

Scalling connected lines

Hello, I have some kind of a shape consisting of vertical, horizontal and diagonal lines. I have starting X,Y and ending X,Y (this is my input - just 2 points defining a line) of each line and I would like to make the whole shape scalable (just by changing the value of a scale ratio variable), so that I can still preserve the proper con...

Vector vs Collections.synchronizedList(ArrayList)

Vector is synchronized but ArrayList is not synchronized but we can synchronize an ArrayList by Collections.synchronizedList (aList), so which will perform better and faster ...

Finding smallest angle between vectors in logarithmic time.

I have n=10000 10-dimensional vectors. For every vector v1 I want to know the vector v2 that minimizes the angle between v1 and v2. Is there a way to solve this problem faster than O(n^2)? ...

how to pass vector of string to foo(char const *const *const)?

Edit: Thank you all very much for your help. Now I feel that I'm really stupid and I am so sorry to waste your time. After implementing James Hopkin' suggestion, I still get the warnings of "invalid name 'null'", which is much better than those weird characters. Then, I went back and read the library document again, and it turns out that...

initializing a vector of custom class in c++

Hey basically Im trying to store a "solution" and create a vector of these. The problem I'm having is with initialization. Heres my class for reference class Solution { private: // boost::thread m_Thread; int itt_found; int dim; pfn_fitness f; double value; std::vector<double> x; public: ...

comparing two angles

Given four points in the plane, A,B,X,Y, I wish to determine which of the following two angles is smaller ∢ABX or ∢ABY. The angle ∢ABX is defined as the angle of BX, when AB is translated to lie on the open segment (-∞,0]. Intuitively when saying ∢ABX I mean the angle you get when you turn left after visiting vertex B. I'd rather not ...

direct access to vector elements similar to arrays

I'm currently creating a tile based game, where elements of the games are placed in four different vectors (since there are multiple game objects with different properties, hence stored in different vectors). These game elements themselves contain x and y coordinates similar to how they are stored in a two dimensional array. i was wond...

J2ME Vector of Hashtable query

I am a newbe to J2ME. I have a vector called locations which prints out [{X=NM0001-1, ccc=1327_10}, {X=NM0001-2, ccc=1329_10}, {X=NM0001-3, ccc=691_10}] when I put System.out.println(locations); I set "X", and "ccc" are the keys. In my program I wanted to query for certain value of "ccc" what is the "X" value. Any help would be ...

ActionScript Reading A Vector's DataType?

is it possible to read the datatype of a vector? var vec:Vector.<int> = new Vector.<int>; trace(the datatype of vec); //ideally this would output 'int' ...