Hashtree can be used to build any hashtree. This could be a SHA1 tree or a tigertree for example.
To create a new hash tree, use the function hash_tree_new, save the returned pointer as the parent. Add new leaf nodes to the hash tree using hash_tree_append_leaf_node, pass the parent as an argument, save the returned pointer as parent again. When you are done adding leaf nodes, call hash_tree_finish. After this you can read parent->hash to read the calculated hash. If you are done with this tree, free the tree with hash_tree_destroy. Look at the function header description for a more detailed information about the arguments and the returned values.
#include "common.h"
#include "hashtree.h"
#include "if/core/nodes.h"
#include "lib/walloc.h"
#include "lib/override.h"
Functions | |
RCSID ("$Id:hashtree.c, v 1.9 2005/06/25 01:37:39 daichik Exp $") | |
node_t * | node_new () |
Create a new node. | |
void | node_destroy (node_t *node) |
Destory a node. | |
node_t * | find_free_leaf_node (node_t *node) |
Find a free leaf node. | |
node_t * | find_free_node (node_t *node) |
Find a free node. | |
void | hashtree_create_tree (node_t *start_node) |
Build a new hashtree with only left nodes. | |
void | hashtree_increase_depth (hashtree *tree) |
Increases the depth of the hashtree. | |
void | build_hash (hashtree *tree, node_t *node) |
Calculate hash. | |
gboolean | node_is_leaf_node (node_t *node) |
Check wether node is a leaf node. | |
gboolean | node_is_free_leaf_node (node_t *node) |
Check wether node is a free leaf node. | |
gboolean | node_is_free_node (node_t *node) |
Check wether node is a free node. | |
hashtree * | hashtree_new (gpointer(*hash_func)(gpointer, gpointer)) |
Create a new hashtree. | |
void | hashtree_append_leaf_node (hashtree *tree, gpointer hash) |
Append leaf node to hash tree. | |
void | hashtree_finish (hashtree *tree) |
Finish the hashtree. | |
void | hashtree_destroy (hashtree *tree) |
Destroy the hashtree. | |
Variables | |
gint | blocks |
|
Calculate hash. Calculates the hash for the current node and its child node by using this function recursively. If a node has only a node to the left and no nodes to the right it will promote the to the left up one level without recalculating.
|
|
Find a free leaf node. Searches the tree to find a free leaf node.
|
|
Find a free node. Searches the tree to find a free node.
|
|
Append leaf node to hash tree. Adds a new leaf node to the hashtree, if necesarry it will expand the hashtree to include the new leaf node.
|
|
Build a new hashtree with only left nodes. Builds a new hashtree until node->depth == 0. Only the nodes at the left are build, all right nodes are NULL.
|
|
Destroy the hashtree. Destroys the hash tree and all its included node. This will free all memory used by the hashtree, including all hashes assigned to a node which was added with hashtree_append_leaf_node which will be freed using g_free
|
|
Finish the hashtree. Calculates all internal hashes in the hashtree. Call this function when you are ready with adding leaf nodes to the hashtree.
|
|
Increases the depth of the hashtree. Increases the hash tree by adding a new parrent to the tree.
|
|
Create a new hashtree. Initializes a new hashtree. Save the returned hashtree pointer which you need to pass to the other hashtree functions.
|
|
Destory a node. Destorys a node and all its child nodes using recursing, all memory assinged to this node will be freed, including an assigned hash.
|
|
Check wether node is a free leaf node.
|
|
Check wether node is a free node.
|
|
Check wether node is a leaf node.
|
|
Create a new node. Creates a new node by allocating memory for it.
|
|
|
|
|