Search Results

Search found 5070 results on 203 pages for 'algorithm'.

Page 186/203 | < Previous Page | 182 183 184 185 186 187 188 189 190 191 192 193  | Next Page >

  • How can I rewrite the history of a published git branch in multiple steps?

    - by Frerich Raabe
    I've got a git repository with two branches, master and amazing_new_feature. The latter branch contains the work on, well, an amazing new feature. A colleague and me are both working on the same repository, and the two of us commit to both branches. Now the work on the amazing new feature finished, and a bit more than 100 commits were accumulated in the amazing_new_feature branch. I'd like to clean those commits up a bit (using git rebase -i) before merging the work into master. The issue we're facing is that it's quite a pain to rewrite/reorder all 100 commits in one go. Instead, what I'd like to do is: Rewrite/merge/reorder the first few commits in the amazing_new_feature branch and put the result into a dedicated branch which contains the 'cleaned up' history (say, a amazing_new_feature_ready_for_merge branch). Rebase the remaining amazing_new_feature branch on the amazing_new_feature_ready_for_merge branch. Repeat at 1. My idea is that at some point, all the work from amazing_new_feature should be in amazing_new_feature_ready_for_merge and then I can merge the latter into master. Is this a sensible approach, or are there better/easier/more fool-proff solutions to this problem? I'm especially scared about the second step of the above algorithm since it means rebasing a published branch. IIRC it's a dangerous thing to do.

    Read the article

  • Currently using View, Should I use a hard table instead?

    - by 1001010101
    I am currently debating whether my table, mapping_uGroups_uProducts, which is a view formed by the following table: CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `db`.`mapping_uGroups_uProducts` AS select distinct `X`.`upID` AS `upID`,`Z`.`ugID` AS `ugID` from ((`db`.`mapping_uProducts_Products` `X` join `db`.`productsInfo` `Y` on((`X`.`pID` = `Y`.`pID`))) join `db`.`mapping_uGroups_Groups` `Z` on((`Y`.`gID` = `Z`.`gID`))); My current query is: SELECT upID FROM uProductsInfo \ JOIN fs_uProducts USING (upID) column \ JOIN mapping_uGroups_uProducts USING (upID) -- could be faster if we use hard table and index \ JOIN mapping_fs_key USING (fsKeyID) \ WHERE fsName="OVERALL" \ AND ugID=1 \ ORDER BY score DESC \ LIMIT 0,30; which is pretty slow. (for 30 results, it requires about 10 secondes). I think the reason for my query being so slow is definitely due to the fact that that particular query relies on a VIEW which has no index to speed things up. +----+-------------+----------------+--------+----------------+---------+---------+---------------------------------------+-------+---------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+----------------+--------+----------------+---------+---------+---------------------------------------+-------+---------------------------------+ | 1 | PRIMARY | mapping_fs_key | const | PRIMARY,fsName | fsName | 386 | const | 1 | Using temporary; Using filesort | | 1 | PRIMARY | <derived2> | ALL | NULL | NULL | NULL | NULL | 19706 | Using where | | 1 | PRIMARY | uProductsInfo | eq_ref | PRIMARY | PRIMARY | 4 | mapping_uGroups_uProducts.upID | 1 | Using index | | 1 | PRIMARY | fs_uProducts | ref | upID | upID | 4 | db.uProductsInfo.upID | 221 | Using where | | 2 | DERIVED | X | ALL | PRIMARY | NULL | NULL | NULL | 40772 | Using temporary | | 2 | DERIVED | Y | eq_ref | PRIMARY | PRIMARY | 4 | db.X.pID | 1 | Distinct | | 2 | DERIVED | Z | ref | PRIMARY | PRIMARY | 4 | db.Y.gID | 2 | Using index; Distinct | +----+-------------+----------------+--------+----------------+---------+---------+---------------------------------------+-------+---------------------------------+ 7 rows in set (0.48 sec) The explain here looks pretty cryptic, and I don't know whether I should drop view and write a script to just insert everything in the view to a hard table. ( obviously, it will lose the flexibility of the view since the mapping changes quite frequently). Does anyone have any idea to how I can optimize my schema better?

    Read the article

  • efficient sort with custom comparison, but no callback function

    - by rob
    I have a need for an efficient sort that doesn't have a callback, but is as customizable as using qsort(). What I want is for it to work like an iterator, where it continuously calls into the sort API in a loop until it is done, doing the comparison in the loop rather than off in a callback function. This way the custom comparison is local to the calling function (and therefore has access to local variables, is potentially more efficient, etc). I have implemented this for an inefficient selection sort, but need it to be efficient, so prefer a quick sort derivative. Has anyone done anything like this? I tried to do it for quick sort, but trying to turn the algorithm inside out hurt my brain too much. Below is how it might look in use. // the array of data we are sorting MyData array[5000], *firstP, *secondP; // (assume data is filled in) Sorter sorter; // initialize sorter int result = sortInit (&sorter, array, 5000, (void **)&firstP, (void **)&secondP, sizeof(MyData)); // loop until complete while (sortIteration (&sorter, result) == 0) { // here's where we do the custom comparison...here we // just sort by member "value" but we could do anything result = firstP->value - secondP->value; }

    Read the article

  • Standard term for a thread I/O reorder buffer?

    - by Crashworks
    I have a case where many threads all concurrently generate data that is ultimately written to one long, serial file. I need to somehow serialize these writes so that the file gets written in the right order. ie, I have an input queue of 2048 jobs j0..jn, each of which produces a chunk of data oi. The jobs run in parallel on, say, eight threads, but the output blocks have to appear in the file in the same order as the corresponding input blocks — the output file has to be in the order o0o1o2... The solution to this is pretty self evident: I need some kind of buffer that accumulates and writes the output blocks in the correct order, similar to a CPU reorder buffer in Tomasulo's algorithm, or to the way that TCP reassembles out-of-order packets before passing them to the application layer. Before I go code it, I'd like to do a quick literature search to see if there are any papers that have solved this problem in a particularly clever or efficient way, since I have severe realtime and memory constraints. I can't seem to find any papers describing this though; a Scholar search on every permutation of [threads, concurrent, reorder buffer, reassembly, io, serialize] hasn't yielded anything useful. I feel like I must just not be searching the right terms. Is there a common academic name or keyword for this kind of pattern that I can search on?

    Read the article

  • How to draw shadows that don't suck?

    - by mystify
    A CAShapeLayer uses a CGPathRef to draw it's stuff. So I have a star path, and I want a smooth drop shadow with a radius of about 15 units. Probably there is some nice functionality in some new iPhone OS versions, but I need to do it myself for a old aged version of 3.0 (which most people still use). I tried to do some REALLY nasty stuff: I created a for-loop and sequentially created like 15 of those paths, transform-scaling them step by step to become bigger. Then assigning them to a new created CAShapeLayer and decreasing it's alpha a little bit on every iteration. Not only that this scaling is mathematically incorrect and sucks (it should happen relative to the outline!), the shadow is not rounded and looks really ugly. That's why nice soft shadows have a radius. The tips of a star shouldn't appear totally sharp after a shadow size of 15 units. They should be soft like cream. But in my ugly solution they're just as s harp as the star itself, since all I do is scale the star 15 times and decrease it's alpha 15 times. Ugly. I wonder how the big guys do it? If you had an arbitrary path, and that path must throw a shadow, how does the algorithm to do that work? Probably the path would have to be expanded like 30 times, point-by-point relative to the tangent of the outline away from the filled part, and just by 0.5 units to have a nice blending. Before I re-invent the wheel, maybe someone has a handy example or link?

    Read the article

  • What are the benefits of `while(condition) { //work }` and `do { //work } while(condition)`?

    - by Shaharyar
    I found myself confronted with an interview question where the goal was to write a sorting algorithm that sorts an array of unsorted int values: int[] unsortedArray = { 9, 6, 3, 1, 5, 8, 4, 2, 7, 0 }; Now I googled and found out that there are so many sorting algorithms out there! Finally I could motivate myself to dig into Bubble Sort because it seemed pretty simple to start with. I read the sample code and came to a solution looking like this: static int[] BubbleSort(ref int[] array) { long lastItemLocation = array.Length - 1; int temp; bool swapped; do { swapped = false; for (int itemLocationCounter = 0; itemLocationCounter < lastItemLocation; itemLocationCounter++) { if (array[itemLocationCounter] > array[itemLocationCounter + 1]) { temp = array[itemLocationCounter]; array[itemLocationCounter] = array[itemLocationCounter + 1]; array[itemLocationCounter + 1] = temp; swapped = true; } } } while (swapped); return array; } I clearly see that this is a situation where the do { //work } while(cond) statement is a great help to be and prevents the use of another helper variable. But is this the only case that this is more useful or do you know any other application where this condition has been used?

    Read the article

  • String literal recognition problem

    - by helicera
    Hello! I'm trying to recognize string literal by reading string per symbol. Here is a sample code: #region [String Literal (")] case '"': // {string literal ""} { // skipping '"' ChCurrent = Line.ElementAtOrDefault<Char>(++ChPosition); while(ChCurrent != '"') { Value.Append(ChCurrent); ChCurrent = Line.ElementAtOrDefault<Char>(++ChPosition); if(ChCurrent == '"') { // "" sequence only acceptable if(Line.ElementAtOrDefault<Char>(ChPosition + 1) == '"') { Value.Append(ChCurrent); // skip 2nd double quote ChPosition++; // move position next ChCurrent = Line.ElementAtOrDefault<Char>(++ChPosition); } } else if(default(Char) == ChCurrent) { // message: unterminated string throw new ScanningException(); } } ChPosition++; break; } #endregion When I run test: [Test] [ExpectedException(typeof(ScanningException))] public void ScanDoubleQuotedStrings() { this.Scanner.Run(@"""Hello Language Design""", default(System.Int32)); this.Scanner.Run(@"""Is there any problems with the """"strings""""?""", default(System.Int32)); this.Scanner.Run(@"""v#:';?325;.<>,|+_)""(*&^%$#@![]{}\|-_=""", default(System.Int32)); while(0 != this.Scanner.TokensCount - 1) { Assert.AreEqual(Token.TokenClass.StringLiteral, this.Scanner.NextToken.Class); } } It passes with success.. while I'm expecting to have an exception according to unmatched " mark in this.Scanner.Run(@"""v#:';?325;.<>,|+_)""(*&^%$#@![]{}\|-_=""", default(System.Int32)); Can anyone explain where is my mistake or give an advice on algorithm.

    Read the article

  • no instance of overloaded function getline c++

    - by Dave
    I'm a bit confused as to what i have incorrect with my script that is causing this error. I have a function which calls a fill for game settings but it doesn't like my getline. Also i should mention these are the files i have included for it: #include <fstream> #include <cctype> #include <map> #include <iostream> #include <string> #include <algorithm> #include <vector> using namespace std;' This is what i have: std::map<string, string> loadSettings(std::string file){ ifstream file(file); string line; std::map<string, string> config; while(std::getline(file, line)) { int pos = line.find('='); if(pos != string::npos) { string key = line.substr(0, pos); string value = line.substr(pos + 1); config[trim(key)] = trim(value); } } return (config); } The function is called like this from my main.cpp //load settings for game std::map<string, string> config = loadSettings("settings.txt"); //load theme for game std::map<string, string> theme = loadSettings("theme.txt"); Where did i go wrong ? Please help! The error: settings.h(61): error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &&,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &&' from 'std::string'

    Read the article

  • Concurrency problem with arrays (Java)

    - by Johannes
    For an algorithm I'm working on I tried to develop a blacklisting mechanism that can blacklist arrays in a specific way: If "1, 2, 3" is blacklisted "1, 2, 3, 4, 5" is also considered blacklisted. I'm quite happy with the solution I've come up with so far. But there seem to be some serious problems when I access a blacklist from multiple threads. The method "contains" (see code below) sometimes returns true, even if an array is not blacklisted. This problem does not occur if I only use one thread, so it most likely is a concurrency problem. I've tried adding some synchronization, but it didn't change anything. I also tried some slightly different implementations using java.util.concurrent classes. Any ideas on how to fix this? public class Blacklist { private static final int ARRAY_GROWTH = 10; private final Node root = new Node(); private static class Node{ private volatile Node[] childNodes = new Node[ARRAY_GROWTH]; private volatile boolean blacklisted = false; public void blacklist(){ this.blacklisted = true; this.childNodes = null; } } public void add(final int[] array){ synchronized (root) { Node currentNode = this.root; for(final int edge : array){ if(currentNode.blacklisted) return; else if(currentNode.childNodes.length <= edge) { currentNode.childNodes = Arrays.copyOf(currentNode.childNodes, edge + ARRAY_GROWTH); } if(currentNode.childNodes[edge] == null) { currentNode.childNodes[edge] = new Node(); } currentNode = currentNode.childNodes[edge]; } currentNode.blacklist(); } } public boolean contains(final int[] array){ synchronized (root) { Node currentNode = this.root; for(final int edge : array){ if(currentNode.blacklisted) return true; else if(currentNode.childNodes.length <= edge || currentNode.childNodes[edge] == null) return false; currentNode = currentNode.childNodes[edge]; } return currentNode.blacklisted; } } }

    Read the article

  • boost::unordered_map is... ordered?

    - by Thanatos
    I have a boost::unordered_map, but it appears to be in order, giving me an overwhelming feeling of "You're Doing It Wrong". Why is the output to this in order? I would've expected the underlying hashing algorithm to have randomized this order: #include <iostream> #include <boost/unordered_map.hpp> int main() { boost::unordered_map<int, int> im; for(int i = 0; i < 50; ++i) { im.insert(std::make_pair(i, i)); } boost::unordered_map<int, int>::const_iterator i; for(i = im.begin(); i != im.end(); ++i) { std::cout << i->first << ", " << i->second << std::endl; } return 0; } ...gives me... 0, 0 1, 1 2, 2 ... 47, 47 48, 48 49, 49

    Read the article

  • Slightly different execution times between python2 and python3

    - by user557634
    Hi. Lastly I wrote a simple generator of permutations in python (implementation of "plain changes" algorithm described by Knuth in "The Art... 4"). I was curious about the differences in execution time of it between python2 and python3. Here is my function: def perms(s): s = tuple(s) N = len(s) if N <= 1: yield s[:] raise StopIteration() for x in perms(s[1:]): for i in range(0,N): yield x[:i] + (s[0],) + x[i:] I tested both using timeit module. My tests: $ echo "python2.6:" && ./testing.py && echo "python3:" && ./testing3.py python2.6: args time[ms] 1 0.003811 2 0.008268 3 0.015907 4 0.042646 5 0.166755 6 0.908796 7 6.117996 8 48.346996 9 433.928967 10 4379.904032 python3: args time[ms] 1 0.00246778964996 2 0.00656183719635 3 0.01419159912 4 0.0406293644678 5 0.165960511097 6 0.923101452814 7 6.24257639835 8 53.0099868774 9 454.540967941 10 4585.83498001 As you can see, for number of arguments less than 6, python 3 is faster, but then roles are reversed and python2.6 does better. As I am a novice in python programming, I wonder why is that so? Or maybe my script is more optimized for python2? Thank you in advance for kind answer :)

    Read the article

  • Is there a recommended way to communicate scientific/engineering programming to C developers?

    - by ggkmath
    Hi, I have a lot of MATLAB code that needs to get ported to C (execution speed is critical for this work) as part of a back-end process for a web application. When I attempt to outsource this code to a C developer, I assume (correct me if I'm wrong) few C developers also understand MATLAB code (things like indexing and memory management are different, etc.). I wonder if there are any C developers out there that can recommend a procedure for me to follow to best communicate what the code does? For example, should I provide the MATLAB code and explain what it's doing line by line? Or, should I just provide the math/algorithm, explain it in plain English, and let the C developer implement it with this understanding in his/her own way (e.g. can I assume the developer understands how to work with complex math (i.e. imaginary numbers), how to generate histograms, perform an FFT, etc.)? Or, is there a better method? I expect I'm not the first to need to do this, so I wonder if any C developers out there ran into this situation and can share any conventional wisdom how they'd like this task to be transferred? Thanks in advance for any comments.

    Read the article

  • Recommendations for IPC between parent and child processes in .NET?

    - by Jeremy
    My .NET program needs to run an algorithm that makes heavy use of 3rd party libraries (32-bit), most of which are unmanaged code. I want to drive the CPU as hard as I can, so the code runs several threads in parallel to divide up the work. I find that running all these threads simultaneously results in temporary memory spikes, causing the process' virtual memory size to approach the 2 GB limit. This memory is released back pretty quickly, but occasionally if enough threads enter the wrong sections of code at once, the process crosses the "red line" and either the unmanaged code or the .NET code encounters an out of memory error. I can throttle back the number of threads but then my CPU usage is not as high as I would like. I am thinking of creating worker processes rather than worker threads to help avoid the out of memory errors, since doing so would give each thread of execution its own 2 GB of virtual address space (my box has lots of RAM). I am wondering what are the best/easiest methods to communicate the input and output between the processes in .NET? The file system is an obvious choice. I am used to shared memory, named pipes, and such from my UNIX background. Is there a Windows or .NET specific mechanism I should use?

    Read the article

  • Is this mingw bug ?

    - by Debanjan
    Hi, I have been trying to execute this program on my migw ,through code::blocks, #include <string.h> #include <math.h> #include <stdio.h> #define N 100 int p[N / 64]; int pr[N]; int cnt; void sieve() { int i,j; for(i=0;i<N;i++) pr[i]=1; pr[0]=pr[1]=0; for(i=2;i<N;i++) if(pr[i]) { p[cnt]=i; cnt++; for(j=i+i;j<=N;j+=i) pr[j]=0; } } int main(){ sieve(); int i; for(i=0;i<cnt;i++) printf("%d ",p[i]); puts(""); printf("Total number of prime numbers : %d",cnt); return 0; } In My system the output is : 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 Total number of prime numbers : 22 Which is completely insane,since I am completely sure about the implementation of my algorithm. So I decided to try it in Ideone where it gives correct output.Can anybody point out the reason ?

    Read the article

  • How does does ifstream eof() work?

    - by Chan
    Hello everyone, #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include <cctype> #include <fstream> using namespace std; int main() { fstream inf( "ex.txt", ios::in ); while( !inf.eof() ) { std::cout << inf.get() << "\n"; } inf.close(); inf.clear(); inf.open( "ex.txt", ios::in ); char c; while( inf >> c ) { std::cout << c << "\n"; } return 0; } I'm really confused about eof() function. Suppose my ex.txt's content is: abc It always reads an extra character and show -1. when reading using eof()? But the inf c gave the correct output which was 'abc'? Can anyone help me explain this? Best regards, Chan Nguyen

    Read the article

  • Microsoft JScript runtime error Object doesn't support this property or method

    - by Darxval
    So i am trying to call this function in my javascript but it gives me the error of "Microsoft JScript runtime error Object doesn't support this property or method" and i cant figure out why. It is occuring when trying to call hmacObj.getHMAC. This is from the jsSHA website: http://jssha.sourceforge.net/ to use the hmac-sha1 algorithm encryption. Thank you! hmacObj = new jsSHA(signature_base_string,"HEX"); signature = hmacObj.getHMAC("hgkghk","HEX","SHA-1","HEX"); Above this i have copied the code from sha.js snippet: function jsSHA(srcString, inputFormat) { /* * Configurable variables. Defaults typically work */ jsSHA.charSize = 8; // Number of Bits Per character (8 for ASCII, 16 for Unicode) jsSHA.b64pad = ""; // base-64 pad character. "=" for strict RFC compliance jsSHA.hexCase = 0; // hex output format. 0 - lowercase; 1 - uppercase var sha1 = null; var sha224 = null; The function it is calling (inside of the jsSHA function) (snippet) this.getHMAC = function (key, inputFormat, variant, outputFormat) { var formatFunc = null; var keyToUse = null; var blockByteSize = null; var blockBitSize = null; var keyWithIPad = []; var keyWithOPad = []; var lastArrayIndex = null; var retVal = null; var keyBinLen = null; var hashBitSize = null; // Validate the output format selection switch (outputFormat) { case "HEX": formatFunc = binb2hex; break; case "B64": formatFunc = binb2b64; break; default: return "FORMAT NOT RECOGNIZED"; }

    Read the article

  • How to -accurately- measure size in pixels of text being drawn on a canvas by drawTextOnPath()

    - by Nick
    I'm using drawTextOnPath() to display some text on a Canvas and I need to know the dimensions of the text being drawn. I know this is not feasible for paths composed of multiple segments, curves, etc. but my path is a single segment which is perfectly horizontal. I am using Paint.getTextBounds() to get a Rect with the dimensions of the text I want to draw. I use this rect to draw a bounding box around the text when I draw it at an arbitrary location. Here's some simplified code that reflects what I am currently doing: // to keep this example simple, always at origin (0,0) public drawBoundedText(Canvas canvas, String text, Paint paint) { Rect textDims = new Rect(); paint.getTextBounds(text,0, text.length(), textDims); float hOffset = 0; float vOffset = paint.getFontMetrics().descent; // vertically centers text float startX = textDims.left; / 0 float startY = textDims.bottom; float endX = textDims.right; float endY = textDims.bottom; path.moveTo(startX, startY); path.lineTo(endX, endY); path.close(); // draw the text canvas.drawTextOnPath(text, path, 0, vOffset, paint); // draw bounding box canvas.drawRect(textDims, paint); } The results are -close- but not perfect. If I replace the second to last line with: canvas.drawText(text, startX, startY - vOffset, paint); Then it works perfectly. Usually there is a gap of 1-3 pixels on the right and bottom edges. The error seems to vary with font size as well. Any ideas? It's possible I'm doing everything right and the problem is with drawTextOnPath(); the text quality very visibly degrades when drawing along paths, even if the path is horizontal, likely because of the interpolation algorithm or whatever its using behind the scenes. I wouldnt be surprised to find out that the size jitter is also coming from there.

    Read the article

  • I need some ideas on my algortihm for a Hit Counter

    - by stckvrflw
    My algorithm is for a hit count, I am tring to not count for the same person twice if that person came to the site twice in a time internval (For example if he comes twice in 5 minutes, I want to count it as 1 for this person) Here how my database looks like UserIp UserId Date of user came 127.0.0.1 new.user.akb 26.03.2010 10:15:44 127.0.0.1 new.user.akb 26.03.2010 10:16:44 127.0.0.1 new.user.akb 26.03.2010 10:17:44 127.0.0.1 new.user.akb 26.03.2010 10:18:44 127.0.0.1 new.user.akb 26.03.2010 10:19:44 127.0.0.1 new.user.akb 26.03.2010 10:20:44 127.0.0.1 new.user.akb 26.03.2010 10:21:44 127.0.0.1 new.user.akb 26.03.2010 10:22:44 127.0.0.1 new.user.akb 26.03.2010 10:23:44 What I need to do is get number of distinct UserIPs from the table above that occured within a time interval. For example if I set the time interval for 5 minutes, and let say that is starts at 26.03.2010 10:15:44 Then I will get 2 as the results, since 1 distinct value between 10:15 to 10:20 and , 1 distinct value from 10:20 to 10:23, For example if my interval is 3 minutes than the return result will be 3 Thanks.

    Read the article

  • C++ iterator and const_iterator problem for own container class

    - by BaCh
    Hi there, I'm writing an own container class and have run into a problem I can't get my head around. Here's the bare-bone sample that shows the problem. It consists of a container class and two test classes: one test class using a std:vector which compiles nicely and the second test class which tries to use my own container class in exact the same way but fails miserably to compile. #include <vector> #include <algorithm> #include <iterator> using namespace std; template <typename T> class MyContainer { public: class iterator { public: typedef iterator self_type; inline iterator() { } }; class const_iterator { public: typedef const_iterator self_type; inline const_iterator() { } }; iterator begin() { return iterator(); } const_iterator begin() const { return const_iterator(); } }; // This one compiles ok, using std::vector class TestClassVector { public: void test() { vector<int>::const_iterator I=myc.begin(); } private: vector<int> myc; }; // this one fails to compile. Why? class TestClassMyContainer { public: void test(){ MyContainer<int>::const_iterator I=myc.begin(); } private: MyContainer<int> myc; }; int main(int argc, char ** argv) { return 0; } gcc tells me: test2.C: In member function ‘void TestClassMyContainer::test()’: test2.C:51: error: conversion from ‘MyContainer::iterator’ to non-scalar type ‘MyContainer::const_iterator’ requested I'm not sure where and why the compiler wants to convert an iterator to a const_iterator for my own class but not for the STL vector class. What am I doing wrong?

    Read the article

  • Image creation performance / image caching

    - by Kilnr
    Hello, I'm writing an application that has a scrollable image (used to display a map). The map background consists of several tiles (premade from a big JPG file), that I draw on a Graphics object. I also use a cache (Hashtable), to prevent from having to create every image when I need it. I don't keep everything in memory, because that would be too much. The problem is that when I'm scrolling through the map, and I need an image that wasn't cached, it takes about 60-80 ms to create it. Depending on screen resolution, tile size and scroll direction, this can occur multiple times in one scroll operation (for different tiles). In my case, it often happens that this needs to be done 4 times, which introduces a delay of more than 300 ms, which is extremely noticeable. The easiest thing for me would be that there's some way to speed up the creation of Images, but I guess that's just wishful thinking... Besides that, I suppose the most obvious thing to do is to load the tiles predictively (e.g. when scrolling to the right, precache the tiles to the right), but then I'm faced with the rather difficult task of thinking up a halfway decent algorithm for this. My actual question then is: how can I best do this predictive loading? Maybe I could offload the creation of images to a separate thread? Other things to consider? Thanks in advance.

    Read the article

  • visual analysis of web pages in ruby

    - by Clint Miller
    I'm looking to write some code that does visual analysis of web pages, preferably using Ruby. My code will need to be able to determine the top, left, width, height, background color, color, and font size for all the elements in the DOM. Of course, these values can only be calculated once all CSS is applied. So, I don't think that Nokogiri is up for the job. Ultimately, I'm trying to use this data in a VIPS-like (Vision-Based Page Segmentation) algorithm in an attempt to find the main content in downloaded news articles. I've considered using Watir to drive Chrome or Firefox and then extract the data. The problem is that browsers can't be run headless through Watir (I think). Ultimately, this code will be running on an array of Linux servers in a data center. So, the code won't have easy access to an X Server for displaying the browser. I suppose one solution is to use Watir and run a headless X Server on the Linux servers. That's a bit of a pain, but it looks like my best option right now. Does anyone have any better ideas?

    Read the article

  • Goldbach theory in C

    - by nofe
    I want to write some code which takes any positive, even number (greater than 2) and gives me the smallest pair of primes that sum up to this number. I need this program to handle any integer up to 9 digits long. My aim is to make something that looks like this: Please enter a positive even integer ( greater than 2 ) : 10 The first primes adding : 3+7=10. Please enter a positive even integer ( greater than 2 ) : 160 The first primes adding : 3+157=160. Please enter a positive even integer ( greater than 2 ) : 18456 The first primes adding : 5+18451=18456. I don't want to use any library besides stdio.h. I don't want to use arrays, strings, or anything besides for the most basic toolbox: scanf, printf, for, while, do-while, if, else if, break, continue, and the basic operators (<,, ==, =+, !=, %, *, /, etc...). Please no other functions especially is_prime. I know how to limit the input to my needs so that it loops until given a valid entry. So now I'm trying to figure out the algorithm. I thought of starting a while loop like something like this: #include <stdio.h> long first, second, sum, goldbach, min; long a,b,i,k; //indices int main (){ while (1){ printf("Please enter a positive integer :\n"); scanf("%ld",&goldbach); if ((goldbach>2)&&((goldbach%2)==0)) break; else printf("Wrong input, "); } while (sum!=goldbach){ for (a=3;a<goldbach;a=(a+2)) for (i=2;(goldbach-a)%i;i++) first = a; for (b=5;b<goldbach;b=(b+2)) for (k=2;(goldbach-b)%k;k++) sum = first + second; } }

    Read the article

  • Terminate function on System.in .. possible?

    - by Ronald
    I am currently working on a project where I have to make an agent to interact with a server. Each 50ms, the server will receive the last thing I outputted to System.out and send me a new set of lines as a 'state' through the System.in printstream to analyze and send my next message to System.out. Also, if the server receives multiple outputs from me, it only regards the most recent one. .. As for my question: My program originally constructed a tree and then analyzed each leaf node to see which would be optimal, and then waited around for the next input, but I can recursively do a deeper tree search that would make my output 'better' (and again and again to keep returning a better result). Using this and the fact that if the server receives multiple outputs, it only takes the most recent one, I could do each level, print my result and start the next level. But here comes my problem... I can't be stuck in some complex algorithm while I am supposed to receiving the next input as I will then miss it. So I was wondering if there is a way to cancel anything else I am doing when I receive something via System.in and then go back to the beginning of the function and start the search again with the new set of input (and rinse and repeat..) I hope this all makes sense, Thank ye all

    Read the article

  • Triangulation & Direct linear transform

    - by srand
    Following Hartley/Zisserman's Multiview Geometery, Algorithm 12: The optimal triangulation method (p318), I got the corresponding image points xhat1 and xhat2 (step 10). In step 11, one needs to compute the 3D point Xhat. One such method is Direct Linear Transform (DLT), mentioned in 12.2 (p312) and 4.1 (p88). The homogenous method (DLT), p312-313, states that it finds a solution as the unit singular vector corresponding to the smallest singular value of A, thus, A = [xhat1(1) * P1(3,:)' - P1(1,:)' ; xhat1(2) * P1(3,:)' - P1(2,:)' ; xhat2(1) * P2(3,:)' - P2(1,:)' ; xhat2(2) * P2(3,:)' - P2(2,:)' ]; [Ua Ea Va] = svd(A); Xhat = Va(:,end); plot3(Xhat(1),Xhat(2),Xhat(3), 'r.'); However, A is a 16x1 matrix, resulting in a Va that is 1x1. What am I doing wrong (and a fix) in getting the 3D point? For what its worth sample data: xhat1 = 1.0e+009 * 4.9973 -0.2024 0.0027 xhat2 = 1.0e+011 * 2.0729 2.6624 0.0098 P1 = 699.6674 0 392.1170 0 0 701.6136 304.0275 0 0 0 1.0000 0 P2 = 1.0e+003 * -0.7845 0.0508 -0.1592 1.8619 -0.1379 0.7338 0.1649 0.6825 -0.0006 0.0001 0.0008 0.0010 A = <- my computation 1.0e+011 * -0.0000 0 0.0500 0 0 -0.0000 -0.0020 0 -1.3369 0.2563 1.5634 2.0729 -1.7170 0.3292 2.0079 2.6624

    Read the article

  • Stored procedure for generic MERGE

    - by GilliVilla
    I have a set of 10 tables in a database (DB1). And there are 10 tables in another database (DB2) with exact same schema on the same SQL Server 2008 R2 database server machine. The 10 tables in DB1 are frequently updated with data. I intend to write a stored procedure that would run once every day for synchronizing the 10 tables in DB1 with DB2. The stored procedure would make use of the MERGE statement. Now, my aim is to make this as generic and parametrized as possible. That is, accommodate for more tables down the line... and accommodate different source and target DB names. Definitely no hard coding is intended. This is my algorithm so far: Have the database names as parameters Have the first query within the stored procedure... result in giving the names of the 10 tables from a lookup table (this can be 10, 20 or whatever) Have a generic MERGE statement that does the sync for each of the above set of tables (based on primary key?) This is where I need more inputs on. What is the best way to achieve this stored procedure? SQL syntax would be helpful.

    Read the article

< Previous Page | 182 183 184 185 186 187 188 189 190 191 192 193  | Next Page >