Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
progseq-controle_continue_3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
dario.genga
progseq-controle_continue_3
Commits
96ad637c
Commit
96ad637c
authored
3 years ago
by
dario.genga
Browse files
Options
Downloads
Patches
Plain Diff
Add current state of ex
parent
a5cd2dd1
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
ex2/ex2.c
+104
-0
104 additions, 0 deletions
ex2/ex2.c
ex4/ex4.c
+33
-0
33 additions, 0 deletions
ex4/ex4.c
ex5/ex5.c
+14
-0
14 additions, 0 deletions
ex5/ex5.c
with
151 additions
and
0 deletions
ex2/ex2.c
+
104
−
0
View file @
96ad637c
...
...
@@ -8,6 +8,110 @@
#include
<string.h>
#include
<stdbool.h>
typedef
struct
hm_t
{
struct
entry_t
**
entries
;
int
length
;
}
hm
;
typedef
struct
entry_t
{
char
*
key
;
double
value
;
struct
entry_t
*
next
;
}
entry
;
int
hash
(
char
*
key
,
int
length
)
{
int
index
=
0
;
for
(
int
i
=
0
;
i
<
4
;
++
i
)
{
index
=
(
43
*
index
+
key
[
i
])
%
length
;
}
return
index
;
}
entry
*
entry_create_empty
()
{
entry
*
e
=
malloc
(
sizeof
(
entry
));
e
->
key
=
NULL
;
e
->
value
=
-
1
;
e
->
next
=
NULL
;
return
e
;
}
hm
*
hm_create
(
unsigned
int
length
)
{
hm
*
hashmap
=
malloc
(
sizeof
(
hm
));
hashmap
->
length
=
length
;
hashmap
->
entries
=
malloc
(
sizeof
(
entry
)
*
length
);
for
(
size_t
i
=
0
;
i
<
length
;
i
++
)
{
hashmap
->
entries
[
i
]
=
entry_create_empty
();
}
return
hashmap
;
}
void
hm_destroy
(
hm
**
hm
)
{
for
(
int
i
=
0
;
i
<
(
*
hm
)
->
length
;
i
++
)
{
entry
*
e
=
(
*
hm
)
->
entries
[
i
];
while
(
e
!=
NULL
)
{
entry
*
to_free
=
e
;
e
=
e
->
next
;
free
(
to_free
);
}
}
free
((
*
hm
)
->
entries
);
free
((
*
hm
));
(
*
hm
)
=
NULL
;
}
entry
*
get_entry_by_key
(
entry
*
e
,
char
*
key
)
{
if
(
e
->
key
==
key
)
{
return
e
;
}
else
if
(
e
->
next
!=
NULL
)
{
return
get_entry_by_key
(
e
->
next
,
key
);
}
else
{
return
e
;
}
}
hm
*
hm_set
(
hm
*
hm
,
const
char
*
const
key
,
double
value
)
{
// Hash the key and get the corresponding entry
int
key_index
=
hash
((
char
*
)
key
,
hm
->
length
);
entry
*
e
=
get_entry_by_key
(
hm
->
entries
[
key_index
],
(
char
*
)
key
);
// Set the key and create the next entry if the key is not existing
if
(
e
->
key
!=
key
)
{
e
->
key
=
(
char
*
)
key
;
if
(
e
->
next
==
NULL
)
{
e
->
next
=
entry_create_empty
();
}
}
// Set the entry value and return the hashmap
e
->
value
=
value
;
return
hm
;
}
int
main
()
{
int
length
=
10
;
hm
*
hashmap
=
hm_create
(
length
);
hm_set
(
hashmap
,
"ajku"
,
1
.
1
);
hm_set
(
hashmap
,
"ajkv"
,
2
.
2
);
hm_set
(
hashmap
,
"ajkw"
,
3
.
1
);
hm_set
(
hashmap
,
"ajkx"
,
4
.
2
);
hm_set
(
hashmap
,
"ajky"
,
5
.
7
);
hm_set
(
hashmap
,
"ajkz"
,
6
.
1
);
hm_set
(
hashmap
,
"ajka"
,
1
.
8
);
hm_set
(
hashmap
,
"ajkb"
,
2
.
7
);
hm_set
(
hashmap
,
"ajkc"
,
3
.
6
);
hm_set
(
hashmap
,
"bjkd"
,
1
.
9
);
// print
hm_set
(
hashmap
,
"ajkt"
,
0
.
1
);
hm_set
(
hashmap
,
"ajku"
,
9
.
1
);
hm_set
(
hashmap
,
"ajkx"
,
2
.
9
);
// print
hm_destroy
(
&
hashmap
);
return
EXIT_SUCCESS
;
}
This diff is collapsed.
Click to expand it.
ex4/ex4.c
+
33
−
0
View file @
96ad637c
...
...
@@ -7,6 +7,7 @@
#include
<stdlib.h>
#include
<string.h>
#include
<stdbool.h>
#include
<math.h>
#define QUADTREE_SIZE 16
...
...
@@ -74,6 +75,25 @@ node *create_tree_from_matrix(int nb_row, int nb_col, int matrix[nb_row][nb_col]
return
qt
;
}
node
*
copy
(
node
*
original
)
{
node
*
c
=
original
;
return
c
;
}
void
destroy
(
node
*
tree
)
{
if
(
tree
==
NULL
)
{
return
;
}
if
(
is_leaf
(
tree
))
{
free
(
tree
);
return
;
}
for
(
int
i
=
0
;
i
<
4
;
i
++
)
{
destroy
(
tree
->
child
[
i
]);
}
}
int
main
()
{
int
row
=
QUADTREE_SIZE
;
int
col
=
QUADTREE_SIZE
;
...
...
@@ -96,5 +116,18 @@ int main() {
{
0
,
3
,
3
,
3
,
3
,
0
,
0
,
7
,
7
,
7
,
7
,
0
,
0
,
11
,
11
,
11
}
};
node
*
qTree
=
create_tree_from_matrix
(
row
,
col
,
matrix
,
4
);
node
*
cpy
=
copy
(
qTree
);
for
(
int
r
=
0
;
r
<
row
;
r
++
)
{
for
(
int
c
=
0
;
c
<
col
;
c
++
)
{
printf
(
"%d "
,
matrix
[
r
][
c
]);
}
printf
(
"
\n
"
);
}
destroy
(
cpy
);
destroy
(
qTree
);
return
EXIT_SUCCESS
;
}
This diff is collapsed.
Click to expand it.
ex5/ex5.c
+
14
−
0
View file @
96ad637c
...
...
@@ -90,6 +90,20 @@ void transform(node *qt, int size, int indices[size]) {
}
}
void
destroy
(
node
*
tree
)
{
if
(
tree
==
NULL
)
{
return
;
}
if
(
is_leaf
(
tree
))
{
free
(
tree
);
return
;
}
for
(
int
i
=
0
;
i
<
4
;
i
++
)
{
destroy
(
tree
->
child
[
i
]);
}
}
int
main
()
{
int
row
=
QUADTREE_SIZE
;
int
col
=
QUADTREE_SIZE
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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