vector

sorting vector in java

I cant find any sorting function in the java API for vectors. Collections.sort is only for List and not for Vector I dont want to write my own sorting algo because I think java should implement this Im looking for something like, class ClassName implements Comparator ... ClassName cn; sort(cn); ...

Why are linked lists almost always used with separate chaining?

It seems as though every time I see a mention of separate chaining in a hash table, a linked list is used as the data structure to store items with collisions. Why is this? For instance, why couldn't you use a vector/array data structure? ...

How to filter an array in Java?

How can I filter an array in Java? I have an array of objects, for example cars: Class: public class Car{ public int doors; public Car(int d){ this.doors = d; } } Use: Car [] cars = new Cars[4]; cars[0] = new Car(3); cars[1] = new Car(2); cars[2] = new Car(4); cars[3] = new Car(6); Now I want to filter the arr...

vector and const

Hello Consider this void f(vector<const T*>& p) { } int main() { vector<T*> nonConstVec; f(nonConstVec); } The following does not compile.The thing is that vector<T*> can not be converted to vector <const T*> , and that seems illogically to me , because there exists implicit conversion from T* to const T*. Why is this ? v...

Vector Transformation with Matrix

Hi all, I'm working on a code to do a software skinner (bone/skin animation), and I'm at the "optimization" phase (the skinner works pretty well and skin a 4900 triangles mesh with 22 bones in 1.09 ms on a Core Duo 2 Ghz (notebook)). What I need to know is : 1) Can someone show me the way (maybe with pseudocode) to transform a float3 (a...

How do I turn an image into a vector on the iPhone like Adobe Illustrator's Live Trace?

I want to be able to create vector files like Illustrator does on the iPhone. Does anyone know of an algorithm? ...

What is std::vector::front() used for?

Sorry if this has been asked before, but I am wondering what the use of std::vector::front() is. Is there a reason to use e.g. myvector.front() rather than myvector[0] or myvector.at(0)? ...

Easier way to do callbacks for vectors (or maybe something else in the STL)? C++

I'm making a simple crime sim game. Throughout it I keep doing the same thing over and over: // vector<Drug*> drugSack; for (unsigned int i = 0; i < this->drugSack.size(); i++) this->sell(drugSack[i]); Just one example. I hate having all these for loops all over the place omg QQ, anyway to do something like: drugSack->D...

push_back() and push_front() in Java

Is there any collection class in java, that implements push_back() and push_front() methods? ...

stl vector assign vs insert

I understand the semantics of the 2 operations , assign- erases before replacing with supplied values. insert - inserts values at specified location(allocates new memory if necessary). Apart from this is there any reason to preffer one over the other? Or to put it another way, is there any reason to use assign instead of insert. ...

Use of unique on STL vector with a structure

In a programming task, I'm trying to ensure a particular vector contains only unique items. With primitive types, the operation is as simple as: vector<int> lala; lala.push_back(1); lala.push_back(99); lala.push_back(3); lala.push_back(99); sort(lala.begin(), lala.end()); // lala: 1, 3, 99, 99 lala.erase(unique(lala.begin(), lala.end()...

Shortest route to intersection

I asked this question about 2 months ago but found none of the answers to be helpful enough. So I am giving it another shot. I think it was my fault not describing it well enough. So lets try again. Here is a rough idea of what I am trying to accomplish. The goal is to send a projectile from point T to intercept the object represente...

Synchronization in Vectors in Java

what is meant by vector in Java is thread safe and synchronized, how is it made thread safe. I'm looking at internal details of implementation ...

j2me NullPointerException adding image to a vector

Hello, I'm doing this: private Vector menuOptions; void addOption(String imagefilename) { try { Image i = Image.createImage(imagefilename); menuOptions.addElement((Object)i); } catch (Exception e) { e.printStackTrace(); } } And I'm getting: java.lang.NullPointerException at GraphicMenu.addOptio...

Is it safe to use C++ STL containers on multiple threads if no insertions and only .find()?

In C++, is it safe to use an std::map or std::vector concurrently in different threads if you are NOT inserting, just doing .find() operations on it? ...

Can I pass a parameter to an std::vector sort function?

Consider the class: MyClass { int varA; int varB; }; I have a vector of pointers to MyClass objects: std::vector<MyClass*> Vec; I want to sort the vector according to varA or varB using the same sort function, i.e. : bool SortFunction(const MyClass* obj1, const MyClass* obj2, const short type) { if( type == VARA_ID ) ...

Scaling up iPhone "vector-based graphics" on affine transforms

I made a "Circle" view with this drawRect - (void)drawRect:(CGRect)rect { CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(ctx, color.CGColor); CGContextAddEllipseInRect(ctx, rect); CGContextFillPath(ctx); } When I try to scale the view up using CGAffineTransformMakeScale(2.0, 2.0), th...

When to use pointers in C++

I just started learning about pointers in C++, and I'm not very sure on when to use pointers, and when to use actual objects. For example, in one of my assignments we have to construct a gPolyline class, where each point is defined by a gVector. Right now my variables for the gPolyline class looks like this: private: vector<gVector3*> ...

small string optimization for vector?

I know several (all?) STL implementations implement a "small string" optimization where instead of storing the usual 3 pointers for begin, end and capacity a string will store the actual character data in the memory used for the pointers if sizeof(characters) <= sizeof(pointers). I am in a situation where I have lots of small vectors wit...

std::vector overwriting final value, rather than growing?

I'm having an issue where using vector.push_back(value) is overwriting the final value, rather than appending to the end. Why might this happen? I have a sample item in the vector, so it's size never hits zero. Below is the code.. void UpdateTable(vector<MyStruct> *Individuals, MyStruct entry) { MyStruct someEntry; bool isNew...