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]
402 questions
4
votes
1 answer
Haskell Labeled AST: No instance for (Show1 (Label a)), How to construct an instance?
I want to have an annotated AST, so I defined those recursive data structures
using Fix:
data Term a
= Abstraction Name a
| Application a a
| Variable Name
deriving (Read,Show,Eq,Functor,Foldable,Traversable)
data Label a b
= Label a…
![](../../users/profiles/3794544.webp)
user47376
- 2,173
- 2
- 17
- 26
4
votes
1 answer
Swift recursive enum enters infinite loop in constructor
I've created a recursive enum in Swift that compiles without errors or warnings, but which enters an infinite loop when I try to instantiate it:
enum Tree {
case Leaf(T)
case Branch(T, [Tree])
}
Tree.Leaf(0) // enters infinite…
![](../../users/profiles/1305540.webp)
exists-forall
- 3,938
- 3
- 20
- 29
4
votes
2 answers
How do you update a QuadTree after an object has moved in C++?
The easiest method is removing and inserting the object, but there are probably faster methods. (If I'm overthinking this and I should just do it the simple way, let me know)
Here are some notes about my QuadTree
The objects that are moving are…
![](../../users/profiles/4930947.webp)
epitaque
- 63
- 3
- 9
4
votes
1 answer
jquery parse xml with unlimited child level category
I'm fairly new on parsing xml with jquery, so if my question looks like noobish, please forgive me.
I have an xml it contains my recursive categories. Some of them has sub categories, some of them not. It has some deep level categories under sub…
![](../../users/profiles/3199530.webp)
HddnTHA
- 981
- 3
- 17
- 36
4
votes
3 answers
'Default Behavior' for Haskell recursive data types
I'm trying to write a propositional logic solver in Haskell. I'm representing logical expressions with a recursive data type called 'Sentence' that has several subtypes for different operations - 'AndSentence', 'OrSentence', etc. So I guess it's a…
![](../../users/profiles/4700962.webp)
rwturner
- 43
- 4
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…
![](../../users/profiles/3351512.webp)
user3351512
- 51
- 4
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…
![](../../users/profiles/975129.webp)
kfmfe04
- 14,193
- 11
- 67
- 132
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…
![](../../users/profiles/570689.webp)
ДМИТРИЙ МАЛИКОВ
- 19,572
- 10
- 69
- 123
4
votes
2 answers
Recursive struct
Do I need to use typedef in order to build recursive structs? I tried to use the following code without success:
struct teste
{
int data;
int data2;
struct teste to_teste;
};
![](../../users/profiles/1843665.webp)
user1843665
- 193
- 1
- 2
- 7
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…
![](../../users/profiles/1725577.webp)
Chen Li
- 151
- 1
- 2
- 8
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)
…
![](../../users/profiles/1105929.webp)
LarsVegas
- 5,410
- 7
- 36
- 59
3
votes
1 answer
Recursive data type with partly fixed types
I have the following code
#include
#include
namespace std
{
template
pair(T1 t1, T2 t2) -> pair;
}
template
struct node {};
template
![](../../users/profiles/1360743.webp)
Reza
- 370
- 2
- 16
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…
![](../../users/profiles/6338059.webp)
Ran Lottem
- 416
- 5
- 14
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…
![](../../users/profiles/209102.webp)
Scott B
- 35,095
- 61
- 148
- 245
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…