nested

Recreate a flattened tree

僤鯓⒐⒋嵵緔 提交于 2019-12-13 15:41:06
问题 I have a vector of maps, that I'd like to transform in a nested fashion. The data is structured as follows: (def data [{:id 1 :name "a" :parent 0} {:id 2 :name "b" :parent 0} {:id 3 :name "c" :parent 0} {:id 4 :name "a_1" :parent 1} {:id 5 :name "a_2" :parent 1} {:id 6 :name "b_1" :parent 2} {:id 7 :name "a_1_1" :parent 4}]) Each map has an :id , some other keys and values not important for this discussion, and :parent key, denoting if the elements belong to another element. If :parent is 0,

Java Nested Foreach SLOW When Casting

三世轮回 提交于 2019-12-13 15:25:07
问题 I am writing an exchange system in Java, but I seem to have run into a crippling performance issue. The following code is where execution becomes VERY slow: outer: for(ArrayList<Offer> listSell : sellOffers.values()) { for(Offer sellOffer : listSell) { ArrayList<Offer> listBuy = buyOffers.get(getStorageHash(sellOffer)); if(listBuy == null) continue outer; for(int i = 0; i < listBuy.size(); i++) { Offer buyOffer = listBuy.get(i); //todo - handle exchange } } } After looking deeper into this, I

Why is it legal to declare nested public types inside an internal type? [closed]

不打扰是莪最后的温柔 提交于 2019-12-13 14:29:12
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 years ago . Shouldn't it be forbidden to declare a nested type that is more accessible than the parent? To expand on why i asked this is why 来源: https://stackoverflow.com/questions/33652663/why-is-it-legal-to-declare-nested-public-types-inside-an-internal-type

Nested Scopes and Lambdas

我只是一个虾纸丫 提交于 2019-12-13 14:06:18
问题 def funct(): x = 4 action = (lambda n: x ** n) return action x = funct() print(x(2)) # prints 16 ... I don't quite understand why 2 is assigned to n automatically? 回答1: n is the argument of the anonymous function returned by funct . An exactly equivalent defintion of funct is def funct(): x = 4 def action(n): return x ** n return action Does this form make any more sense? 回答2: It's not assigned "automatically": it's assigned very explicitly and non -automatically by your passing it as the

Typeahead v0.10.2 & Bloodhound - Working With Nested JSON Objects

有些话、适合烂在心里 提交于 2019-12-13 11:53:32
问题 UPDATE Based on the correct answer from @BenSmith (https://stackoverflow.com/users/203371/BenSmith) I was able to find my problem and found out I was not navigating through my JSON hierarchy properly. Here is the working code: // instantiate the bloodhound suggestion engine var engine = new Bloodhound({ datumTokenizer: function (datum) { return Bloodhound.tokenizers.whitespace(datum.title); }, queryTokenizer: Bloodhound.tokenizers.whitespace, prefetch: { url: "SampleData.json", filter:

python nested list unexpected behaviour [duplicate]

醉酒当歌 提交于 2019-12-13 10:23:08
问题 This question already has answers here : List of lists changes reflected across sublists unexpectedly (13 answers) Closed 3 years ago . I've ran into an unexpected behavior when using a nested list in python, that took a while to debug. If a list is initialized like this: a = [[None] * 2] * 2 a [[None, None], [None, None]] and another list initialized like this: b = [[None, None], [None, None]] b [[None, None], [None, None]] I would expect the same behavior from both these lists, but if I do:

SQL - Can I have a Group By clause after a nestled Select?

跟風遠走 提交于 2019-12-13 10:22:23
问题 For example: Select max(date) From table A Where max(date) < any (select.. ...) Group By Book_Name,Client_Name So the max(date) field could be compared to the Nestled Select return, as if the grouping of the greater Select was already made. 回答1: What you want is typically done with the HAVING clause. Select Book_Name,Client_Name, max(date) From table A Group By Book_Name,Client_Name HAVING max(date) < any (select.. ...) I removed reference to the other answer. I don't think it was correct and

How would I flatten a nested dictionary in Python 3? [duplicate]

对着背影说爱祢 提交于 2019-12-13 10:03:09
问题 This question already has answers here : Flatten nested dictionaries, compressing keys (25 answers) Closed 5 years ago . Is there a native function to flatten a nested dictionary to an output dictionary where keys and values are in this format: _dict2 = { 'this.is.an.example': 2, 'this.is.another.value': 4, 'this.example.too': 3, 'example': 'fish' } Assuming the dictionary will have several different value types, how should I go about iterating the dictionary? 回答1: You want to traverse the

Translating four nested loops into a CUDA kernel

僤鯓⒐⒋嵵緔 提交于 2019-12-13 08:52:47
问题 I'm writing CUDA program that adds blur effect onto BMP files. I wrote working program that does this on CPU, now I'm trying to convert the code to CUDA. This is the function I want to work on CUDA: void blur(bitmap_header* hp, unsigned char *data) { int xx,yy,x,y, avgB, avgG, avgR, ile; int blurSize = 5; for(xx = 0; xx < hp->width; xx++) { for(yy = 0; yy < hp->height; yy++) { avgB = avgG = avgR = 0; ile = 0; for(x = xx; x < hp->width && x < xx + blurSize; x++) { for(y = yy; y < hp->height &&

Getting HIERARCHY_REQUEST_ERR when using Javascript to recursively generate a nested list

我只是一个虾纸丫 提交于 2019-12-13 08:07:20
问题 I have a method that is trying to take in a list. This list can contain data and other lists. The end goal is to try to convert something like this ["a", "b", ["c", "d"]] into <ol> <li> <b>a</b> </li> <li> <b>b</b> </li> <ol> <li> <b>c</b> </li> <li> <b>d</b> </li> </ol> </ol> The code is: function $(tagName) { return document.createElement(tagName); } //returns an html element representing data //data should be an array or some sort of value function tagMaker(data) { tag = null; if(data