Tag Info

New answers tagged

1

I don't particularly care for any of your proposed approaches simply because it's tying your classes directly to your configuration. Which means that once you do decide on an approach then you are pretty much stuck with it. Instead, you should consider adopting more of a dependency injection approach. class Bootstrap { public function ...


0

The common resolution I have come across (in visualisation problems, not in games) is to ditch one of the points, either always replacing or never replacing. I suppose the main point in favour is that it is easy to do.


1

If you have enough of these little configuration values that you feel the need to put them in another file, then they should go in a configuration file, not a source code file. There are countless ways of implementing config files, but I believe PHP has some standard approaches. To answer your numbered questions more directly: 1) They're never really ...


3

I recommend using an R-tree (link to Wikipedia). This is the standard data structure that most use for doing this sort of spatial indexing. R-trees are tree data structures used for spatial access methods, i.e., for indexing multi-dimensional information such as geographical coordinates, rectangles or polygons. The R-tree was proposed by Antonin Guttman ...


0

From a purely technical standpoint, an anti-tree is what you have every time you choose to represent a tree not by equipping each parent node with an array of pointers to its child nodes, but by equipping each child node with a single pointer to its parent node. Trees are commonly represented this way, for example, in relational databases.


3

There sorta kind of is and isn't! But we need to refine our terminology to understand what's going on. We have a hierarchy like this in graph theory, which flows from general at the top to more specific/restricted at the bottom: Graph: a collection of nodes (vertex) and paths (connections between vertex) Connected graph: a collection of nodes where you ...


1

I'm not sure of an exact mathematical concept for what you are describing, but it does seem to match pretty closely to the concept of a directed acyclic graph aka DAG. Many programmers actually use DAGs every day in their work, in the form of version control software. Git (and Mercurial and etc) commit histories form a DAG. We track the leaf nodes (in Git, ...


6

If you view a tree as undirected graph without loops, then the opposite of that is just the same tree - it's completely isomorphic. If you speak about an actual data structure which uses directed graphs, then, again, it can be just named "tree" which has it's links inverted: normally you have children referencing their parents (like is SQL database you'd ...


0

I'm not really sure what the meaningful difference would be, nor how you would go about implementing such a thing. The two ways I have seen trees implemented is either with an array or a by reference. In an array implementation, the first element is the root and child nodes can be located by a fairly simple transformation of the parent's index. You could ...


1

JIT compilation tracing techniques often make "hot" objects transformed into instances of hidden (and dynamically created) classes or structures, for which property access becomes as fast as field access in a C struct


0

The previous answer works ONLY IF the key are a built-in type. To complement the previous answer, here is a way to implement a set whose elements are user-defined types: package math // types type IntPoint struct { X, Y int } // set implementation for small number of items type IntPointSet struct { slice []IntPoint } // functions func (p1 ...


1

Since you say that approximations will work for you, what I would do is that I would pick a time interval like 1 second and I would treat it as a quantum. I would record all information of interest from every event happening during the quantum, and at the end of the quantum I would summarize everything that happened and discard the details in preparation ...


0

In the case I=0 (from beginning), the fastest way to compute the average values is this way. You should quantize your data in intervalls to discrete values like 0ms-1ms = 1 1ms-2ms = 2 ... 40ms-50ms = k 50ms-70ms = k+1 ... >5000ms = n (also for never responded) The more unlikely the measured latency value is in real world, the wider should be the ...


3

Building on Franck's comment, you can use a DataSet to save to XML. Writing DataSet Contents as XML Data System.IO.StreamWriter xmlSW = new System.IO.StreamWriter("Customers.xml"); // This example assumes you have a custom dataset called ds holding customer data ds.WriteXml(xmlSW, XmlWriteMode.WriteSchema); xmlSW.Close(); This will produce an XML file ...


2

Adding a "tenant" column (ClientId in this case), and using that to filter by tenant, is logically identical to having a separate database for each tenant. The only difference is, you have to remember to use that everywhere. This is true for everything in the database, not simply your nested sets. You are safe, assuming you are careful in writing the stored ...


5

Depending on what kind of requirements you have for the application you're trying to build. (Maybe if you are a litle more specific I can help you more, otherwise is a too generic question). There's many ways of saving complex data. For example, and naming only a few ways to do it, you can use a small database like SQL Compact or SQLite, or you can just use ...


1

I am on mobile so bear with me. This is a basic walk through of object serialization. I think that there are pros and cons to either solution. You have to weigh them out and decide which is right for you, but I would go with a database. I would say my reasoning is quite arbitrary but this is exactly the purpose of a database. However... If I were going ...


1

To protect yourself against garbage input, you should validate the input as the user enters it. In the large majority of cases, your garbage input won't be as bad as "paoghsfodgvfnamox33" for a com-port, but rather clumsy typing, like "\ttys\comn2". If you catch these errors as soon as possible, while the user is still editing the configuration, then the ...


1

In general, one can write a checksum with the data that can be recomputed at read time and compared with the written value. If they do not match, you know there has been data corruption (or your checksum is out of date). You could go a step further and provide enough redundant information to repair the corruption (error correcting codes), but this might be ...


2

What "polynomial time" means is that if you calculate a formula describing how long the algorithm will take to complete on a data set with n elements, the largest-magnitude term in the formula will be in the form of n^x. Here are a few examples of runtime classes: O(1): the runtime does not get larger as the data set increases in size. Example: Array ...


1

A classic example of an O(n³) algorithm is matrix multiplication. Multiplying two 10x10 matrices together will require 10^3 multiplications. In practice, however, modern algorithms such as the Coppersmith–Winograd algorithm can bring the order down to about 2.37.


1

Consider finding the smallest element in an unsorted collection. While you could use an array or linked list to hold the data, the time complexity will be O(n) as each element has to be examined as that could be the smallest that hasn't been known yet.


1

One of the most common ways to express polynomial time, O(nk), is nested loops where n is used as an input to calculate the maximum iterations of each loop and k is the level of nested loops. For example, this loop is O(n2) because it is a doubly-nested loop where n is the number of iterations: int n = ...; int x = 0; for (int i = 0; i < n; ++i) { for ...



Top 50 recent answers are included