00001 /* 00002 ** Copyright (C) 2003 by Kevin L. Mitchell <klmitch@mit.edu> 00003 ** 00004 ** This library is free software; you can redistribute it and/or 00005 ** modify it under the terms of the GNU Library General Public 00006 ** License as published by the Free Software Foundation; either 00007 ** version 2 of the License, or (at your option) any later version. 00008 ** 00009 ** This library is distributed in the hope that it will be useful, 00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 ** Library General Public License for more details. 00013 ** 00014 ** You should have received a copy of the GNU Library General Public 00015 ** License along with this library; if not, write to the Free 00016 ** Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 00017 ** MA 02111-1307, USA 00018 ** 00019 ** @(#)$Id: rt_flush.c,v 1.2 2006/07/13 19:16:24 klmitch Exp $ 00020 */ 00028 #include "dbprim.h" 00029 #include "dbprim_int.h" 00030 00031 RCSTAG("@(#)$Id: rt_flush.c,v 1.2 2006/07/13 19:16:24 klmitch Exp $"); 00032 00033 unsigned long 00034 rt_flush(rb_tree_t *tree, rb_iter_t flush_func, void *extra) 00035 { 00036 unsigned long retval = 0; 00037 rb_node_t *node; 00038 00039 initialize_dbpr_error_table(); /* initialize error table */ 00040 00041 if (!rt_verify(tree)) /* verify arguments */ 00042 return DB_ERR_BADARGS; 00043 00044 if (tree->rt_flags & RBT_FLAG_FREEZE) /* don't mess with frozen trees */ 00045 return DB_ERR_FROZEN; 00046 00047 /* OK, walk through the nodes... */ 00048 while (tree->rt_root) { 00049 rt_remove(tree, node = tree->rt_root); /* remove the node... */ 00050 00051 if (flush_func) { 00052 tree->rt_flags |= RBT_FLAG_FREEZE; /* freeze the table... */ 00053 00054 retval = (*flush_func)(tree, node, extra); /* call flush function */ 00055 00056 tree->rt_flags &= ~RBT_FLAG_FREEZE; /* unfreeze table... */ 00057 00058 if (retval) /* if flush function failed, error out */ 00059 return retval; 00060 } 00061 } 00062 00063 tree->rt_count = 0; /* clear the node count */ 00064 tree->rt_root = 0; /* and the root node... */ 00065 00066 return 0; 00067 }