/** rjp Copyright (C) 2018-2019 rexy712 This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef RJP_TREE_H #define RJP_TREE_H #include "rjp.h" #define RJP_TREE_SUCCESS 0 #define RJP_TREE_ERR_NULL_ROOT 1 #define RJP_TREE_ERR_NOT_FOUND 2 typedef struct RJP_object_member{ RJP_value value; RJP_string name; }RJP_object_member; typedef struct RJP_object_iterator RJP_object_iterator; typedef struct RJP_tree_node RJP_tree_node; struct RJP_tree_node{ RJP_tree_node* parent; RJP_tree_node* left; RJP_tree_node* right; RJP_object_member data; unsigned color:1; }; typedef struct RJP_tree_stack{ RJP_tree_node** data; int size; int pos; }RJP_tree_stack; typedef struct RJP_object_iterator{ RJP_tree_stack stack; RJP_tree_node* current; }RJP_object_iterator; RJP_tree_node* irjp_new_node(RJP_object_member* value); RJP_tree_node* irjp_tree_insert_value(RJP_tree_node* root, RJP_object_member* value, int* status); RJP_tree_node* irjp_tree_remove_value(RJP_tree_node* root, const char* key, int* status); RJP_tree_node* irjp_tree_search_value(RJP_tree_node* root, const char* key); RJP_tree_node* irjp_copy_tree(const RJP_tree_node* root); void irjp_free_tree(RJP_tree_node* root); int irjp_init_object_iterator(RJP_object_iterator* it, const RJP_tree_node* root); void irjp_delete_object_iterator(RJP_object_iterator* it); RJP_tree_node* irjp_object_iterator_next(RJP_object_iterator* it); RJP_tree_node* irjp_object_iterator_current(RJP_object_iterator* it); void irjp_dbg_print_tree(RJP_tree_node* root); void irjp_dbg_print_tree_bfs(RJP_tree_node* root); #endif