New answers tagged

0

There are two ways to go about designing an API. You can either design the objects and then build the API's contract from the objects, or you can design the API's contract and the build the objects to facilitate this. In this case, you may find that going with the contract first design approach may be easier to work with. Side bit - glance at swagger as ...


0

There is a good answer already given, but you could also implement a max-heap then insert an element with a priority equal to the number of elements currently in your heap.


2

Trivially. Your stack object simply maintains a tree of ints. The Push operation is identical to the insertion of an item in the tree whose key is one greater than the key in the current maximum. That should be the key in the root note, and the new node becomes the new root. The Pop operation is removal of the node with the greatest key (the root). ...


3

What are some reasons you may choose a worse runtime algorithm? By far the most common reason is that the "worse" algorithm is a lot simpler, or is the first solution I think of, and getting mathematically optimal performance just doesn't matter in the part of the code I'm currently working on. Which is most parts of the code. Another common reason is ...


1

I saw an interesting talk last year with a couple related papers about using a technique called programming by example on your sort of problem. They had impressive results on spreadsheets, and the technique could probably be adapted to database tables and REST interfaces. The basic idea is the user highlights some examples of the data they wish to extract, ...


1

An map/association of sets/enums? Each key is the verb form. Base/infinitive can be a special case, outside the map. Each value is a set of what conjugations it represents. for an arbitrary form answer the question what conjugations the form represents. That's a lookup of the key, returns the set of conjugations. for an arbitrary ...


-2

Adding another answer as have not seen a reference to build systems like make which uses DAG to find out dependencies for building. More details here


2

You should consider the idea that specifications change. Today there are 50 default fields, tomorrow there could be 51. You do not want to be adding a column every time the requirements change. The reverse might also be true; what if a column is no longer mandatory or is no longer required? The sample ERD below allows the following: people can take a ...


0

I would go for option 1., but I think there is no reason for: a json string which defines the custom fields. Some databases ( eg. PostgreSQL ) have support for traversing JSON, so to get list of keys from a JSON you make: select key from json_each('{"a":"foo", "b":"bar"}'); So in your example you can just select that JSON from answers table ( via ...


7

The clue to finding the right data structure here is that the requirements (other than the space requirements and direct accessibility) are those of a binary tree. This got me thinking about how you could modify a binary tree to make it meet the requirements. What you can do is to effectively serialise into an array a pre-order breadth-first traversal of a ...


4

I'm going to respectfully disagree with Michael here, and some rather smart programmers, like Rich Hickey, tend to think along the same lines as me. The key here is that you take care not to pass this data structure all over the place, but you use it as a base layer from which you build the sort of abstractions that Michael talks about in his answer. These ...


13

This is a dumb, stringly typed data structure. It is a: List of Maps keyed by String of Maps keyed by String of Local date array This makes it difficult to create, traverse, and could very well get you into code that looks like: foo.get(1).get("bar").get("qux")[42] And guess what... you've got a null pointer exception that was thrown on that ...


0

Is there a language, or a language-agnostic design pattern, that makes it easy to define a generic public interface that works with any data structure? Haskell seems like an awesome suggestion, but maybe a bit hardcore. At least I'm a little bit afraid of Haskell (it's a language whose code always inspires me, but I never actually got the nerve to ...


4

When programming in C I have found it invaluable to pack structs using GCCs __attribute__((__packed__)) [...] Since you mention __attribute__((__packed__)), I assume your intention is to eliminate all padding within a struct (make each member have a 1-byte alignment). Is there no standard for packing structs that works in all C compilers? ... ...


0

If your idea is that by storing data in a database in case an error occurs you don't need to parse it again: Errors should be rare, they are a big hit anyway, so a little bit of time for parsing wouldn't matter. On the other hand, you must now make sure that the database file is still there, that it hasn't been modified or overwritten, you must delete it ...


0

There is a very old joke circa 1916. A harassed young lieutenant sent the message "Send reinforcements we are going to advance" via a runner who passed on the message by telephone and eventually a telegram was received at HQ. A confused general received the message "Send three and fourpence we are going to a dance" and duly sent the correct change. EXCEL is ...


1

(since you code in PHP, I am guessing that the Excel file is uploaded in some browser, so is coming from the Internet; if it is not the case, ignore my answer) Is it better practice to store the parsed data in a database first and then use the data however I wish? I believe that yes. The data is coming from an untrusted source, the "bad Internet", so ...


5

For me it makes more sense as then I don't need to re-parse if errors occur when sending the email for example. In such a case, the main decision criteria are simplicity and performance (which depend not only on the process you are implementing, but also how you do it). For example, when the running time for re-parsing the input file is negligible, ...


2

I think parsing the file and storing the data to a database would be a good idea. It provides a transactional history so you can retry failed messages, audit records sent, and provide reporting. That said, if you have no requirements to support any of those functions and no possibility of having them in the future, writing to a database would just be ...


0

Depends on the business model. Let us say it like this. If the processed excel file should generate a different result to the previous one, I would say store and according the request the model process the output different previous according the uri. But if the data is running on the same data the same routine (request), with the service resultset, ...


0

A very common alternative is "named padding" : struct s { short s1; char c2; char reserved; // Padding }; This does assume the structure will not be padded to 8 bytes.


5

No all architectures are the same, just turn on the 32 bit option on one module, and see what happens when using the same source code and the same compiler. Byte order is another well known limitation. Throw in floating point representation and the problems get worse. Using Packing to send binary data is non-portable. To standardize it so it was practically ...


11

In a struct, what matters is the offset of each member from the address of each struct instance. Not so much is the matter of how tightly things are packed. An array, however, matters in how it is "packed". The rule in C is that each array element is exactly N bytes from the previous, where N is the number of bytes used to store that type. But with a ...


4

I'm no expert on JS or PHP so there might be some caveats I'm not aware of, but these are some ideas that come to my mind when I see this. First off, I think your first idea is great. To answer the points you are raising: Is it okay to use the property "name" twice, since they are on different levels? I've read that it's better to keep the property ...



Top 50 recent answers are included