New answers tagged

1

For the question as posed, a queue would work OK. Though the monitoring would need to include the total number of events in the queue, too. Monitoring the timestamps of the head and tail is optional, perhaps a nice-to-have. A Java BlockingQueue would offer most of the things we need. The network side can use the ...


1

You might find some useful inspiration from relational-database indices, which seek to solve a similar problem of finding rows which have a certain value in a column. However I wonder if it can be done in < O(n)? I'd look at trees, either self-balancing search trees or (if you have a lot of data) B-trees. You can probably achieve O(n) storage and ...


1

I am strongly against procedures, I don't believe any business logic (including logic that says in which format you should query a database) belongs to the database, but to the code itself. Even though in your case the simplest solution is to simply create a new function in your code, make a getUsersByEmail procedure in the database and call this newly ...


1

It seems like in your app, having two separate functions (Option 1) is a simple enough solution because you have these distinct ways of getting user details at different places in your application. If you wanted to have a single function that has to determine whether you're giving it an ID or an email, that type of logic isn't too difficult. You can even ...


0

Given Have StandardizedData, Collection, and CollectionCollection store than the standardization info. I'd like to avoid this scenario if possible as there could be a 1000 StandardizedData object which will be loaded into the small memory of mobile devices. you could investigate the flyweight pattern. If your standardisation info is replicated, ...


1

When you only needed to deal with Transactions, then a single Transactions table was sufficient. Now you need to know about summarisations at the Account level. Yes, you could calculate these dynamically, but this will get progressively slower the more Transactions you have to trawl through. This isn't a User Experience decision. How often will a User ...


6

It depends on what you're willing to do in terms of architectural/performance payoffs. It sounds like at the core you're doing a kind of Event Sourcing, which actually makes a lot of sense when you start talking about domains where it's important to have audit-trails for exactly what happened. I think a key-point for avoiding "code rot" is to make sure that ...


2

Yes, O(5) is the same thing as O(1). If you've been asked to implement a function in O(1) time, it means it needs to run in the same amount of time no matter how large the data being provided to it is.


1

The most efficient would probably be a binary format which you could read directly into memory, skipping the parsing step.


2

Use the factory-pattern. A factory is an object which creates objects. So when you have a weapon which shoot projectiles, pass a ProjectileFactory to it and leave the creation of the projectile to that class. You can then have different classes which extend ProjectileFactory, like BulletProjectileFactory, ExplosiveProjectileFactory, ...


2

You can do better than either XML or JSON by exploiting the particular characteristics of your particular data. If the data is completely flat and every row contains the same fields, then CSV is going to be more efficient than either XML or JSON. The reason people generally prefer formats like XML and JSON is because they recognise that the life-time cost of ...


1

The downside of your inefficient proposal comes when there are 2 jobs for a category. Now one is working..and everyone else is doing a busy wait. You can make this good enough by having workers scan through the queue for a next doable task, then return everything but that to the queue if they find one. Alternately return everything, then sleep. If the ...


2

This is an example where the forward links in the graph are difficult to calculate, but the reverse links are quite easy, so index those instead. Go through the word list and create entries for every link back to the word. For example, the word "cat" would generate the following index entries: ".at" -> Set("cat") "c.t" -> Set("cat") "ca." -> ...


4

There are two parts to this problem. One: the unknown list of possible categories. Two: interprocess communication between the workers to prevent two jobs of the same category being processed simultaiously. If you had a known list of categories you can have one queue and one worker per category. With unknown categories, you can still have a queue per ...


1

From what i know there is no way like you mentioned to hook the vertex to some node. what you can do is to take the elements from smaller tree and insert them into the larger one.(Long method) Or You can do inorder traversal of 1st tree store it in array1 takes O(n) time. Apply same for 2nd tree and store in array2 O(n) time. These 2 arrays would be ...


0

You have two choices, other than rolling your own -- slap a facade over a modifiable list (like UnmodifiableList) that doesn't allow modification through that interface, or use one of the available third party libraries that is truly immutable. The problem with the facade approach is that someone (say, a subclass) could modify the underlying list, breaking ...


4

It appears you have two requirements here: Event exposes collections, but callers cannot modify those collections. Event can modify its collections, but only through the Event class. It sounds like you need to use immutable collections, for example, java.util.Collections.unmodifiableList(List list). However, you do not want to store an immutable ...


