1
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3
* Authors: Stanislav Slusny <slusnys@gmail.com>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU Lesser General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
3
* Authors: Stanislav Slusny <slusnys@gmail.com>
7
* This library is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU Lesser General Public License as published by
9
* the Free Software Foundation.
11
* This library is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16
* You should have received a copy of the GNU Lesser General Public License
17
* along with this program; if not, see <http://www.gnu.org/licenses/>.
22
* SECTION: e-cal-backend-intervaltree
23
* @include: libedata-cal/libedata-cal.h
24
* @short_description: A utility for calculating intervals and recurrances
26
* Implementation of the interval node as described in Introduction to
27
* Algorithms book by Cormen et al, chapter 14.3.
29
* Basically, the interval tree is the red-black tree, the node key is
30
* the start of the interval.
23
33
#ifdef HAVE_CONFIG_H
599
610
y = ((z->left == nil) || (z->right == nil)) ? z :
600
611
intervaltree_node_next (tree, z);
612
g_return_val_if_fail (y, FALSE);
601
613
x = (y->left == nil) ? y->right : y->left;
614
g_return_val_if_fail (x, FALSE);
602
615
/* y is to be spliced out. x is it's only child */
604
617
x->parent = y->parent;
606
if (root == x->parent)
619
if (root && root == x->parent)
621
else if (y->parent) {
609
622
if (y == y->parent->left)
610
623
y->parent->left = x;
612
625
y->parent->right = x;
616
629
/* y (the succesor of z) is the node to be spliced out */
617
630
g_return_val_if_fail (y != tree->priv->nil, FALSE);
623
636
y->parent = z->parent;
624
637
z->left->parent = z->right->parent = y;
626
if (z == z->parent->left)
629
z->parent->right = y;
640
if (z == z->parent->left)
643
z->parent->right = y;
631
647
fixup_min_max_fields (tree, x->parent);