Data structure & algorithms for super-interval queries on intervals with small integer ends

I would like to have an online data structure that supports inserting an interval, and given a query interval $ I_q=[l_q,h_q]$ answer if $ I_q$ is contained at some interval of the data structure, i.e. if $ I_q$ is a super-interval of some interval of the structure (so the answer of the query is just boolean, no need to output all such intervals on the structure) at the fastest possible time complexity.

I have searched for such a combination, and found out that probably an Interval Tree would be appropriate for my situation, with $ O(\log n)$ interval insertion and overlapping intervals query (so it’s not exactly my desired query, but I think that it could possibly be turned to it. Also I can avoid the output complexity dependence, since the desired output is boolean and therefore on the first match I would know the answer is true).

Furthermore, here ( it is stated that:

If the endpoints of intervals are within a small integer range (e.g., in the range [1,…,O(n)]), faster data structures exist with preprocessing time O(n) and query time O(1+m) for reporting m intervals containing a given query point.

Since I also can guarantee that both interval ends are going to be small integers (i.e. not floats, but natural integers up to $ \approx 10^6$ ), what would be the best data-structure/algorithmic way (considering time-complexity of the above two operations) to implement those two operations I would like to have?

If the fastest time-complexity would be an Interval Tree, then how can I modify the overlapping-intervals query to support my query in $ O(\log n)$ time, i.e. not $ O(k\cdot\log n)$ where $ k$ is $ I_q$ ‘s range? However, I am quite interested in the above quoted passage, and how I could possibly (with another data structure, maybe?) manage such a fast complexity, so in that case Interval Trees wouldn’t matter.

Note: In my attempt to test such an algorithm and speed on an Interval Tree, I have found out the following library: where a similar query seems to be implemented on the envelop query with a time-complexity of $ O(m+k\cdot\log n)$ , where “$ n$ = size of the tree, $ m$ = number of matches, $ k$ = size of the search range”, which however is not as fast as I would like (especially considering the $ k$ multiplying factor).

MVC Proper Structure Packaging

I wonder to know, in MVC, I do understand what the generic division between M, V and C is but I am definitely not sure what are good ways to manage the files under these. Assume Golang. For instance, a project structure would be:

pkg/views/ pkg/controllers/                 group.go                   * has a BBQ                   * StoreTeamBBQAtTeamMember()                   * SetColorBBQ()                   * CreateBBQ()                   * DeleteBBQ()                 BBQ.go                   * SetColor()                   * Create()                   * Delete() pkg/models/  group.go                 group.go                   * has a BBQ                   * StoreTeamBBQAtTeamMember()                   * SetColorBBQ()                   * CreateBBQ()                   * DeleteBBQ()                 BBQ.go                   * SetColor()                   * Create()                   * Delete() 

My idea is that group.go has a BBQ and can manage it in a “group” way, whereas BBQ.go is the BBQ itself and that of course makes it have some intrinsic for a BBQ methods – create, delete. Apparently, my example leads to overlaps between how we model a BBQ and a groupBBQ.

My questions are:

  1. Shall we strive to keep some rigorous vertical semantic encapsulation of what we model? For instance, there won’t be groupBBQ and group controllers and models but group and BBQ

  2. Is it a good practice to speak call one model’s methods from another model?

  3. Is it good or bad one controller to call another controller’s methods?

  4. Is it good or bad one controller to call another model’s methods?

  5. Is it good or bad practice the controller of e.g. groupBBQ to call a method defined under BBQ?

  6. Are these modelled well, or all methods of a BBQ have to stay under BBQ even if they’re group ones?

The example I came up with on the fly but pretty much is a real life situation I’m dealing with. Lately I have been doing mainly microservices, no MVC and such overlaps I see here tenderly disturb me. 🙂

Move Item from Drop Off Library to Destination Library and create folder structure in Destination Library based on certain criteria

The project i started with SharePoint from my previous question has moved to the second stage. The documents added to our Drop Off Library, after I manually run the workflow to strip the document name to its respective columns, will need another workflow to move the items from the Drop Off library to a destination library called “Employee Files” in the format below enter image description here

The Drop Off Library list has the following fields enter image description here

The workflow has to create a Root folder for example A (based on the last name index on Drop Off), then create sub-folder (a.) with last name, first name (emp ID) and sub-folder within (a.) based on the HR Employee File Category. I am able to come up with creating a folder in Employee Files library based on Last Name Index, or move just the document from Drop Off to Employee Files, but have no idea how to do all the necessary actions i.e create the complex sub folder structure, move to Employee Files and copy the document (there is an attached pdf before Name)inside one of these folders based on the HR category and the Payroll folder. Is the workflow in SP Designer 2013 doable?

Thanks again for all your help!


Code Structure: Keep classes simple or keep usage simple?

Tl;dr: In terms of the “high cohesion and low coupling” principle, how do I best deal with many simple objects that need to access the strings.xml resource in order to correctly parse an output?

I’m setting up an app in android studio that handles accounts and stores payments to those accounts. I have set up a class for payments and accounts respectively and until now tried to keep them as simple as possible, so they don’t have to store any references to other classes. However, since this is an android app, I want to make use of the formatting options provided by the strings.xml resource file.

My question is, is there a way to keep the classes as simple as possible(i.e. not have them deal with the main activity to get the strings.xml resource), while also preserving the simplicity of payment.getTimeString() call?

And if not, in terms of high cohesion and low coupling, would it be smarter to give all those elements a reference to the main activity, so they can access the strings.xml resource? Or would it be smarter to create a function in a handler class, that transforms the output of the payment- or account objects, which would mean that, when switching activities for example, I not only have to reference the object I want the new activity to work with, but also the handler that transforms the output? Or is there a different solution entirely that I’m not thinking about?

Example A:
Payment Class:

public class Payment implements Serializable {     private Calendar time;     private Activity mainActivity;     [...]      public Payment(Calendar time, Activity mainActivity, ...) {         this.time = time;         this.mainActivity = mainActivity;         [...]     }      [...]      public String getTimeString() {         DateFormat dateFormat = new SimpleDateFormat(mainActivity.getResources().getString(R.string.dateFormat));         return dateFormat.format(time.getTime());     } 

Example B:
Payment Class:

public class Payment implements Serializable {     private Calendar time;     [...]      public Payment(Calendar time, ...) {         this.time = time;         [...]     }      [...]      public Calendar getTime() {         return time;     } 


public class AccountHandler implements Serializable {     private Activity activity;     [...]      public AccountHandler(MainActivity activity) {         this.activity = activity;     }      public String parseTime(Calendar time) {         DateFormat dateFormat = new SimpleDateFormat(mainActivity.getResources().getString(R.string.dateFormat));         return dateFormat.format(time.getTime());     } 

Edit: I originally asked this question on StackOverflow. I was told to post it on Code Review instead, as it would better fit there. However on Code Review I was told that my question was not suited for Code Review and that I should ask here instead. So I hope the question does fit this board!

Data Structure for applying transformations upon universe of tuples


I want a data structure which describes a universe of tuples all of length $ n$ , $ U$ . In $ U$ we associate each $ tuple$ with a non-negative value, which we will denote as $ U.count(tuple)$ . If $ U.count(tuple)=0$ , then we consider $ tuple$ to not be in $ U$ . I want to be efficiently update these $ U$ with five operations, some of which involve two fixed constants $ maxVal$ and $ minVal$ . (to clarify, $ maxVal$ and $ minVal$ should not change throughout the process, and should a tuple in $ U$ should never have a value which exceeds $ maxVal$ )

1) append(U,c): yields an updated universe $ U’$ , $ c$ should be below $ maxVal$ . For each tuple $ t$ in $ U$ , make a copy $ t’$ , and append $ c$ to $ t’$ . For each $ t’$ , $ U’.count(t’) = U.count(t)$ .

2) add(U,c,i): yields an updated universe $ U’$ . For each tuple $ t$ in $ U$ , we create a copy $ t’$ , and add $ c$ to $ t'[i]$ . If $ t'[i]<maxVal$ , then then $ t’$ is in $ U’$ and $ U’.count(t’) = U.count(t)$ . Otherwise $ U’.count(t’)=0$ and for our purposes we no longer need to keep track of it, and can exclude it from $ U’$ .

3) merge(U,i,j): yields an updated universe $ U’$ . For each tuple $ t$ in $ U$ , we create a copy $ t’$ , we pop $ t'[j]$ , and add its value to $ t'[i]$ . In this case, there can be multiple tuples $ t$ which correspond to $ t’$ in $ U’$ , thus let us initially say $ U’.count(t’)=0$ and then add to this. Now, if $ t'[i] < maxVal$ , $ U’.count(t’) = U’.count(t’) + U.count(t)$ .

4) finish(U,i): yields an updated universe $ U’$ . For each tuple $ t$ in $ U$ , we make a copy $ t’$ and delete $ t'[i]$ . Again, for the same reasons as in 2, let us initially say $ U’.count(t’) = 0$ . If $ t[i] > minVal$ , then $ t’.count = t’.count + t.count$ . At the end, all $ t’$ with non-zero count are included in $ U’$ .

