A recursive datastructure is a datastructure (e.g. a struct or class) that contains one or several references to instances of the same datastructure as a member.
Questions tagged [recursive-datastructures]
524 questions
4
votes
3 answers
OCaml Explicit polymorphic type annotations
I would enjoy to receive some helpful comments concerning an example given on:
http://caml.inria.fr/pub/docs/manual-ocaml-400/manual021.html#toc79
7.12 Explicit polymorphic type annotations
type 'a t = Leaf of 'a | Node of ('a * 'a) t
let rec…

user3351512
- 51
- 4
4
votes
1 answer
use gob to package recursively defined structs
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"
…

domoarigato
- 2,802
- 4
- 24
- 41
4
votes
2 answers
How do I generate recursive data structures on variadic templates?
I am trying to grasp the technique of recursive data-structure generation using TMP with this question.
Question
Suppose I have a variadic template template struct my_sets { };.
In my_sets I would like to generate a new type whose…

kfmfe04
- 14,936
- 14
- 74
- 140
4
votes
4 answers
Parse recursive data with parsec
import Data.Attoparsec.Text.Lazy
import Data.Text.Lazy.Internal (Text)
import Data.Text.Lazy (pack)
data List a = Nil | Cons a (List a)
list :: Text
list = pack $ unlines
[ "0"
, "1"
, "2"
, "5"
]
How can List Int parser coud be…

ДМИТРИЙ МАЛИКОВ
- 21,474
- 11
- 78
- 131
4
votes
1 answer
Memoization Recursion C++
I was implementing a recursive function with memoization for speed ups. The point of the program is as follows:
I shuffle a deck of cards (with an equal number of red and black
cards) and start dealing them face up.
After any card you can say…

Chen Li
- 151
- 1
- 2
- 9
4
votes
2 answers
How do I marshall a recursive struct to c sharp?
I have an unmanaged struct I'd like to marshal to c sharp that looks basically like this:
struct MyStruct{
/* ... some stuff ... */
int numChilds;
MyStruct *childs;
}
I believe that I have to write a custom marshaller but I'm not…

Roald
- 1,722
- 11
- 21
3
votes
2 answers
Get also elements that don't match fnmatch
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)
…

LarsVegas
- 6,522
- 10
- 43
- 67
3
votes
2 answers
Recursive CTE Query to make groups without duplicates
I need to build a sql query to find the least expensive squad (salary-wise) for teams in a European volleyball league.
For each team, the squad consists of 6 players. The entire team has 10 players (but could have more).
Positions…

VBStarr
- 586
- 6
- 17
3
votes
0 answers
How to infer recursive container types (with dependent types) in typescript?
Let's say I can have any of the following values in typescript and I pass it to a function:
[1, [2,3,4], 5]
[1, 2, [3,4,5]]
How can I type the function and the ReturnType of the function so I can preserve all the type information inferred from the…

PEZO
- 441
- 4
- 14
3
votes
3 answers
How to understand the "reflexive aggregation" relationship similar to reflexive association in UML
What does this class diagram mean? The class diagram of reflexive association uses solid lines and arrows, but here is replaced by a hollow diamond. Does it have anything to do with recursion? What will this class diagram generate? It would be best…

mc_wendy
- 43
- 5
3
votes
1 answer
Lifetime in recursive struct with mutable reference
I am trying to define a recursive struct similar to a linked list for a tree traversal. A node has some data and access to its parent. The child node should borrow its parent mutably to ensure exclusive access, and release it once it's dropped. I…

Demurgos
- 1,568
- 18
- 40
3
votes
1 answer
Typescript - type safe deep omit, or: how to list legal object paths
Alright, this is a long and very specific one. Would greatly appreciate any input.
I've written a recursive Omit type, which takes a type T and a tuple of strings (a 'path'), and indexes into T, removing the last item on the path and returning that…

Ran Lottem
- 476
- 5
- 17
3
votes
2 answers
DirectoryIterator scan to exclude '.' and '..' directories still including them?
In the script below, I'm trying to copy the folders that exist in the $base directory over to the $target directory. However, in my initial echo test, its returning the . and .. directories even though I'm trying to handle that exception in the…

Scott B
- 38,833
- 65
- 160
- 266
3
votes
1 answer
Searching in KD-tree slow
I'm implementing a KD-tree to cluster points a map into groups. I've been using Wikipedia's KD-tree article as a reference. The search returns the correct nearest neighbor point, but it is slower than I expected. Here is my code:
- (FDRKDTree…
3
votes
1 answer
deriving a Functor for an infinite Stream
I'm following this blog about F-algebras
It explains that
A terminal coalgebra is usually interpreted in programming as a recipe
for generating (possibly infinite) data structures or transition
systems.
and says that
A canonical example of a…
user6996876