I believe I have been writing some inefficient code here, but can't seem to figure out a more efficient way of writting it.
This often happens with json output, though I've had the issue with some html or xml output as well.
I run a query in my database which brings back an array. Say a persons favorite foods.
php's mysql_fetch_assoc...
Hi there,
I've got an interesting XSL scenario to run by you guys. So far my solutions seem to be inefficient (noticable increase in transformation time) so thought I'd put it out there.
The scenario
From the following XML we need to get the id of latest news item for each category.
The XML
In the XML I have a list of news items, a l...
I have a HTML document, a list of common spelling mistakes, and the correct spelling for each case.
The HTML documents will be up to ~50 pages and there are ~30K spelling correction entries.
What is an efficient way to correct all spelling mistakes in this HTML document?
(Note: my implementation will be in Python, in case you know of an...
I have a database with static tables which require to be updated from CSV weekly.
Tables are Mysql MyISAM and by static i mean they are used for read only (except when updated from CVS, obviously).
There're about 50 tables and in total about 200mb of data to be reloaded weekly.
I can think about 3 ways:
Truncate table
Load data from ...
Currently I'm using a HashMap to map the strings to int and the int values need to be frequently accessed. I'm looking for a better way to do this if possible with minimal object creation, and preferable being able to store the values as primitive ints without wrapping them with the Integer class. (Basically, the reverse of the SparseArr...
What's a good algorithm for counting submatrices within a larger, dense matrix? If I had a single line of data, I could use a suffix tree, but I'm not sure if generalizing a suffix tree into higher dimensions is exactly straightforward or the best approach here.
Thoughts?
My naive solution to index the first element of the dense matrix...
The code in question is the code contained within the 2nd foreach loop, the purpose of which is to prevent exact duplicate latitude and longitudes.
foreach($aUsers as $k => $v)
{
// generate address
$aAddress = array();
if(!empty($v['city_location']))
$aAddress[] = $v['city_loc...
Does anyone know what is the worst possible asymptotic slowdown that can happen when programming purely functionally as opposed to imperatively (i.e. allowing side-effects)?
Clarification from comment by itowlson: is there any problem for which the best known non-destructive algorithm is asymptotically worse than the best known destruct...
I'm trying to figure out how non-destructive manipulation of large collections is implemented in functional programming, ie. how it is possible to alter or remove single elements without having to create a completely new collection where all elements, even the unmodified ones, will be duplicated in memory. (Even if the original collectio...
I want to draw many spheres (~100k) using OpenGL. So far, I'm doing something like
for (int i=0; i<pnum; i++){
glPushMatrix();
glTranslatef(bpos[i].x, bpos[i].y, bpos[i].z);
glCallList(DListSPHERE);
glPopMatrix();
}
Before using proper spheres, I used GL_POINTS. That allowed me to call glDrawArrays with an array co...
How to write a thread-safe and efficient, lock-free memory allocator in C? By efficient I mean:
Fast allocation & deallocation
Optimal memory usage (minimal wastage and no external fragmentation)
Minimal meta-data overhead
...
Hello all,
I am trying to save lots of variables to a database and its getting ridiculous now. I am using PHP and MySQL.
Is there a way, I can get the array value and the array keys (array keys are exactly saqme as the table column/field names) in one go without having to add a new variable and table column pair.
To be honest, I just ...
I have a comma separated string, out of which I need to create a new string which contains a random order of the items in the original string, while making sure there are no recurrences.
For example:
Running 1,2,3,1,3 will give 2,3,1 and another time 3,1,2, and so on.
I have a code which picks a random item in the original string, and t...
Suppose I have 500 jar files linked to my program totaling over 500 MB (size of all the jars, not each one) and my program makes a call to a class located in one of them. How does Java search through jars for a class, and what is the efficiency of this? O(n)? O(log(n))?
...
Hi,
I have a large file where each line contains space-separated integers. The task is to sparse this file line-by-line. For the string to int conversion I have three solutions:
static int stringToIntV1(const string& str) {
return (atoi(str.c_str()));
}
However, if I pass a malformed string, it doesn't produce any error. For inst...
Hi,
I'm no professional programmer and I don't study it. I'm an aerospace student and did a numeric method for my diploma thesis and also coded a program to prove that it works.
I did several methods and implemented several algorithms and tried to show the proofs why different situations needed their own algorithm to solve the task.
I...
Is it possible to find a defined sequence in an integer without converting it to a string?
That is, is it possible to do some form of pattern matching directly on integers.
I have not thought of one but I keeping thinking there should be a mathematical way of doing this. That's not to say it is more efficient.
(edit) I actually what num...
Greetings All, I've seen similar questions asked before with no conclusive or tested answers.
I'm designing a News Feed system using PHP/MySQL similar to facebooks. Seeing as this table could grow to be quite large -- any inefficiency could result in a significant bottleneck.
Example Notifications:
(Items in bold are linked objects)
...
I am working on a old J2EE struts app which has very bad UI design. Most of the pages are misusing the screen real estate like there are uneven spaces among dropdown, labels, text boxes etc. Alignment of different items on page is not very efficient leading to space wastage. And sometimes users are forced to use unnecessary scroll bars w...
I have been learning Hibernate for the past few weeks, I have gotten most of what I learned to work but have a question on the efficiency of a One-to-Many mapping. It works, but I am pretty sure that it could be tweaked quite a bit. When saving, I notice that there are three queries that get executed, an insert for the "Parent" object, a...