5) combine(U1,U2): yields an updated universe $ U’$ , $ U_1$ and $ U_2$ should have same length tuples. For each $ t$ in $ U_1 \cup U_2$ , $ U’.count(t) = U_1.count(t) + U_2.count(t)$

My thoughts so far (messy)

If we did this naively, and represented $ U$ as a list of the tuples with non-zero, this would be horribly inefficient. Let’s assume $ U.count(t) \neq 0$ for all $ t$ that don’t exceed $ maxVal$ . Then, with $ maxVal = 10$ , a universe for tuples of length $ 4$ , that’s 10,000 if statements for the add operation…

I think one optimization would to have a tree, where the first level has nodes for each value of $ t[0]$ , and the child of a node are the next element in the tuple. I’d imagine you’d do this by having a list of all your first level nodes. Each node itself, is represented as a tuple of its value, and a list of its valid children, or $ U.count(t)$ for leaves. With add at lower levels, you have much less updates to do, and by ordering children in a fixed way according to their value, and keeping childless nodes as placeholders, your only need to do the validity check once too. Furthermore, to make append efficient, instead of having the levels be consecutive indices, we could make the order arbitrary, describe the tree-level to tuple index conversion with another list. For stuff like combine I am less sure what’s a good way to do things, maybe it would be beneficial to actually sum the counts of shared tuples, but maybe there are a clever cheats or work arounds…

