1 /* tree.h 2 * =========================================================================== 3 * 4 * PUBLIC DOMAIN NOTICE 5 * National Center for Biotechnology Information 6 * 7 * This software/database is a "United States Government Work" under the 8 * terms of the United States Copyright Act. It was written as part of 9 * the author's official duties as a United States Government employee and 10 * thus cannot be copyrighted. This software/database is freely available 11 * to the public for use. The National Library of Medicine and the U.S. 12 * Government have not placed any restriction on its use or reproduction. 13 * 14 * Although all reasonable efforts have been taken to ensure the accuracy 15 * and reliability of the software and data, the NLM and the U.S. 16 * Government do not and cannot warrant the performance or results that 17 * may be obtained by using this software or data. The NLM and the U.S. 18 * Government disclaim all warranties, express or implied, including 19 * warranties of performance, merchantability or fitness for any particular 20 * purpose. 21 * 22 * Please cite the author in any work or product based on this material. 23 * 24 * =========================================================================== 25 * 26 * File Name: tree.h 27 * 28 * Author: Vladimir Soussov 29 * 30 * File Description: Data types for tree manager 31 * 32 * 33 * $Log: tree.h,v $ 34 * Revision 1.5 1999/05/18 21:13:47 soussov 35 * TREE_SHUTDOWN event added 36 * 37 * Revision 1.4 1998/04/02 23:03:31 vakatov 38 * PC-specific fixes 39 * 40 * Revision 1.3 1998/04/02 22:30:25 soussov 41 * Some prototype added to make Denis happy 42 * 43 * Revision 1.2 1998/03/31 23:12:56 kans 44 * minor changes needed for code warrior 45 * 46 * Revision 1.1 1998/03/31 21:22:26 sirotkin 47 * With Vladimir - moved from distrib/internal/taxonomy/tree 48 * 49 * Revision 6.0 1997/08/25 18:29:49 madden 50 * Revision changed to 6.0 51 * 52 * Revision 1.1 1997/05/30 16:16:18 soussov 53 * Set of files for ncbitree library 54 * 55 * Revision 1.1 1997/05/29 20:44:27 soussov 56 * Initial version of tree library 57 * 58 * 59 */ 60 61 #ifndef TREE_H_DONE 62 #define TREE_H_DONE 63 64 #include <ncbi.h> 65 66 typedef enum { 67 TREE_CURSOR_MOVED = 0, 68 TREE_NODE_UPDATE, 69 TREE_NODE_UPD_DONE, 70 TREE_NODEDATA_UPDATE, 71 TREE_NODEDATA_UPD_DONE, 72 TREE_NODE_DELETE, 73 TREE_NODE_DEL_DONE, 74 TREE_NODE_MOVE, 75 TREE_NODE_MV_DONE, 76 TREE_NODE_MERGE, 77 TREE_NODE_MERGE_DONE, 78 TREE_CHILDREN_MOVE, 79 TREE_CHILDREN_MV_DONE, 80 TREE_NODE_ADDED, 81 TREE_SUBTREE_DELETE, 82 TREE_SUBTREE_DEL_DONE, 83 TREE_SHUTDOWN 84 } TreeEvent; 85 86 typedef struct t_nodeId0 { 87 Uint1 bag_store; 88 Uint1 bag; 89 Uint1 node; 90 Uint1 vers; 91 } _nodeId0; 92 93 typedef union t_nodeIdU { 94 _nodeId0 id4; 95 Uint4 idi; 96 } _NodeId, PNTR _NodeIdPtr; 97 98 99 typedef void* _NodeData; 100 101 102 #define NODE_BAG_SIZE 256 103 #define NOF_BAGS 256 104 105 #define TREE_FREE_ROOM 0x1 106 #define TREE_MERGED_NODE 0x2 107 108 typedef struct t_Node { 109 _NodeId parent; /* parent node id */ 110 _NodeId child; /* child node id */ 111 _NodeId sibling; /* sibling node id */ 112 _NodeData data; /* user data */ 113 VoidPtr sys_data; /* system data (can not be saved) */ 114 Uint2 size; 115 Uint1 vers; 116 Uint1 flags; 117 } _Node, PNTR _NodePtr; 118 119 typedef struct T_NodeBag { 120 Int4 nof_nodes; /* number of live nodes in bag */ 121 struct T_NodeBag** my_bag_store; 122 _Node node[NODE_BAG_SIZE]; 123 } _NodeBag, PNTR _NodeBagPtr; 124 125 typedef _NodeBagPtr PNTR _BagStore; 126 127 typedef struct t_TreeCursor TreeCursor, PNTR TreeCursorPtr; 128 129 typedef void (*TreeCursorCBFunc)(TreeCursorPtr, TreeEvent, _NodeId); 130 131 struct t_TreeCursor { 132 struct t_Tree PNTR tree; 133 struct t_TreeCursor* next_cursor; 134 _NodeId node_id; 135 _NodeId prev_id; 136 _NodePtr node; 137 TreeCursorCBFunc callBack; 138 VoidPtr user_data; 139 _NodeBagPtr cbag; 140 }; 141 142 typedef struct t_Tree Tree, PNTR TreePtr; 143 144 typedef void (*TreeSpyFunc)(TreePtr, Int2, TreeEvent, _NodeId, _NodeId, VoidPtr, Int2); 145 146 typedef void (*TreeSaveFunc)(TreeCursorPtr); 147 148 typedef Boolean (*TreeUpdateFunc)(TreeCursorPtr, Uint4, VoidPtr, Uint2); 149 150 typedef VoidPtr (*TreeGetFunc)(TreeCursorPtr, Uint4, Uint2Ptr); 151 152 153 #define TREE_NOF_SPIES 32 154 155 struct t_Tree { 156 TreeCursorPtr cursor; 157 _NodeId id4NewNode; 158 _NodeId rootNodeId; 159 _BagStore bag_store[NOF_BAGS]; 160 TreeGetFunc get_func; 161 TreeUpdateFunc update_func; 162 TreeSaveFunc save_func; 163 TreeSpyFunc spy[TREE_NOF_SPIES]; 164 VoidPtr spy_data[TREE_NOF_SPIES]; 165 Int4 nof_spies; 166 }; 167 168 169 #endif 170