75 lines
2.0 KiB
C
75 lines
2.0 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;
|
|
};
|
|
|
|
/*
|
|
* gl_create_node
|
|
*
|
|
* DESCRIPTION: Create a dependency tree node.
|
|
* PARAMETERS: char *data
|
|
* RETURNS: struct node* on success, NULL on failure
|
|
*/
|
|
struct node *gl_create_node(char *data);
|
|
|
|
/*
|
|
* gl_free_node
|
|
*
|
|
* DESCRIPTION: Recursively free a node and all its children.
|
|
* PARAMETERS: struct node *root
|
|
* RETURNS: void
|
|
*/
|
|
void gl_free_node(struct node *root);
|
|
|
|
/*
|
|
* gl_add_child
|
|
*
|
|
* DESCRIPTION: Add a child node to a parent node.
|
|
* PARAMETERS: struct node *parent, struct node *child
|
|
* RETURNS: 0 on success, 1 on NULL pointer, 2 on invalid numChildren, 3 on max children exceeded
|
|
*/
|
|
int gl_add_child(struct node *parent, struct node *child);
|
|
|
|
/*
|
|
* gl_print_tree
|
|
*
|
|
* DESCRIPTION: Print a dependency tree.
|
|
* PARAMETERS: struct node *root, int level
|
|
* RETURNS: 0 on success, 1 on invalid level, 2 on max recursion depth exceeded, 3 on invalid numChildren, 4 on child print error
|
|
*/
|
|
int gl_print_tree(struct node *root, int level);
|
|
|
|
#endif
|