If I want to populate an array with a large number of primative type values using a loop. How can I overcome the Too many code statements limit?
Integer[] arr = new Integer[]{};
for(Integer i=0; i<500000; i++) {
arr.add(i);
}
Thanks.
This could help
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_gov_limits.htm
It shows some limits on amount of scripts in the code I think you are working in.
Tell me if it works!
Related
I'm a novice and I'm pretty sure I haven't set up the for-loop correctly in my function "importData":
function urlsToSheets(){
importData("https://hub.arcgis.com/datasets/d3cd48afaacd4913b923fd98c6591276_36.csv", "Pavement Condition");
importData("https://hub.arcgis.com/datasets/lahub::tctmc-streets-of-significance-construction-impacted-streets.csv", "Streets of Significance");
importData("https://geohub.lacity.org/datasets/lahub::one-year-moratorium-streets.csv", "One-Year Moratorium");
importData("https://hub.arcgis.com/datasets/lahub::boe-permits-lines.csv", "BOE Permit Lines")
importData("https://hub.arcgis.com/datasets/lahub::archived-boe-permits-lines.csv", "Archived BOE Permit Lines");
importData("https://hub.arcgis.com/datasets/lahub::boe-permits-points.csv", "BOE Permit Points");
importData("https://hub.arcgis.com/datasets/56318ef6ed6444d981977adf80157b87_5.csv","Archived BOE Permit Points");
}
function importData(url, sheetName){
const file = UrlFetchApp.fetch(url);
const csv = file.getBlob().getDataAsString();
const csvData = csvToArray(csv);
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
sheet.clear();
for (let i = 0; i <= csvData.length; i++){
sheet.getRange(1, 1, csvData.length, csvData[i].length).setValues(csvData);
}
}
Each of these URLs have thousands of rows; the first URL has 85k rows of data. It takes over 10 minutes for the csvData to transfer to its intended sheet.
What am I doing wrong? How can I make this quicker?
Thank you!
Instead of setting the data for each row, set values of a double dimension matrix. The less interactions you do using the SpeadsheetApp API, the faster your code gets.
I suggest creating an array of all of your data. Then selecting the rows and setting values in separate lines (out of for loop).
Thank you everyone! The simplest solution was to take the following code out of the for-loop and to make it its own line.
sheet.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData)
Thank you!
I have some numbers in my header that I want to access in the code like this.
int _number0;
int _number1;
Then in implementation
_number0 = 10;
_number1 = 20;
int i;
for(i=0; i<2, i++){
auto number = _number+i; //This is where I'm lost, how to do the right part right in order to get this int by its name created from a String + an Integer.
CCLOG("Number: %i", number); //Output Number: 10 // Number: 20
}
I was thinking on a pseudo code like this:
auto number = dynamic_cast<Int*>(this->findTheMemberWithName("level%i",i));
Is there any way to do something like this in C++?
Thanks for any guideline. Greetings.
I think std::map should fulfill your requirement.
P.S:In fact, why don't you use array or vector to do the job? It is really not a good idea to make up the parameter names in CPP.
so the title essentially says it all. I am writing a symbol table in c++ for a compiler project I am working on, and all is going well except for looking up identifiers in the table.
So this is how I store into the table (pseudo like):
vector<symbolTable*>* symbolStack = new symbolTable();
//where a symbolStack is a vector of unordered_maps (symbolTables),
//each iteration in vector referencing a new block of code.
string* check = new string(root->children[0]->lexicode->c_str());
symbol* sym = new symbol();
...... //setting sym info
symbol_entry pair = make_pair(check, test)
//the unordered_map has keys of (string*, symbol*)
symbolStack[tableNumber]->insert(pair);
I am pretty solid that this works, as I have tested printing the size/infos from the map and it all seems to be storing as expect. Here is where the problem is happening for me (this takes place in a different function later):
for(int i = 0; i =< tableNumber;i++){
auto finder = symbolStack[i]->find(checkS) //checkS == check from above
if(finder == symbolStack[i]->end()) cout<<not found;
else cout<<we did it!!!!
My else is never reached. However, if I do this assuming the string*->c_str() == "test":
cout<<string->c_str(); // prints out "test"
cout<<finder->second->c_str() //prints out "test".
So the question. Why is it finding the key, and knowing it found the key, but at the same time returning that is has reached the end of the symbol stack without finding it? I have been trying to figure this out for a good 4 days solid now. Is it that my pointers are somehow off? Any insight is appreciated greatly.
So somewhat answer to my own question.
First I will say this: I have concluded the comparison with find() or similar methods do not work because for some reason the pointers are not matching up. I have no clue why this is still, or what I am doing wrong.
What I did to solve my issue and complete my code is this:
for(int k = 0; k<= tableNumber; k++){
unordered_map<string*,symbol*>::iterator it;
for(it = symbolStack[k]->begin(); it != symbolStack[k]->end(); it++)
{
string a = targetString->c_str();
string b = it->first->c_str();
if(a.compare(b) == 0) cout<<"You have found the match! \n";
}
}
}
So this answers how to get it working pragmatically if somebody else is in a similar ship, however not really answers why my other attempt failed other than noticing the pointer values were different.
In symbolTable you store pointers to strings as keys, not strings themselves. Therefore unordered_map compares pointers, not strings, and cannot find matching items. When you reconstruct the key string (as in your answer, using string b = it->first->c_str()), the comparison on strings works again. So, either you need to store string instead of string * in symbolTable, or you need to provide your own comparison function that will compare keys of type string *.
Right now i have to write a code that will print out "*" for each collectedDots, however if it doesn't collect any collectedDots==0 then it print out "". Using too many if statements look messy and i was wandering how you would implement the forloop in this case.
As a general principle the kind of rearrangement you've done here is good. You have found a way to express the rule in a general way rather than as a sequence of special cases. This is much easier to reason about and to check, and it's obviously extensible to cases where you have more than 3 dots.
You probably have made an error in confusing your target number and the iteration value, I assume that collectedDots contains the number of dots you have (as per your if statement) and so you need to introduce a variable to count up to that value
for (int i =0; i <= collectedDots; i++)
{
stars = "*";
System.out.print(stars);
}
Ok, so you already have a variable called collectedDots that is a number which tells you how many stars to print?
So your loop would be something like
for every collected dot
print *
But you can't just print it out, you need to return a string that will be printed out. So it's more like
for every collected dot
add a * to our string
return the string
They key difference between this and your attempt so far is that you were assigning a star to be your string each time through the loop, then at the end of it, you return that string–no matter how many times you assign a star to the string, the string will always just be one star.
You also need a separate variable to keep track of your loop, this should do the trick:
String stars = "";
for(int i = 0; i < collectedDots; i++)
{
stars = stars + "*";
}
return stars;
You are almost correct. Just need to change range limit of looping. Looping initial value is set to 1. So whenever you have collectedDots = 0, it will not go in loop and will return "", as stars is intialized with "" before loop.
String stars = "";
for (int i =1; i <= collectedDots; i++)
{
stars = "*";
System.out.print(stars);
}
return stars;
I have a foreach loop that processes a few thousand xmlnodes from an xmlnodelist. I'm trying to integrate the Parallel.For options from .net 4 but I get an error that "No overload for method 'For' takes 3 arguments'. But every example I see so far has it written this way. Does someone know what I need to change to get this to compile? Thanks.
Parallel.For( 0, jobs.Count, i =>
{
//..do work here..
});
Now the only other question I have is how do I break out of the current iteration? It doesn't seem to like my continue statements.
How exactly do you expect continue statements to work when each iteration can be running concurrently? You should read How to: Stop or Break from a Parallel.For Loop on the MSDN for more information about this and take a look at the Stop and Break methods.
Now the only other question I have is how do I break out of the
current iteration? It doesn't seem to like my continue statements.
Instead of continue, use break. Rather than:
for (int i = 1; i < jobs.Count; i++) {
// Initialise iteration.
if (iterationInvalid) continue;
// Do work.
}
What you're essentially getting is:
for (int i = 1; i < jobs.Count; i++)
action(i);
void action (int i) {
// Initialise iteration.
if (iterationInvalid) break;
// Do work.
}