Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals

rt_move.c

Go to the documentation of this file.
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_move.c,v 1.2 2006/07/13 19:16:24 klmitch Exp $
00020 */
00029 #include "dbprim.h"
00030 #include "dbprim_int.h"
00031 
00032 RCSTAG("@(#)$Id: rt_move.c,v 1.2 2006/07/13 19:16:24 klmitch Exp $");
00033 
00034 unsigned long
00035 rt_move(rb_tree_t *tree, rb_node_t *node, db_key_t *key)
00036 {
00037   unsigned long retval;
00038 
00039   initialize_dbpr_error_table(); /* initialize error table */
00040 
00041   if (!rt_verify(tree) || !rn_verify(node) || !key) /* verify arguments */
00042     return DB_ERR_BADARGS;
00043 
00044   if (!node->rn_tree) /* it's not in a tree */
00045     return DB_ERR_UNUSED;
00046   if (node->rn_tree != tree) /* it's in the wrong tree */
00047     return DB_ERR_WRONGTABLE;
00048 
00049   if (tree->rt_flags & RBT_FLAG_FREEZE) /* don't mess with frozen trees */
00050     return DB_ERR_FROZEN;
00051 
00052   if (_rb_locate(tree, 0, key)) /* don't permit duplicates */
00053     return DB_ERR_DUPLICATE;
00054 
00055   /* OK, remove node from the tree... */
00056   if ((retval = rt_remove(tree, node)))
00057     return retval;
00058 
00059   /* Now re-add it to the tree... */
00060   return rt_add(tree, node, key) ? DB_ERR_READDFAILED : 0;
00061 }

Generated on Sat Jul 15 14:10:33 2006 for DatabasePrimitivesLibrary by  doxygen 1.4.4