~ubuntu-branches/ubuntu/utopic/evolution-data-server/utopic-proposed

« back to all changes in this revision

Viewing changes to calendar/libedata-cal/e-cal-backend-intervaltree.c

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2014-06-13 12:02:14 UTC
  • mfrom: (1.1.116) (1.2.35 sid)
  • Revision ID: package-import@ubuntu.com-20140613120214-1zx93d8jxwt093aw
Tags: 3.12.2-1ubuntu1
* Merge with Debian, remaining changes:
  - debian/control: build depend on hardening-wrapper
  - Add build-depends and pass configure flag to enable Ubuntu Online
    Accounts support.
  - Filter out -Bsymbolic-functions from LDFLAGS (for future people
    wondering about this change, see e.g. BGO #594473 and duplicates).
  - Enable Ubuntu Online Accounts and split it and GOA into a separate
    package

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
2
/*
3
 
 *  Authors: Stanislav Slusny <slusnys@gmail.com>
4
 
 *
5
 
 *  Copyright 2008
6
 
 *
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.
11
 
 *
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.
16
 
 *
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.
20
 
 *
 
3
 * Authors: Stanislav Slusny <slusnys@gmail.com>
 
4
 *
 
5
 * Copyright 2008
 
6
 *
 
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.
 
10
 *
 
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
 
14
 * for more details.
 
15
 *
 
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/>.
 
18
 *
 
19
 */
 
20
 
 
21
/**
 
22
 * SECTION: e-cal-backend-intervaltree
 
23
 * @include: libedata-cal/libedata-cal.h
 
24
 * @short_description: A utility for calculating intervals and recurrances
 
25
 *
 
26
 * Implementation of the interval node as described in Introduction to
 
27
 * Algorithms book by Cormen et al, chapter 14.3.
 
28
 *
 
29
 * Basically, the interval tree is the red-black tree, the node key is
 
30
 * the start of the interval.
21
31
 */
22
32
 
23
33
#ifdef HAVE_CONFIG_H
26
36
 
27
37
#include <stdio.h>
28
38
#include <string.h>
29
 
#include <malloc.h>
30
39
 
31
40
#include "e-cal-backend-intervaltree.h"
32
41
 
569
578
/**
570
579
 * e_intervaltree_remove:
571
580
 * @tree: an #EIntervalTree
 
581
 * @uid: the uid of the component to remove
 
582
 * @rid: the recurrance id of the component to remove
572
583
 *
573
584
 * Since: 2.32
574
585
 **/
577
588
                       const gchar *uid,
578
589
                       const gchar *rid)
579
590
{
580
 
        EIntervalNode *y;
581
 
        EIntervalNode *x;
582
 
        EIntervalNode *z;
 
591
        EIntervalNode *y = NULL;
 
592
        EIntervalNode *x = NULL;
 
593
        EIntervalNode *z = NULL;
583
594
        EIntervalNode *nil, *root;
584
595
        gchar *key;
585
596
 
598
609
 
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 */
603
616
 
604
617
        x->parent = y->parent;
605
618
 
606
 
        if (root == x->parent)
 
619
        if (root && root == x->parent)
607
620
                root->left = x;
608
 
        else {
 
621
        else if (y->parent) {
609
622
                if (y == y->parent->left)
610
623
                        y->parent->left = x;
611
624
                else
612
625
                        y->parent->right = x;
613
626
        }
614
627
 
615
 
        if (y != z) {
 
628
        if (z && y != z) {
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);
618
631
 
623
636
                y->parent = z->parent;
624
637
                z->left->parent = z->right->parent = y;
625
638
 
626
 
                if (z == z->parent->left)
627
 
                        z->parent->left = y;
628
 
                else
629
 
                        z->parent->right = y;
 
639
                if (z->parent) {
 
640
                        if (z == z->parent->left)
 
641
                                z->parent->left = y;
 
642
                        else
 
643
                                z->parent->right = y;
 
644
 
 
645
                }
630
646
 
631
647
                fixup_min_max_fields (tree, x->parent);
632
648
 
662
678
 * @start: start of the interval
663
679
 * @end: end of the interval
664
680
 * 
665
 
 * Returns list of nodes that overlaps given interval or %NULL.
 
681
 * Returns: list of nodes that overlaps given interval or %NULL.
666
682
 *
667
683
 * Since: 2.32
668
684
 **/