My explicit questions

1a) Is there an efficient data-structure which performs these operations?

1b) Otherwise, are there some general rules of thumb for data structure which are relevant for this problem or my proposed solution?

2) Same as above but for the case where combine is applied to a very large number of universes, instead of just 2.

Best way to store table structure

I'm developing a front-end for input/output/editing of multiple different tables. Is it in good practice to directly query the table structure using DESCRIBE and use that to construct the corresponding HTML tables & input forms? I'm also considering using the comments field to encode validation rules for individual fields.

REST API Structure to request multiple items

I have a REST API that looks something like the below where a person can belong to an organisation (but doesn’t have to) and a person has many items. The items may also belong to the organisation instead of the person.

/people/:personId /people/:personId/items /organisations/:orgId/items /organisations/:orgId/people/:personId/items 

There is a scenario where we want to query the items for multiple people within an organisation, what’s the correct URL structure to use?

Option 1


Option 2


Option 3


Repository structure for microservices

As part of a larger project, my team is building a microservices API layer. We do not have experience with building microservices so we have been trying to figure out how to go about the project.

The first decision we are working on is if we should use a mono-repository or split each microservice into a separate repository. It seems like there are pros and cons to each option.

A mono-repo will increase development time, promote code reuse and make refactoring easier. However, the code base is larger, longer clone time, could run into issues merging and could increase complexity of deployments.

A multi-repo approach will have smaller code bases, less code to clone and will reduce the deployment complexity. However, this approach will increase the development effort. Debugging time can increase and makes it difficult to share common code.

To sum it up, it seems multi-repo is better when the application is in production while a mono-repo is better for development.

With all that said, is there anything else I should consider when deciding whether to use a mono-repo or a multi-repo approach?

Collapsible Tree Structure View in SharePoint?

Is there any way to create a collapsible tree structure in SharePoint that would not only allow me to create an easily browsable structure (with + and – buttons to collapse and uncollapse each section) but would also allow me to upload a file (e.g. pdf or xls) under the last level of the structure so that a person viewing the structure might also download and read the file?

Basically, the reason behind all this is that I have a vast amount of separate files for which I would have to find a way to display in a hierarchical order for other people to view them and actually make sense of the entire structure & the files. (PS: Creating a folder structure on the computer won’t work because the names of some of the folders become too long and thus limit the maximum depth of the structure since at some point, the folder path reaches its limit.)