Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CompilerbauAufgabe1
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Moritz Elias Plonka
CompilerbauAufgabe1
Commits
c3e99e90
Commit
c3e99e90
authored
2 years ago
by
moritz.plonka
Browse files
Options
Downloads
Patches
Plain Diff
Implemented syntree.
parent
2ac386de
Branches
main
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/syntree.rs
+31
-9
31 additions, 9 deletions
src/syntree.rs
with
31 additions
and
9 deletions
src/syntree.rs
+
31
−
9
View file @
c3e99e90
...
...
@@ -14,15 +14,22 @@ pub struct Syntree<T> {
// Hint: Start with seek_node_mut
impl
<
'a
,
T
>
Syntree
<
T
>
{
pub
fn
new
(
value
:
T
,
id
:
ID
)
->
Syntree
<
T
>
{
todo!
()
let
children
=
Vec
::
new
();
Syntree
{
id
,
value
,
children
}
}
pub
fn
push_node
(
&
mut
self
,
parent_id
:
ID
,
new_node
:
Syntree
<
T
>
)
->
Result
<
(),
String
>
{
todo!
()
pub
fn
push_node
(
&
mut
self
,
parent_id
:
ID
,
new_node
:
Syntree
<
T
>
)
->
Result
<
(),
&
str
>
{
let
current_node
=
self
.seek_node_mut
(
&
parent_id
);
if
current_node
.is_none
()
{
return
Result
::
Err
(
"The listed node does not exist."
);
}
let
current_node
=
current_node
.unwrap
();
current_node
.children
.push
(
new_node
);
return
Result
::
Ok
(());
}
pub
fn
prepend_node
(
&
mut
self
,
parent_id
:
ID
,
new_node
:
Syntree
<
T
>
)
->
Result
<
(),
String
>
{
todo!
(
)
pub
fn
prepend_node
(
&
mut
self
,
parent_id
:
ID
,
new_node
:
Syntree
<
T
>
)
->
Result
<
(),
&
str
>
{
self
.insert_node
(
parent_id
,
0
,
new_node
)
}
pub
fn
insert_node
(
...
...
@@ -30,8 +37,14 @@ impl<'a, T> Syntree<T> {
parent_id
:
ID
,
index
:
usize
,
new_node
:
Syntree
<
T
>
,
)
->
Result
<
(),
String
>
{
todo!
()
)
->
Result
<
(),
&
str
>
{
let
current_node
=
self
.seek_node_mut
(
&
parent_id
);
if
current_node
.is_none
()
{
return
Result
::
Err
(
"The listed node does not exist."
);
}
let
current_node
=
current_node
.unwrap
();
current_node
.children
.insert
(
index
,
new_node
);
return
Result
::
Ok
(());
}
// Anmerkung: `'a` Is ein Lebenszeit angabe für die Referenzen
...
...
@@ -50,7 +63,16 @@ impl<'a, T> Syntree<T> {
}
pub
fn
seek_node_mut
(
&
'a
mut
self
,
id
:
&
ID
)
->
Option
<&
'a
mut
Syntree
<
T
>>
{
todo!
()
if
self
.id
==
*
id
{
Some
(
self
)
}
else
{
for
child
in
&
mut
self
.children
{
if
let
Some
(
result
)
=
child
.seek_node_mut
(
id
)
{
return
Some
(
result
);
}
}
None
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment