Search Results

Search found 3677 results on 148 pages for 'concurrent vector'.

Page 13/148 | < Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >

  • Is there a version of the removeElement function in Go for the vector package like Java has in its V

    - by Brian T Hannan
    I am porting over some Java code into Google's Go language and I converting all code except I am stuck on just one part after an amazingly smooth port. My Go code looks like this and the section I am talking about is commented out: func main() { var puzzleHistory * vector.Vector; puzzleHistory = vector.New(0); var puzzle PegPuzzle; puzzle.InitPegPuzzle(3,2); puzzleHistory.Push(puzzle); var copyPuzzle PegPuzzle; var currentPuzzle PegPuzzle; currentPuzzle = puzzleHistory.At(0).(PegPuzzle); isDone := false; for !isDone { currentPuzzle = puzzleHistory.At(0).(PegPuzzle); currentPuzzle.findAllValidMoves(); for i := 0; i < currentPuzzle.validMoves.Len(); i++ { copyPuzzle.NewPegPuzzle(currentPuzzle.holes, currentPuzzle.movesAlreadyDone); copyPuzzle.doMove(currentPuzzle.validMoves.At(i).(Move)); // There is no function in Go's Vector that will remove an element like Java's Vector //puzzleHistory.removeElement(currentPuzzle); copyPuzzle.findAllValidMoves(); if copyPuzzle.validMoves.Len() != 0 { puzzleHistory.Push(copyPuzzle); } if copyPuzzle.isSolutionPuzzle() { fmt.Printf("Puzzle Solved"); copyPuzzle.show(); isDone = true; } } } } If there is no version available, which I believe there isn't ... does anyone know how I would go about implementing such a thing on my own?

    Read the article

  • Finding the centroid of a polygon?

    - by user146780
    I have tried: for each vertex, add to total, divide by number of verities to get center. I'v also tried: Find the topmost, bottommost - get midpoint... find leftmost, rightmost, find midpoint. Both of these did not return the perfect center because I'm relying on the center to scale a polygon. I want to scale my polygons so I may put a border around them. What is the best way to find the centroid of a polygon given that the polygon may be concave, convex and have many many sides of various lengths. Thanks

    Read the article

  • Is the old vector get cleared? If yes, how and when?

    - by user180866
    I have the following code: void foo() { vector<double> v(100,1); // line 1 // some code v = vector<double>(200,2); // line 2 // some code } what happened to the vector of size 100 after the second line? Is it gets cleared by itself? If the answer is yes, how and when it is cleared? By the way, is there any other "easy and clean" ways to change the vector as in line 2? I don't want things like v.resize(200); for (int i=0; i<200; i++) v[i] = 2;

    Read the article

  • C++ vector<T>::iterator operator +

    - by Tom
    Hi, Im holding an iterator that points to an element of a vector, and I would like to compare it to the next element of the vector. Here is what I have Class Point{ public: float x,y; } //Somewhere in my code I do this vector<Point> points = line.getPoints(); foo (points.begin(),points.end()); where foo is: void foo (Vector<Point>::iterator begin,Vector<Point>::iterator end) { std::Vector<Point>::iterator current = begin; for(;current!=end-1;++current) { std::Vector<Point>::iterator next = current + 1; //Compare between current and next. } } I thought that this would work, but current + 1 is not giving me the next element of the vector. I though operator+ was the way to go, but doesnt seem so. Is there a workaround on this? THanks

    Read the article

  • fastest engine to convert PDF into PNG

    - by skyde
    I would like to know which of the opensource PDF engine can convert a pdf into a image the fastest. I don't care about the quality of the result (antialiasing ...) For my project it need to be very very fast. I would probably need to build my own but i dont wan't to start from scratch.

    Read the article

  • How to restrict the range of elements of C++ STL vector?

    - by cambr
    vector<int> l; for(int i=0;i<10;i++){ l.push_back(i); } I want the vector to only be able to store numbers from a specified range (or set). How can that be done, in general? In particular, I want to restrict the vector to beonly be able to store single digits. So, if I do a l[9]++, it should give me an error or warn me. (because 10 is not a single digit number). Similarly, l[0]-- should warn me. Is there a way to do this using C++ STL vector?

    Read the article

  • Attribute vector emptying itself

    - by ravloony
    Hello, I have two classes, derived from a common class. The common class has a pure virtual function called execute(), which is implemented in both derived classes. In the inherited class I have an attribute which is a vector. In both execute() methods I overwrite this vector with a result. I access both classes from a vector of pointers to their objects. The problem is when I try to access the result vector form outside the objects. In one case I can get the elements (which are simply pointers), in the other I cannot, the vector is empty. Code: class E; class A{ protected: vector<E*> _result; public: virtual void execute()=0; vector<E*> get_result(); }; vector<E*> A::get_result() { return _result; } class B : public A { public: virtual void execute(); }; B::execute() { //... _result = tempVec; return; } class C : public A { public: virtual void execute(); }; C::execute() { //different stuff to B _result = tempvec; return; } main() { B* b = new B(); C* c = new C(); b->execute(); c->execute(); b->get_result();//returns full vector c->get_result(); //returns empty vector!! } I have no idea what is going on here... I have tried filling _result by hand from a temp vector in the offending class, doing the same with vector::assign(), nothing works. And the other object works perfectly. I must be missing something.... Any help would be greatly appreciated.

    Read the article

  • which is better in general, map or vector in c++?

    - by tsubasa
    As I know that accessing an element in vector takes constant time while in map takes logarithmic time. However, storing a map takes less memory than storing a vector. Therefore, I want to ask which one is better in general? I'm considering using one of those two in my program, which has about 1000 elements. I plan to use 3 dimensional vector, which would take 1000x1000x1000 elements.

    Read the article

  • Does std::vector change its address? How to avoid

    - by kunigami
    Since vector elements are stored contiguously, I guess it may not have the same address after some push_back's , because the initial allocated space could not suffice. I'm working on a code where I need a reference to an element in a vector, like: int main(){ vector<int> v; v.push_back(1); int *ptr = &v[0]; for(int i=2; i<100; i++) v.push_back(i); cout << *ptr << endl; //? return 0; } But it's not necessarily true that ptr contains a reference to v[0], right? How would be a good way to guarantee it? My first idea would be to use a vector of pointers and dynamic allocation. I'm wondering if there's an easier way to do that? PS.: Actually I'm using a vector of a class instead of int, but I think the issues are the same.

    Read the article

  • How to initialize std::vector from C-style array?

    - by dehmann
    What is the cheapest way to initialize a std::vector from a C-style array? Example: In the following class, I have a vector, but due to outside restrictions, the data will be passed in as C-style array: class Foo { std::vector<double> w_; public: void set_data(double* w, int len){ // how to cheaply initialize the std::vector? } Obviously, I can call w_.resize() and then loop over the elements, or call std::copy(). Are there any better methods?

    Read the article

  • Concurrent modification during backup: rsync vs dump vs tar vs ?

    - by pehrs
    I have a Linux log server where multiple applications write data. Data is written in bursts, and in a lot of different files. I need to make a backup of this mess, preferably preserving as much coherence between the file versions as possible and avoiding getting truncated files. Total amount of data on the server is about 100Gb. What I really would want (but can't) is to shut-down, backup the system cold and then start it up again. What kind of guarantees against concurrent modification does the various backup tools give? When do they "freeze" the file versions? I am looking at rsync, dump and tar at the moment, but I am open for other (open source) alternatives. Changing the application or blocking writing for backups is sadly not an option. System is not running LVM (yet), but I have considered that for rebuilding the system and then snapshots.

    Read the article

  • NUMA-aware constructs for java.util.concurrent

    - by Dave
    The constructs in the java.util.concurrent JSR-166 "JUC" concurrency library are currently NUMA-oblivious. That's because we currently don't have the topology discovery infrastructure and underpinnings in place that would allow and enable NUMA-awareness. But some quick throw-away prototypes show that it's possible to write NUMA-aware library code. I happened to use JUC Exchanger as a research vehicle. Another interesting idea is to adapt fork-join work-stealing to favor stealing from queues associated with 'nearby' threads.

    Read the article

  • proper concurrent users estimation case studies

    - by golemwashere
    I've been asked to size a web architecture for an excessive number of concurrent users ( hundreds of thousands ). I'm having a hard time convincing these people that unless you are in the top 5 of your country websites it's quite hard to hit those numbers. Can anyone provide some real world case studies providing stats for total / concurrent users explaining what is the usual ratio between total vs concurrent?

    Read the article

  • Resultant Vector Algorithm for 2D Collisions

    - by John
    I am making a Pong based game where a puck hits a paddle and bounces off. Both the puck and the paddles are Circles. I came up with an algorithm to calculate the resultant vector of the puck once it meets a paddle. The game seems to function correctly but I'm not entirely sure my algorithm is correct. Here are my variables for the algorithm: Given: velocity = the magnitude of the initial velocity of the puck before the collision x = the x coordinate of the puck y = the y coordinate of the puck moveX = the horizontal speed of the puck moveY = the vertical speed of the puck otherX = the x coordinate of the paddle otherY = the y coordinate of the paddle piece.horizontalMomentum = the horizontal speed of the paddle before it hits the puck piece.verticalMomentum = the vertical speed of the paddle before it hits the puck slope = the direction, in radians, of the puck's velocity distX = the horizontal distance between the center of the puck and the center of the paddle distY = the vertical distance between the center of the puck and the center of the paddle Algorithm solves for: impactAngle = the angle, in radians, of the angle of impact. newSpeedX = the speed of the resultant vector in the X direction newSpeedY = the speed of the resultant vector in the Y direction Here is the code for my algorithm: int otherX = piece.x; int otherY = piece.y; double velocity = Math.sqrt((moveX * moveX) + (moveY * moveY)); double slope = Math.atan(moveX / moveY); int distX = x - otherX; int distY = y - otherY; double impactAngle = Math.atan(distX / distY); double newAngle = impactAngle + slope; int newSpeedX = (int)(velocity * Math.sin(newAngle)) + piece.horizontalMomentum; int newSpeedY = (int)(velocity * Math.cos(newAngle)) + piece.verticalMomentum; for those who are not program savvy here is it simplified: velocity = v(moveX² + moveY²) slope = arctan(moveX / moveY) distX = x - otherX distY = y - otherY impactAngle = arctan(distX / distY) newAngle = impactAngle + slope newSpeedX = velocity * sin(newAngle) + piece.horizontalMomentum newSpeedY = velocity * cos(newAngle) + piece.verticalMomentum My Question: Is this algorithm correct? Is there an easier/simpler way to do what I'm trying to do?

    Read the article

  • Concurrent Affairs

    - by Tony Davis
    I once wrote an editorial, multi-core mania, on the conundrum of ever-increasing numbers of processor cores, but without the concurrent programming techniques to get anywhere near exploiting their performance potential. I came to the.controversial.conclusion that, while the problem loomed for all procedural languages, it was not a big issue for the vast majority of programmers. Two years later, I still think most programmers don't concern themselves overly with this issue, but I do think that's a bigger problem than I originally implied. Firstly, is the performance boost from writing code that can fully exploit all available cores worth the cost of the additional programming complexity? Right now, with quad-core processors that, at best, can make our programs four times faster, the answer is still no for many applications. But what happens in a few years, as the number of cores grows to 100 or even 1000? At this point, it becomes very hard to ignore the potential gains from exploiting concurrency. Possibly, I was optimistic to assume that, by the time we have 100-core processors, and most applications really needed to exploit them, some technology would be around to allow us to do so with relative ease. The ideal solution would be one that allows programmers to forget about the problem, in much the same way that garbage collection removed the need to worry too much about memory allocation. From all I can find on the topic, though, there is only a remote likelihood that we'll ever have a compiler that takes a program written in a single-threaded style and "auto-magically" converts it into an efficient, correct, multi-threaded program. At the same time, it seems clear that what is currently the most common solution, multi-threaded programming with shared memory, is unsustainable. As soon as a piece of state can be changed by a different thread of execution, the potential number of execution paths through your program grows exponentially with the number of threads. If you have two threads, each executing n instructions, then there are 2^n possible "interleavings" of those instructions. Of course, many of those interleavings will have identical behavior, but several won't. Not only does this make understanding how a program works an order of magnitude harder, but it will also result in irreproducible, non-deterministic, bugs. And of course, the problem will be many times worse when you have a hundred or a thousand threads. So what is the answer? All of the possible alternatives require a change in the way we write programs and, currently, seem to be plagued by performance issues. Software transactional memory (STM) applies the ideas of database transactions, and optimistic concurrency control, to memory. However, working out how to break down your program into sufficiently small transactions, so as to avoid contention issues, isn't easy. Another approach is concurrency with actors, where instead of having threads share memory, each thread runs in complete isolation, and communicates with others by passing messages. It simplifies concurrent programs but still has performance issues, if the threads need to operate on the same large piece of data. There are doubtless other possible solutions that I haven't mentioned, and I would love to know to what extent you, as a developer, are considering the problem of multi-core concurrency, what solution you currently favor, and why. Cheers, Tony.

    Read the article

  • How to print a rendered website to pdf or vector graphics?

    - by Lo Sauer
    This is a crucial question to many: Searching the web, I have found several command line tools that allow you to convert a HTML-document to a PDF-document, however they all seem to use their own, and rather incomplete rendering engine, resulting in poor quality How can you print the rendered output of a modern web-browser to pdf, (and/or svg) whilst retaining as much vector graphics as possible? There is a solution called: webkit-pdf (which renders everything to bitmap graphics) I am looking for options, alternatives, suggestions perhaps even a printer-driver or webservices? Thanks

    Read the article

  • "Microsoft ne défend pas assez les Droits de l'Homme", Google n'apprécie pas que son concurrent rest

    "Microsoft ne défend pas assez les Droits de l'Homme", Google n'apprécie pas que son concurrent reste en Chine La morale businesso-américaine commence à s'intéresser au cas de la Chine. Suite à l'altercation musclée entre Google et le régime en place à Pékin, d'autres entreprises se mettent à considérer l'idée de quitter le pays du riz. La politique chinoise est montrée du doigt dans les discussions mondaines entre les dirigeants des plus grands groupes américains. Fort de son nouveau statut de justicier, Sergey Brin (l'un des co-fondateurs de Google), s'en est pris à Microsoft, accusant la firme de ne pas assez défendre les droits de l'Homme et la liberté d'expression. « J'es...

    Read the article

  • How do Tortoise svn handle concurrent file updation

    - by sabithpocker
    I don't know much about Tortoise SVN, but have been using it for a while :) I understand that it is capable of managing concurrent users on same file, but how does it do that? I am working on a file that another user is using concurrently and he committed couple of times before me, Now my files doesnt have the changes he made. Every time i end up in such a situation I gets a conflict and I am stuck. So is there something else I should do instead of just committing and causing conflict. Is it safe to do a update first and then commit ? Will I lose my local changes in this case? Please dont beat me up if this is somthing basic, A link to some tutorial will be useful in that case :)

    Read the article

  • NoSQL : JSON, indexation distribuée et géoréplication débarquent dans Couchbase, le concurrent de MongoDB

    Base de données NoSQL : documents JSON, indexation distribuée et géoréplication débarquent dans Couchbase Le concurrent de MongoDB Couchbase Server, le système de gestion de bases de données NoSQL, vient de subir une mise à jour assez importante. La version 2.0 de Couchbase introduit un modèle de stockage de documents et un magasin clé-valeur (key-value), permettant à l'outil de faire un grand pas dans le support du Big Data (gros volumes de données). Pour rappel, CouchBase est un projet initialement basé sur le système noSQL Apache CouchDB, à la différence que le code Erlang de CouchDB a été entièrement réécrit en C++, avec des ajustements et ajouts en tirant profit du système de ...

    Read the article

  • Les Google Apps veulent se positionner en concurrent de Sharepoint, Gmail passe les 425 millions d'utilisateurs

    Les Google Apps veulent se positionner en concurrent de Sharepoint Gmail passe les 425 millions d'utilisateurs Parmi les nombreux chiffres donnés sur ses différents produits, Google en a mis deux particulièrement en avant : ceux de ses Web Apps et de sa messagerie. Lancée en 2004, la messagerie Gmail possède aujourd'hui 425 millions d'utilisateurs. Un bon résultat. Surtout si on lui ajoute 5 millions de client "business" qui utilisent les Google Apps (en résumé Gmail + Google Docs) comme par exemple la compagnie aérienne européenne KLM. Mais cette annonce a surtout été l'occasion pour Sundar Pichai, vice-président de Google, de s'attaquer à son conc...

    Read the article

  • C++ STL: How to iterate vector while requiring access to element and its index?

    - by Ashwin
    I frequently find myself requiring to iterate over STL vectors. While I am doing this I require access to both the vector element and its index. I used to do this as: typedef std::vector<Foo> FooVec; typedef FooVec::iterator FooVecIter; FooVec fooVec; int index = 0; for (FooVecIter i = fooVec.begin(); i != fooVec.end(); ++i, ++index) { Foo& foo = *i; if (foo.somethingIsTrue()) // True for most elements std::cout << index << ": " << foo << std::endl; } After discovering BOOST_FOREACH, I shortened this to: typedef std::vector<Foo> FooVec; FooVec fooVec; int index = -1; BOOST_FOREACH( Foo& foo, fooVec ) { ++index; if (foo.somethingIsTrue()) // True for most elements std::cout << index << ": " << foo << std::endl; } Is there a better or more elegant way to iterate over STL vectors when both reference to the vector element and its index is required? I am aware of the alternative: for (int i = 0; i < fooVec.size(); ++i) But I keep reading about how it is not a good practice to iterate over STL containers like this.

    Read the article

  • What is a truly empty std::vector in C++?

    - by RyanG
    I've got a two vectors in class A that contain other class objects B and C. I know exactly how many elements these vectors are supposed to hold at maximum. In the initializer list of class A's constructor, I initialize these vectors to their max sizes (constants). If I understand this correctly, I now have a vector of objects of class B that have been initialized using their default constructor. Right? When I wrote this code, I thought this was the only way to deal with things. However, I've since learned about std::vector.reserve() and I'd like to achieve something different. I'd like to allocate memory for these vectors to grow as large as possible because adding to them is controlled by user-input, so I don't want frequent resizings. However, I iterate through this vector many, many times per second and I only currently work on objects I've flagged as "active". To have to check a boolean member of class B/C on ever iteration is silly. I don't want these objects to even BE there for my iterators to see when I run through this list. Is reserving the max space ahead of time and using push_back to add a new object to the vector a solution to this?

    Read the article

  • C++: getting the address of the start of an std::vector ?

    - by shoosh
    Sometimes it is useful to use the starting address of an std::vector and temporarily treat that address as the address of a regularly allocated buffer. For instance replace this: char* buf = new char[size]; fillTheBuffer(buf, size); useTheBuffer(buf, size); delete[] buf; With This: vector<char> buf(size); fillTheBuffer(&buf[0], size); useTheBuffer(&buf[0], size); The advantage of this is of course that the buffer is deallocated automatically and I don't have to worry about the delete[]. The problem I'm having with this is when size == 0. In that case the first version works ok. An empty buffer is "allocated" and the subsequent functions do nothing size they get size == 0. The second version however fails if size == 0 since calling buf[0] may rightly contain an assertion that 0 < size. So is there an alternative to the idiom &buf[0] that returns the address of the start of the vector even if the vector is empty? I've also considered using buf.begin() but according to the standard it isn't even guaranteed to return a pointer.

    Read the article

< Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >