recursive-datastructures

how to create tree structure recursive json & query for it ,where id =5 in nodejs

天大地大妈咪最大 提交于 2019-12-11 09:10:34
问题 Table for my folder structure id | name | parent_id ----+--------------+----------- 1 | parent | 2 | child | 1 3 | grandchild A | 2 4 | grandchild B | 2 5 | grandchild c | 3 select id,parent_id, name from table. I want to create a json for this result set which should be in tree structure. how to make a json for this, please help. 回答1: Something like this? { "1": { "name": "parent", "parent_id": 0 }, "2": { "name": "child", "parent_id": 1 }, "3": { "name": "grandchild a", "parent_id": 2 } }

Initialization order of values in objects: How to setup cyclic/recursive objects properly?

我们两清 提交于 2019-12-11 02:22:51
问题 The following code abstract class Table(val name: String) { val columns: List[Column] def getAliasColumns: String = { val reallyThere = columns.forall(c => c != null) println("Columns really there: " + reallyThere) if (reallyThere == false) { println(" columns " + columns) } columns.map(c => s"${c.table.name}.${c.name} as ${c.table.name}_${c.name}") .mkString(", ") } } class Column(val table: Table, val name: String, val foreignKey: Option[Column]) object Column { def apply(table: Table, name

Infinite self-referencing list

蓝咒 提交于 2019-12-10 18:46:57
问题 Problem I'm trying to implement the modified Dragon Curve from AoC Day 16 as an infinite list in Haskell. The list is composed of True and False . We start with some list s0 : s1 = s0 ++ [False] ++ (map not . reverse) s0 s2 = s1 ++ [False] ++ (map not . reverse) s1 s3 = s2 ++ [False] ++ (map not . reverse) s2 Generally sn = s(n-1) ++ [0] ++ (map not . reverse) s(n-1) = s0 ++ [0] ++ (f s0) ++ [0] ++ (f (s0 ++ [0] ++ (f s0))) ++ ... where f = (map not . reverse) Attempted Implementation I can

Why must coq mutually inductive types have the same parameters?

十年热恋 提交于 2019-12-10 15:31:32
问题 Following Arthur's suggestion, I changed my Fixpoint relation to a mutual Inductive relation which "builds up" the different comparisons between games rather than "drilling down". But now I am receiving an entirely new error message: Error: Parameters should be syntactically the same for each inductive type. I think the error message is saying that I need the same exact parameters for all of these mutual inductive definitions. I realize there are simple hacks to get around this (unused dummy

Database about a forum design issue

眉间皱痕 提交于 2019-12-10 12:18:59
问题 I am currently designing a database about a forum. The database will have for now the current tables - A table about the users, about the categories. The problem comes when I want to add the QuestionAndComments table. The QuestionAndComments table must have UserId (a foreign key pointing to the users table) and ParentId (will be null if it is a question and will have some value if it is a comment - the comment could be to a question or to an other comment) of the question but it must also

PHP RecursiveIterator traversing

北城余情 提交于 2019-12-10 03:09:02
问题 I have a structure representing a form and I want to iterate it using RecursiveIterator. The problem is this only returns the top-level questions. What am I doing wrong? Whole form: class Form implements RecursiveIterator{ private $id; private $caption; private $other_text; private $questions = array(); private $current; private function __construct(DibiRow $row){ $this->id = $row->id; $this->caption = $row->caption; $this->other_text = $row->other_text; $this->loadQuestions(); } private

get also element that don't match fnmatch

寵の児 提交于 2019-12-07 13:51:27
问题 I'm using a recursive glob to find and copy files from a drive to another def recursive_glob(treeroot, pattern): results = [] for base, dirs, files in os.walk(treeroot): goodfiles = fnmatch.filter(files, pattern) results.extend(os.path.join(base, f) for f in goodfiles) return results Works fine. But I also want to have access to the elements that don't match the filter. Can someone offer some help? I could build a regex within the loop, but there must be a simpler solution, right? Thanks in

use gob to package recursively defined structs

放肆的年华 提交于 2019-12-07 12:19:40
问题 I mostly use Python, but am playing around with Go. I wrote the following to do something that is quite simple in python, and im hoping it can be accomplished in Go as well. package main import ( "bytes" "encoding/gob" "fmt" "io/ioutil" ) type Order struct { Text string User *User } type User struct { Text string Order *Order } func main() { o := Order{} u := User{} o.Text = "order text" u.Text = "user text" // commenting this section prevents stack overflow o.User = &u u.Order = &o fmt

use gob to package recursively defined structs

瘦欲@ 提交于 2019-12-05 22:20:07
I mostly use Python, but am playing around with Go. I wrote the following to do something that is quite simple in python, and im hoping it can be accomplished in Go as well. package main import ( "bytes" "encoding/gob" "fmt" "io/ioutil" ) type Order struct { Text string User *User } type User struct { Text string Order *Order } func main() { o := Order{} u := User{} o.Text = "order text" u.Text = "user text" // commenting this section prevents stack overflow o.User = &u u.Order = &o fmt.Println("o.u.text:", o.User.Text, "u.o.text:", u.Order.Text) // end section m := new(bytes.Buffer) enc :=

PHP RecursiveIterator traversing

丶灬走出姿态 提交于 2019-12-05 03:31:51
I have a structure representing a form and I want to iterate it using RecursiveIterator. The problem is this only returns the top-level questions. What am I doing wrong? Whole form: class Form implements RecursiveIterator{ private $id; private $caption; private $other_text; private $questions = array(); private $current; private function __construct(DibiRow $row){ $this->id = $row->id; $this->caption = $row->caption; $this->other_text = $row->other_text; $this->loadQuestions(); } private function loadQuestions(){ $questions = dibi::query('SELECT * FROM cyp_questions WHERE form_id = %i AND