gdsl
1.8
|
00001 /* 00002 * This file is part of the Generic Data Structures Library (GDSL). 00003 * Copyright (C) 1998-2018 Nicolas Darnis <ndarnis@free.fr>. 00004 * 00005 * GDSL is free software: you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation, either version 3 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * GDSL is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with GDSL. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 /* 00020 * GDSL - Generic Data Structures Library 00021 * $RCSfile: _gdsl_bintree.h,v $ 00022 * $Revision: 1.30 $ 00023 * $Date: 2015/02/17 12:22:55 $ 00024 */ 00025 00026 00027 #ifndef __GDSL_BINTREE_H_ 00028 #define __GDSL_BINTREE_H_ 00029 00030 00031 #include <stdio.h> 00032 00033 00034 #include "gdsl_types.h" 00035 #include "gdsl_macros.h" 00036 00037 00038 #if __cplusplus 00039 extern "C" 00040 { 00041 #endif /* __cplusplus */ 00042 00055 typedef struct _gdsl_bintree* _gdsl_bintree_t; 00056 00064 typedef int (* _gdsl_bintree_map_func_t) (const _gdsl_bintree_t TREE, 00065 void* USER_DATA 00066 ); 00067 00074 typedef void (* _gdsl_bintree_write_func_t) (const _gdsl_bintree_t TREE, 00075 FILE* OUTPUT_FILE, 00076 void* USER_DATA 00077 ); 00078 00079 /******************************************************************************/ 00080 /* Management functions of low-level binary trees */ 00081 /******************************************************************************/ 00082 00098 extern _gdsl_bintree_t 00099 _gdsl_bintree_alloc (const gdsl_element_t E, 00100 const _gdsl_bintree_t LEFT, 00101 const _gdsl_bintree_t RIGHT 00102 ); 00103 00117 extern void 00118 _gdsl_bintree_free (_gdsl_bintree_t T, 00119 const gdsl_free_func_t FREE_F 00120 ); 00121 00139 extern _gdsl_bintree_t 00140 _gdsl_bintree_copy (const _gdsl_bintree_t T, 00141 const gdsl_copy_func_t COPY_F 00142 ); 00143 00144 /******************************************************************************/ 00145 /* Consultation functions of low-level binary trees */ 00146 /******************************************************************************/ 00147 00158 extern bool 00159 _gdsl_bintree_is_empty (const _gdsl_bintree_t T 00160 ); 00161 00172 extern bool 00173 _gdsl_bintree_is_leaf (const _gdsl_bintree_t T 00174 ); 00175 00186 extern bool 00187 _gdsl_bintree_is_root (const _gdsl_bintree_t T 00188 ); 00189 00198 extern gdsl_element_t 00199 _gdsl_bintree_get_content (const _gdsl_bintree_t T 00200 ); 00201 00212 extern _gdsl_bintree_t 00213 _gdsl_bintree_get_parent (const _gdsl_bintree_t T 00214 ); 00215 00231 extern _gdsl_bintree_t 00232 _gdsl_bintree_get_left (const _gdsl_bintree_t T 00233 ); 00234 00250 extern _gdsl_bintree_t 00251 _gdsl_bintree_get_right (const _gdsl_bintree_t T 00252 ); 00253 00262 extern _gdsl_bintree_t* 00263 _gdsl_bintree_get_left_ref (const _gdsl_bintree_t T 00264 ); 00265 00274 extern _gdsl_bintree_t* 00275 _gdsl_bintree_get_right_ref (const _gdsl_bintree_t T 00276 ); 00277 00289 extern ulong 00290 _gdsl_bintree_get_height (const _gdsl_bintree_t T 00291 ); 00292 00301 extern ulong 00302 _gdsl_bintree_get_size (const _gdsl_bintree_t T 00303 ); 00304 00305 /******************************************************************************/ 00306 /* Modification functions of low-level binary trees */ 00307 /******************************************************************************/ 00308 00320 extern void 00321 _gdsl_bintree_set_content (_gdsl_bintree_t T, 00322 const gdsl_element_t E 00323 ); 00324 00336 extern void 00337 _gdsl_bintree_set_parent (_gdsl_bintree_t T, 00338 const _gdsl_bintree_t P 00339 ); 00340 00354 extern void 00355 _gdsl_bintree_set_left (_gdsl_bintree_t T, 00356 const _gdsl_bintree_t L 00357 ); 00358 00372 extern void 00373 _gdsl_bintree_set_right (_gdsl_bintree_t T, 00374 const _gdsl_bintree_t R 00375 ); 00376 00377 /******************************************************************************/ 00378 /* Rotation functions of low-level binary trees */ 00379 /******************************************************************************/ 00380 00394 extern _gdsl_bintree_t 00395 _gdsl_bintree_rotate_left (_gdsl_bintree_t* T 00396 ); 00397 00411 extern _gdsl_bintree_t 00412 _gdsl_bintree_rotate_right (_gdsl_bintree_t* T 00413 ); 00414 00428 extern _gdsl_bintree_t 00429 _gdsl_bintree_rotate_left_right (_gdsl_bintree_t* T 00430 ); 00431 00445 extern _gdsl_bintree_t 00446 _gdsl_bintree_rotate_right_left (_gdsl_bintree_t* T 00447 ); 00448 00449 /******************************************************************************/ 00450 /* Parse functions of low-level binary trees */ 00451 /******************************************************************************/ 00452 00471 extern _gdsl_bintree_t 00472 _gdsl_bintree_map_prefix (const _gdsl_bintree_t T, 00473 const _gdsl_bintree_map_func_t MAP_F, 00474 void* USER_DATA 00475 ); 00476 00495 extern _gdsl_bintree_t 00496 _gdsl_bintree_map_infix (const _gdsl_bintree_t T, 00497 const _gdsl_bintree_map_func_t MAP_F, 00498 void* USER_DATA 00499 ); 00500 00519 extern _gdsl_bintree_t 00520 _gdsl_bintree_map_postfix (const _gdsl_bintree_t T, 00521 const _gdsl_bintree_map_func_t MAP_F, 00522 void* USER_DATA 00523 ); 00524 00525 /******************************************************************************/ 00526 /* Input/output functions of low-level binary trees */ 00527 /******************************************************************************/ 00528 00545 extern void 00546 _gdsl_bintree_write (const _gdsl_bintree_t T, 00547 const _gdsl_bintree_write_func_t WRITE_F, 00548 FILE* OUTPUT_FILE, 00549 void* USER_DATA 00550 ); 00551 00569 extern void 00570 _gdsl_bintree_write_xml (const _gdsl_bintree_t T, 00571 const _gdsl_bintree_write_func_t WRITE_F, 00572 FILE* OUTPUT_FILE, 00573 void* USER_DATA 00574 ); 00575 00593 extern void 00594 _gdsl_bintree_dump (const _gdsl_bintree_t T, 00595 const _gdsl_bintree_write_func_t WRITE_F, 00596 FILE* OUTPUT_FILE, 00597 void* USER_DATA 00598 ); 00599 00605 #ifdef __cplusplus 00606 } 00607 #endif /* __cplusplus */ 00608 00609 00610 #endif /* __GDSL_BINTREE_H_ */ 00611 00612