recursion

Is it necessary to clearTimeout inside a recursively invoked timer?

眉间皱痕 提交于 2019-12-31 04:29:27
问题 Is it necessary to call clearTimeout() inside a recursively invoked function in Coffeescript? My concern is whether not calling clearTimeout() will possibly cause some sort of memory leak over time if this function is run many many times per second. My thinking is the JS garbage collector handles this, but want to double check. A contrived example from a websockets/socket.io implementation I'm working on: socket.on 'dataReceived', => @_recursive_fn() _recursive_fn: -> @timer = setTimeout (=>

Recursive XAML binding data templates on the Universal Windows Platform

我的梦境 提交于 2019-12-31 04:22:06
问题 So I have a class Task which has a couple of properties and also can have a list Task objects ( child tasks ) inside it. I would like to recursively display each Tasks and their sub-tasks on the 'UWP'. Apparently 'WPF' had special 'UserControls' for that purpose according to this post: Are recursive DataTemplates possible? but they don't seem to be available on 'UWP'. 回答1: You can use TreeView Control. Here are the links to this project: NuGet:WinRTXamlToolkit and GitHub:WinRTXamlToolkit.

create dynamic nested json objects using recursive

烈酒焚心 提交于 2019-12-31 04:10:14
问题 I have following JSON. [{ "ID": "Root_1", "Name": "Root_1", "ParentID": "", "Sequent": 1 }, { "ID": "Root_2", "Name": "Root_2", "ParentID": "", "Sequent": 2 }, { "ID": "Root_1_Sub_1_Child_1", "Name": "Root_1_Sub_1_Child_1", "ParentID": "Root_1_Sub_1", "Sequent": 1 }, { "ID": "Root_1_Sub_1_Child_2", "Name": "Root_1_Sub_1_Child_2", "ParentID": "Root_1_Sub_1", "Sequent": 2 }, { "ID": "Root_1_Sub_1", "Name": "Root_1_Sub_1", "ParentID": "Root_1", "Sequent": 1 }] I want to change my JSON to as

Recursively creating a tree hierarchy without using class/object

泪湿孤枕 提交于 2019-12-31 04:08:12
问题 I am having trouble creating a tree hierarchy in Python 3. I'd like to be able to do this without using classes. The data I need to start with is not in order and in the format ['ID','Parent'] : data=[['E1', 'C1'],['C1', 'P1'],['P1', 'R1'],['E2', 'C2'],['C2', 'P2'],['P2', 'R1'],['C3', 'P2'],['E3', 'C4'],['C4', 'P3'], ['P3', 'R2'],['C5', 'P3'],['E4', 'C6'],['C6', 'P4'], ['P4', 'R2'],['E5', 'C7'],['C7', 'P5'],['P5', 'R3'],['E6', 'C9'],['C9', 'P6'],['P6', 'R3'], ['C8', 'P6'],['E7', 'C10'],['C10'

How can I unfold the recurrence: T(n)=2T((n+2)/3)

自古美人都是妖i 提交于 2019-12-31 04:04:05
问题 I'm trying to solve this recurrence, but I don't know how to unfold it. T(n)=2T((n+2)/3) + 1 Can I ignore that "+2" and solve it as it was 2T(n/3) + 1? This comes from a from a problem that uses a V[a..b] array and makes this return: return V(X) + f(V, a, Y) + f(V, Z, b) Where Y is (2a+b)/3 and Z is (a+2b)/3 So: ((b-a+3)/3) = ((n+2)/3) 回答1: Sort of. The rigorous version of this trick is to set U(n) = T(n+1) and write U(n) = T(n+1) = 2T((n+1+2)/3) + 1 = 2T(n/3 + 1) + 1 = 2U(n/3) + 1. Then

Sql Server CTE Parent Child recursive

别说谁变了你拦得住时间么 提交于 2019-12-31 04:00:45
问题 I have following table structure: create table Test( ParentId int, ChildId int ) insert into Test(ParentId, ChildId) select 1, NULL union select 1, 2 union select 1, 3 union select 2, NULL union select 2, 5 union select 5, 6 union select 6, 5 union select 6, 8 I'm trying to build a result set of all parent child DIRECT and INDIRECT relationships . So suppose I pass the parameter of ParentID = 2, I would like the result set to return exactly as below: ParentId ChildId ------------------- 2

Javascript function for handling multiple unknown callbacks

北战南征 提交于 2019-12-31 03:56:14
问题 I have a scenario where I would like to send in 2 or more functions (as parameters) into a handler function, and have that handler function execute each passed function as a callback function for the preceding function. Here is a general concept of the function I am trying to write: function functionChain() { // MAKE SURE WE HAVE AT LEAST 1 PARAMETER if ( arguments.length < 1 ) { return; } // for each parameter, call it (as a function) for ( var i=0; i<arguments.length; i++) { if ( typeof

Prolog recursively count numbers in a list

那年仲夏 提交于 2019-12-31 03:51:38
问题 I need a program to count all the numbers in a list, no matter how DEEPLY NESTED they are. I was able to count numbers in the case where they were not inside another list, but recursing through deeply nested elements is not working out. I have this so far: count([],0). count([H|Tail], N) :- count(Tail, N1), ( number(H) ->N is N1 + 1 ; is_list(H) -> count(H,N) ; N = N1 ). So, if I were to call count([a,1,[2,b],3],N) , the output should be N=3 ; however, I only get N=2 . Could someone please

Detecting Conflicts on a Scheduler Timeline (Algorithm)

99封情书 提交于 2019-12-31 03:50:09
问题 Suppose I am plotting events with a (StartTime,EndTime) on a 24-hr Calendar similar to Outlook. My goal is to detect overlaps (conflicts) and split them up such that each column occupies N% of the width of the window, where N = total number of conflicts in that time frame. My problem is, my algorithm 1) first, sort all events by StartTime 2) LOOP: looks at neighbors: CurrentEvent and NextEvent (n+1): if NextEvent exists { if (CurrentEvent EndTime > NextEvent StartTime) { // CONFLICT!

Arangodb AQL recursive graph traversal

纵饮孤独 提交于 2019-12-31 03:21:26
问题 I have a graph with three collections which items can be connected by edges. ItemA is a parent of itemB which in turn is a parent of itemC. Elements only can be connected by edges in direction "_from : child, _to : parent" Currently I can get only "linear" result with this AQL query: LET contains = (FOR v IN 1..? INBOUND 'collectionA/itemA' GRAPH 'myGraph' RETURN v) RETURN { "root": { "id": "ItemA", "contains": contains } } And result looks like this: "root": { "id": "itemA", "contains": [ {