Skip to content
Snippets Groups Projects
Commit 21435537 authored by jonas.stirnema's avatar jonas.stirnema
Browse files

Added compression functions

parent b5c8b2a1
No related branches found
No related tags found
No related merge requests found
```c
tree tree_compress(tree)
{
if !is_leaf(tree)
{
tree->left = tree_compress(tree->left);
tree->right = tree_compress(tree->right);
if (tree->left == tree->right)
{
tree = tree->left;
}
}
}
```
\ No newline at end of file
......@@ -5,6 +5,7 @@ typedef int value_t;
typedef struct node_
{
value_t value;
value_t sqared_avg;
node_ *child[4]
} node_t;
......@@ -142,3 +143,51 @@ node_t *tree_vert_sym(node_t *tree)
tree = fill_tree(m);
return tree;
}
/**
* @brief Lossless tree compression
*
* @param tree
* @return node_t*
*/
void tree_lossless_compress(node_t *tree)
{
if (!is_leaf(tree))
{
for (int i = 0; i < 4; i++)
{
tree->child[i] = tree_lossless_compress(tree->child[i]);
}
if(last_branch(tree)
{
if (tree->child[0] == tree->child[1] == tree->child[2] == tree->child[3])
{
tree->data = tree->child[0]->data;
free(tree->child);
}
}
}
}
#define DIFF 4
standard_deviation = Racine de la moyenne des elements au carré
void
tree__lossy_compression(node_t * tree)
{
if (!is_leaf(tree))
{
for (int i = 0; i < 4; i++)
{
tree->child[i] = tree_lossy_compress(tree->child[i]);
}
if (last_branch(tree))
{
if (sqrt(tree->sqared_avg - tree->value * tree->value) < DIFF)
{
free(tree->child);
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment