I have two questions about STL
1) why STL is not thread-safe? Is there any structure that is thread-safe?
2) How to debug STL using GDB? In GDB, how can I print a vector?
I am using a set because, i want to use the quick look up property of a sorted container such as a set. I am wondering if I have to use the find member method to get the benefit of a sorted container, or can I also use the static find method in the STL algorithms?
My hunch is that using the static version will use a linear search instead of a…
Hi all,
I am newbie for integer linear programming.
I plan to use a integer linear programming solver to solve my combinatorial optimization problem.
I am more familiar with C++/object oriented programming on an IDE.
Now I am using NetBeans with Cygwin to write my applications most of time.
May I ask if there is an easy use ILP solver for me?…
I have a large vector (10^9 elements) of chars, and I was wondering what is the fastest way to write such vector to a file. So far I've been using next code:
vector<char> vs;
// ... Fill vector with data
ofstream outfile("nanocube.txt", ios::out | ios::binary);
ostream_iterator<char> oi(outfile, '\0');
copy(vs.begin(), vs.end(),…
I'm just wonder, what the differences are between creating a BMP file algorithm and JPG file algorithm ?
If you know the others images' format algorithm, please post them.
Thanks.
I have always wondered why you cannot use locally defined classes as predicates to STL algorithms.
In the question: Approaching STL algorithms, lambda, local classes and other approaches, BubbaT mentions says that 'Since the C++ standard forbids local types to be used as arguments'
Example code:
int main() {
int array[] = { 1, 2, 3,…
I have the following scenario.The implementation is required for a real time application.
1)I need to store at max 20 entries in a container(STL Map, STL List etc).
2)If a new entry comes and 20 entries are already present i have to overwrite the oldest entry with the new entry.
Considering point 2, i feel if the container is full (Max…
Hi
I wonder how can I implement the STL map sorting by value.
For example, I have a map m
map<int, int>;
m[1] = 10;
m[2] = 5;
m[4] = 6;
m[6] = 1;
and then.. I'd like to sort that with the m's value.
So, if I print the map, I'd like to get the result like
m[6] = 1
m[2] = 5
m[4] = 6
m[1] = 10
this.
How can I sort like this…
What is the significance of Bresenhams Line of Sight algorithm in chasing and evading in games?
As far as i know and implemented this algorithm calulates the straight line between two given points. However while implementing it in game development i stored the points calculated using this algorithm in an array.Then im traversing this…
Hello everybody,
I am completely perplexed at a seg fault that I seem to be creating.
I have:
vector<unsigned int> words;
and global variable
string input;
I define my custom compare function:
bool wordncompare(unsigned int f, unsigned int s) {
int n = k;
while (((f < input.size()) && (s <…
Greetings,
I am trying to perform a copy from one vector (vec1) to another vector (vec2) using the following 2 abbreviated lines of code (full test app follows):
vec2.reserve( vec1.size() );
copy(vec1.begin(), vec1.end(), vec2.begin());
While the call to vec2 sets the capacity of vector vec2, the copying of data to…
FYI: no boost, yes it has this, I want to reinvent the wheel ;)
Is there some form of a selective iterator (possible) in C++? What I want is to seperate strings like this:
some:word{or other
to a form like this:
some : word { or other
I can do that with two loops and find_first_of(":") and ("{") but this seems…
I'm studying AI. My teacher gave us source code of a chess-like game and asked us to enhance it. My exercise is to improve the alpha/beta algorithm implementing in that game. The programmer already uses transposition tables, MTD(f) with alpha/beta+memory (MTD(f) is the best algorithm I know by far). So is there any…
I'm looking for matchmaking algorithm for 1x1 online game. Players must be matched not by their skill or level, as usual, but by some specific filters. Each player sends request, where he specifies some set of parameters (generally, 2-4 parameters). If some parameter is specified, player can be matched only with…
If you've used C++ you undoubtedly have used the Standard Template Libraries. Designed for in-memory management of data and collections of data this is a core aspect of all C++ programs.
Berkeley DB is a database library with a variety of APIs designed to ease development, one of those APIs extends and makes…
I generated a height map with the diamond square algorithm. The thing is i do not manage to create islands, this is, restrict the height other than water level range to a certain value in the center of the map.
I manualy seeded a circle in the middle of the map but the rest of the map still receives heights…
Hii..
Can anybody help me to find an algorithm in Java code to find synonyms of a search word based on the context and I want to implement the algorithm with WordNet database.
For example, "I am running a Java program". From the context, I want to find the synonyms for the word "running", but the synonyms…
After learning good amount of c++, i'm now into STL containers and algorithms template library, my major concerns are,
1) Is this library same across different platforms like MS, linux n other os?
2) will quality or efficiency of program c++ module decrease with more use of STL containers and algorithms,…
I am trying to implement the Hopcroft Karp algorithm in Python using networkx as graph representation.
Currently I am as far as this:
#Algorithms for bipartite graphs
import networkx as nx
import collections
class HopcroftKarp(object):
INFINITY = -1
def __init__(self, G):
self.G = G
…
I have a set of points which are contained within the rectangle. I'd like to split the rectangles into subrectangles based on point density (giving a number of subrectangles or desired density, whichever is easiest).
The partitioning doesn't have to be exact (almost any approximation better than regular…
I wish to triangulate a polygon I only have the outline of (p0, p1, p2 ... pn) like described in this question: polygon triangulation algorithm and this webpage: http://cgm.cs.mcgill.ca/~godfried/teaching/cg-projects/97/Ian/algorithm2.html
I do not wish to learn the subject and have a deep understanding…
I want to generate a maze with the following properties:
The maze is non-perfect. Means it has loops and multiple ways to reach the exit.
The maze should be random. The algorithm should output different mazes for different input parameters
The maze doesn't have to be braided. Means dead-ends are…
I have a matrix of tiles, on some of that tiles there are objects. I want to calculate which tiles are visible to player, and which are not, and I need to do it quite efficiently (so it would compute fast enough even when I have a big matrices (100x100) and lots of objects).
I tried to do it with…
Could somebody please provide a step-through approach to solving the following problem using the Banker's Algorithm? How do I determine whether a "safe-state" exists? What is meant when a process can "run to completion"?
In this example, I have four processes and 10 instances of the same…