6

On languages such as Haskell, most datatypes have instances which allow their values to be used as keys of structures such as Maps. It's the same in ECMAScript. Any object, including primitives, can be used as the key in a Map. Even NaN, even though NaN !== NaN // true does the right thing and can be reasonably used as the key in a Map. JavaScript ...


3

What you really want is a Map, not an object: Map You need to check if the support you need to provide fits with the Map supported browsers, but that´s what you really want as objects only take strings or symbols as keys while a map can take anything Here is an example of its usage: var point1 = {"x": 7, "y": 8, "z": 9}; var point2 = {"x": 6, "y": 5, ...


0

When writing GoJS we solved this by having the following rules for data: Every node has a key, which must be unique Links can be represented one of two ways: In a Tree-like fashion (TreeModel), or as separate JSON object entities (GraphLinksModel) If the flowchart or diagram is created in a Tree-like fashion, with only one parent per Node, then you don't ...


1

What I would do. Repackage the data on disk in small cubes, a few KB each. That is, if the data are represented as a typical array of arrays of arrays, the points that are close in the 3D space are not close in the representation. I'd try to overcome that. The result would be a the same amount of data, addressable in two steps. First step would be finding ...


0

You could consider the use of Guava's Table. The instances of this interface create a mapping between two elements and a third one. In your case, it would be a map between (Key1,Key2) and List (or a Value object, depending on the meaning of the extra values. A typical implementation is the HashBasedTable, which is unsurprisingly based on the key hashcodes. ...


4

If key2 is not unique, you can't use a Map to store a key2 -> (value1,value2,value3) relationship, since a Map asserts a 1-1 key/value relationship. I would not worry about performance initially, since you have 100's of objects (as opposed to millions), and I would prefer simplicity/readability to begin with. Hide your lookup behind an interface (so that ...


5

A grid or datagrid is a kind of user interface widget used to display tabular data. A database is a software system that manages read and write operations on large amounts of structured persistent data. Here are some typical goals/features for a database that don't apply to a datagrid: Ensure transactions always complete in their entirety, or get fully ...


0

Working code (not pseudocode as I said, duh! but this is more explicative): I have two file desciptor, one for client and another for server, both opened with socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); the select() checks if client of server sent something, the fd_set is only for reading (from client and server). Warning: I'm not sure if I close correctly ...


0

QOS Algorithm If possible, you can solve this with multiple threads (or processes): One thread/process receives requests and puts the request into the queue with the right priority. Another thread/process blocks waiting for requests arriving in any of the queues. When the thread/process wakes, it sends the messages that are in the queues, first checking ...


1

I think you're looking for isomorphic. An "isomorphism" is a 1-to-1 structure-preserving mapping between two sets of objects. Two objects are said to be isomorphic if a given isomorphism maps them to each other. This concept usually corresponds to our intuition that the two sets are "different representations of the same thing", including the fact that ...


0

If you are talking about huge data, you should consider using BTree data structure (or its variants). BTrees are used by most relational databases for indexing huge data. You can check B-tree on Wikipedia for more details. Based on the amount of data you have to deal with, your objective functions vary. For example, if you have to deal with very huge data, ...


1

Instead of precomputing all the possible combinations, just precompute levels of power of 2. So first would be M0_1=M0*M1, M2_3=M2*M3, M4_5=M4*M5, ... Second would be M0_3=M0*M1*M2*M3, M4_7=M4*M5*M6*M7, ... And so on, until biggest power of 2 that is smaller than n. This will take only 2x more memory. Then, you can pick subdivide the range so that the ...


0

For middleware I would put a bus in order to concentrate all the possible sources of data and offer a single interface of access. Such interface will provide VC facades. You can also implement your own bus service. And the solution of Repos already exposed could fit very well under such bus "layer/service" For View layer, as you pointed its mandatory to ...


0

I prefer using Repository Design pattern with large application, you can create repo classes that responsible for fetch data from Web Services and cached it with anyway you prefer. I prefer using abstract Factory For Web Services and its configuration Classes which will give me extensibility to switch to new service or upgrade configurations. also i will ...



Top 50 recent answers are included