libglacier/include/data.h

105 lines
2.7 KiB
C

/*
* data.h - Data structures for libglacier
*
* This file is part of Glacier.
*
* Glacier is free software: you can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* Glacier is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with Glacier. If
* not, see <https://www.gnu.org/licenses/>.
*/
#ifndef GLACIERDATA_H_
#define GLACIERDATA_H_
#include <stdbool.h>
/* Maximum number of children a node can have */
#define MAX_CHILDREN 64
/* Maximum recursion depth for tree operations */
#define MAX_RECURSION_DEPTH 100
/* Node structure definition */
struct node {
char *data;
struct node *children[MAX_CHILDREN];
int numChildren;
struct node *left;
struct node *right;
};
/*
* create_node
*
* DESCRIPTION: Create_node creates a node for a dependency tree data structure.
* PARAMETERS:
* char *data -> The name of the node to create
* RETURN VALUES:
* A pointer to the created node on success, NULL on failure
* CAVEATS:
* Caller must free the node using free_node when done
* EXAMPLE:
* struct node *package = create_node("Package");
*/
struct node *create_node(char *data);
/*
* free_node
*
* DESCRIPTION: Free_node recursively frees all memory allocated for a node and its children.
* PARAMETERS:
* struct node *root -> The root node to free
* RETURN VALUES:
* None.
* CAVEATS:
* Will free all child nodes recursively.
* EXAMPLE:
* free_node(package);
*/
void free_node(struct node *root);
/*
* add_child
*
* DESCRIPTION: Add_child adds a child node to a parent node.
* PARAMETERS:
* struct node *parent -> The parent node which the child will be added to
* struct node *child -> The child node which will be added to the parent node
* RETURN VALUES:
* 0 on success, 1-3 for different error conditions
* CAVEATS:
* None.
* EXAMPLE:
* add_child(package, dep1);
*/
int add_child(struct node *parent, struct node *child);
/*
* print_tree
*
* DESCRIPTION: Print_tree prints a dependency tree specified at its root node.
* PARAMETERS:
* struct node *root -> The tree to print
* int level -> The number of levels to descend
* RETURN VALUES:
* 0 on success, non-zero on error
* CAVEATS:
* None.
* EXAMPLE:
* print_tree(package, 0);
*/
int print_tree(struct node *root, int level);
#endif