Tag Info

New answers tagged

0

Do a "binning" of the initial black box stack into N groups of equal proportions (your A-D, D-K...). At that point you can use any O(n log n) algorithm to sort each group in turn. Actually, you could pop items from the black-box stack directly into a group of N red-black trees. But if you have lots of identical elements... could you not just store a ...


1

There are a lot of ads asking for "language agnostic programmers". They're looking for people who are okay with programming in whatever language is needed to get the work done. They want people who are totally fine with learning another language if that's what the project calls for. They're looking for people who aren't clinging to just one language and ...


0

We were told numbers could be up to about 10^12 and about 20% of numbers would be used. That is 2 * 10^11 numbers actually used. With these numbers, the best you can do is a bitmap of about 125 GBytes, and if you can't afford the RAM, an SSD drive and virtual memory will have to do. You should probably measure whether "normal" file access is faster than ...


-3

Just to add a suggestion to the other solutions. In the biomedical world we often search for specific strings of data (ie genetic patterns). Research has shown that attacking the parent string in the reverse direction, the last entry to the first, is faster that going forward through the string. I guess this is some how related to slurping in all the data ...


1

I would try to go for the bitfield too, but if the data is sparse and the range too great to make this work, a splay tree might be a good data structure to use. Splay trees are modified on each access (so they are not thread-safe, which could be an exclusion reason for you) to optimize repeated access to the same element. Often-used elements bubble to the ...


2

You could generate a binary tree (radix tree aka trie). To prepare for the search, for each number in your array, starting with the least significant bit, if it is 0, you look to the left node. If it is 1, you look to the right node. You follow the tree until you find no more nodes, and from there you create the tree one node at a time. To search, ...


8

If there is a known maximum N, you can use a Bit array for really fast lookup time. Simply keep an array of size N/8 (rounded up) around, with each bit corresponding to a number, 1 if it is in the set, 0 if it isn't. Lookup the relevant bit to check whether a number is in the set. If this is too slow, and you have the megabytes ("millions" doesn't sound ...


8

It's a bounded queue (a first-in-first-out queue with a fixed capacity). This particular queue always allows addition of elements and silently remove head element for newly added element (when full). In Java there is the CircularFifoQueue that works exactly that way (see also Size-limited queue that holds last N elements in Java). For .NET you'd take a ...


0

What if you auto-generate the file which contains the table declaration? Since it is auto-generated, you never need to diff that legible file itself. Diffing the input file will show only truly changed lines, since you will never reformat the input file to make it more legible. Q.E.D :-)


2

If you look at the version control diff, it's nearly impossible to see what was added as whole table has been rewritten Then don't look at the version control diff. For instance WinMerge, which is free & runs on both Windows & Linux has an option " Line differences with Whitespace: Ignoring all". Couldn't you use that? It won't show those ...


2

One possible kludge which would allow you to keep you change history but align your code correctly would be to comment out the entire existing table. And add a new correctly aligned table after it. This would/should be recorded as just two changes in the source code. After the new table been saved in the repository you can delete the commented out section ...


4

Naming things is hard. But in my experience, ambiguity like this can almost always be solved by using a slightly more verbose name in the right place. The alternative method names you suggested are indeed ugly; in this example my first choice would be to rename the parameters: public interface Component { int Read(int portID, byte[] outputBuffer); ...


5

There are few possible reasons for this sort of thing: As in JacquesB's answer it may simply be convenience for the library user to call a single method rather than two methods and keep their code more succinct. Performance may be a consideration. Calling .substring(3) will result in a new string being created, and therefore you are looping over the string ...


4

These are called convenience functions. They are included so users can write shorter and simpler code. Note that almost every library is "redundant" in the sense that users could write the same code themselves outside of the library. However the point of using libraries is that you save time and code, and you can reuses the knowledge of the library in ...


2

Why not both? I suppose you want a quick turnaround, without waiting for the session to get stored in the database. But this does not prevent you from putting the data into the database eventually, because probably users do not register a new session at every request for prolonged periods. I'd have an in-memory cache of a limited size, a queue, and a ...



Top 50 recent answers are included