universe@816: /* universe@816: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. universe@816: * universe@816: * Copyright 2024 Mike Becker, Olaf Wintermann All rights reserved. universe@816: * universe@816: * Redistribution and use in source and binary forms, with or without universe@816: * modification, are permitted provided that the following conditions are met: universe@816: * universe@816: * 1. Redistributions of source code must retain the above copyright universe@816: * notice, this list of conditions and the following disclaimer. universe@816: * universe@816: * 2. Redistributions in binary form must reproduce the above copyright universe@816: * notice, this list of conditions and the following disclaimer in the universe@816: * documentation and/or other materials provided with the distribution. universe@816: * universe@816: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" universe@816: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE universe@816: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE universe@816: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE universe@816: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR universe@816: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF universe@816: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS universe@816: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN universe@816: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) universe@816: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE universe@816: * POSSIBILITY OF SUCH DAMAGE. universe@816: */ universe@816: /** universe@816: * \file tree.h universe@816: * \brief Interface for tree implementations. universe@816: * \author Mike Becker universe@816: * \author Olaf Wintermann universe@816: * \copyright 2-Clause BSD License universe@816: */ universe@816: universe@816: #ifndef UCX_TREE_H universe@816: #define UCX_TREE_H universe@816: universe@816: #include "common.h" universe@816: universe@816: #ifdef __cplusplus universe@816: extern "C" { universe@816: #endif universe@816: universe@816: universe@822: /** universe@822: * Links a node to a (new) parent. universe@822: * universe@822: * If the node has already a parent, it is unlinked, first. universe@822: * universe@822: * @param parent the parent node universe@822: * @param node the node that shall be linked universe@822: * @param loc_parent offset in the node struct for the parent pointer universe@822: * @param loc_children offset in the node struct for the children linked list universe@822: * @param loc_prev offset in the node struct for the prev pointer universe@822: * @param loc_next offset in the node struct for the next pointer universe@822: * @see cx_tree_unlink() universe@822: */ universe@816: __attribute__((__nonnull__)) universe@816: void cx_tree_link( universe@816: void * restrict parent, universe@816: void * restrict node, universe@816: ptrdiff_t loc_parent, universe@816: ptrdiff_t loc_children, universe@816: ptrdiff_t loc_prev, universe@816: ptrdiff_t loc_next universe@816: ); universe@816: universe@822: /** universe@822: * Unlinks a node from its parent. universe@822: * universe@822: * If the node has no parent, this function does nothing. universe@822: * universe@822: * @param node the node that shall be unlinked from its parent universe@822: * @param loc_parent offset in the node struct for the parent pointer universe@822: * @param loc_children offset in the node struct for the children linked list universe@822: * @param loc_prev offset in the node struct for the prev pointer universe@822: * @param loc_next offset in the node struct for the next pointer universe@822: * @see cx_tree_link() universe@822: */ universe@816: __attribute__((__nonnull__)) universe@816: void cx_tree_unlink( universe@816: void *node, universe@816: ptrdiff_t loc_parent, universe@816: ptrdiff_t loc_children, universe@816: ptrdiff_t loc_prev, universe@816: ptrdiff_t loc_next universe@816: ); universe@816: universe@823: /** universe@823: * Function pointer for a search function. universe@823: * universe@823: * A function of this kind shall check if the specified \p node universe@823: * contains the given \p data or if one of the children might contain universe@823: * the data. universe@823: * universe@823: * For example if a tree stores file path information, a node that is universe@823: * describing a parent directory of a filename that is searched, shall universe@823: * return 1 to indicate that a child node might contain the searched item. universe@823: * On the other hand, if the node denotes a path that is not a prefix of universe@823: * the searched filename, the function would return -1 to indicate that universe@823: * the search does not need to be continued in that branch. universe@823: * universe@823: * @param node the node that is currently investigated universe@823: * @param data the data that is searched for universe@823: * universe@823: * @return 0 if the node contains the data, universe@823: * 1 if one of the children might contain the data, universe@823: * -1 if neither the node, nor the children contains the data universe@823: */ universe@823: int (*cx_tree_search_func)(void const *node, void const* data); universe@823: universe@816: #ifdef __cplusplus universe@816: } // extern "C" universe@816: #endif universe@816: universe@816: #endif //UCX_TREE_H