efficiency

How to best handle exception to repeating calendar events

I'm working on a project that will require me to implement a calendar. I'm trying to come up with a system that is very flexible: can handle repeating events, exceptions to repeats, etc. I've looked at the schema for applications like iCal, Lotus Notes, and Mozilla to get an idea of how to go about implementing such a system. Currently I...

mySQL Efficiency Issue - How to find the right balance of normalization...?

I'm fairly new to working with relational databases, but have read a few books and know the basics of good design. I'm facing a design decision, and I'm not sure how to continue. Here's a very over simplified version of what I'm building: People can rate photos 1-5, and I need to display the average votes on the picture while keeping tr...

Most efficient way to combine two objects in C#

I have two objects that can be represented as an int, float, bool, or string. I need to perform an addition on these two objects with the results being the same thing c# would produce as a result. For instance 1+"Foo" would equal the string "1Foo", 2+2.5 would equal the float 5.5, and 3+3 would equal the int 6 . Currently I am using th...

Database design and foreign keys: Where should they be added in related tables?

I have a relatively simple subset of tables in my database for tracking something called sessions. These are academic sessions (think offerings of a particular program). The tables to represent a sessions information are: sessions session_terms session_subjects session_mark_item_info session_marks All of these tabl...

Is TFS is efficient for large teams and SVN efficient for small teams?

I'm and open source and SVN lover. We at the company are at a situation that must decide between SVN or Team Foundation Server. I'm trying to convince others to use SVN because I think TFS is enhanced in large teams. We are just 7 developers and 3 testers. Am I right about this? ...

Fastest way to uniqify a list in Python

Hi, Fastest way to uniqify a list in Python without preserving order? I saw many complicated solutions on Internet - could they be faster then simply: list(set([a,b,c,a])) ? ...

Python if statement efficiency

A friend (fellow low skill level recreational python scripter) asked me to look over some code. I noticed that he had 7 separate statements that basically said. if ( a and b and c): do something the statements a,b,c all tested their equality or lack of to set values. As I looked at it I found that because of the nature of the test...

Most efficient way to fetch and output Content with 2-Level Comments?

I have some content with up to 2-levels of replies. I am wondering what the most efficient way to fetch and output the replies. I should note that I am planning on storing the comments with fields content_id and reply_to, where reply_to refers to which comment it is in reply to (if any). Any criticism on this design is welcome. In pseud...

Is there a more efficient way to run enum values through a switch-case statement in C# than this?

I was wondering if there was a more efficient (efficient as in simpler/cleaner code) way of making a case statement like the one below... I have a dictionary. Its key type is an Enum and its value type is a bool. If the boolean is true, I want to change the color of a label on a form. The variable names were changed for the example. D...

Java Program Specialization - What is it? I don't understand it..

I'm reading about program specialization - specifically java and I don't think I quite understand it to be honest. So far what I understand is that it is a method for optimizing efficiency of programs by constraining parameters or inputs? How is that actually done? Can someone maybe explain to me how it helps, and maybe an example of wha...

How to keep only duplicates efficiently?

Given an STL vector, output only the duplicates in sorted order, e.g., INPUT : { 4, 4, 1, 2, 3, 2, 3 } OUTPUT: { 2, 3, 4 } The algorithm is trivial, but the goal is to make it as efficient as std::unique(). My naive implementation modifies the container in-place: My naive implementation: void not_unique(vector<int>* pv) { if (!...

Efficiency Question for an Ajax App

Hi, Currently I am dealing with a web application which uses a txt file as a database for testing for now. But we will connect it to a server later on. My question is, if there is a more efficient way to get my objects than the way I am using now. During the page_init I am getting all my objects into a Collection as List-<-TravelP->-,...

What container type provides better (average) performance than std::map?

In the following example a std::map structure is filled with 26 values from A - Z (for key) and 0 - 26 for value. The time taken (on my system) to lookup the last entry (10000000 times) is roughly 250 ms for the vector, and 125 ms for the map. (I compiled using release mode, with O3 option turned on for g++ 4.4) But if for some odd reas...

How do I most efficienty check the unique elements in a list?

let's say I have a list li = [{'q':'apple','code':'2B'}, {'q':'orange','code':'2A'}, {'q':'plum','code':'2A'}] What is the most efficient way to return the count of unique "codes" in this list? In this case, the unique codes is 2, because only 2B and 2A are unique. I could put everything in a list and compare, but is this...

What is the lightest way to make a huge chess-like grid?

Hey there I'm working on a browser-game and I can't help but wonder about what's the lightest way to make the grid/board on which the game takes place. Right now, as a mere sample, I'll show you this: -link no longer active, it was basically a 25x25 table+tr+td grid- Now, as the grid gets bigger and bigger, the table and its td's cre...

Efficiently Serving Dynamic Content in Google App Engine

My app on google app engine returns content items (just text) and comments on them. It works like this (pseudo-ish code): query: get keys of latest content #query to datastore for each item in content if item_dict in memcache: use item_dict else: build_item_dict(item) #by fetching from datastore store it...

Efficiently store last X records per item

I want to store the last X records in an MySQL database in an efficient way. So when the 4th record is stored the first should be deleted. The way I do this not is first run a query getting the items. Than check what I should do then insert/delete. There has to be a better way to do this. Any suggestions? Edit I think I should ad...

How can I efficiently group a large list of URLs by their host name in Perl?

I have text file that contains over one million URLs. I have to process this file in order to assign URLs to groups, based on host address: { 'http://www.ex1.com' => ['http://www.ex1.com/...', 'http://www.ex1.com/...', ...], 'http://www.ex2.com' => ['http://www.ex2.com/...', 'http://www.ex2.com/...', ...] } My current basic s...

How to effectively copy an array in java ?

The toArray method in ArrayList , Bloch uses both System.arraycopy and Arrays.copyOf to copy an array . public <T> T[] toArray(T[] a) { if (a.length < size) // Make a new array of a's runtime type, but my contents: return (T[]) Arrays.copyOf(elementData, size, a.getClass()); System.arraycopy(elementData, 0, a, 0, s...

MySQL index cardinality - performance vs storage efficiency

Say you have a MySQL 5.0 MyISAM table with 100 million rows, with one index (other than primary key) on two integer columns. From my admittedly poor understanding of B-tree structure, I believe that a lower cardinality means the storage efficiency of the index is better, because there are less parent nodes. Whereas a higher cardinality ...