Files
federated-calendar/src/views/gcal-range-tree.h
T
Georges Basile Stavracas Neto 29ad51b19a project: introduce GcalRangeTree
In order to correctly implement the week grid, we must
have a fast and optimized data structure to handle date
intervals.

This commit introduces, then, GcalRangeTree. The range tree
is an augmented AVL tree designed to handle intervals (i.e.
ranges) rather than single-dimensional keys.

It is a very good struct since common operations like insert
and removal are O(log n). It also is optimized for the ranges
we work on, so the nodes only take up the absolutely minimum
space required.
2016-12-07 21:27:25 -02:00

73 lines
3.5 KiB
C

/* gcal-range-tree.h
*
* Copyright (C) 2016 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GCAL_RANGE_TREE_H
#define GCAL_RANGE_TREE_H
#include <glib-object.h>
G_BEGIN_DECLS
#define GCAL_TYPE_RANGE_TREE (gcal_range_tree_get_type())
typedef struct _GcalRangeTree GcalRangeTree;
typedef gboolean (*GcalRangeTraverseFunc) (guint16 start,
guint16 end,
gpointer data,
gpointer user_data);
GType gcal_range_tree_get_type (void) G_GNUC_CONST;
GcalRangeTree* gcal_range_tree_new (void);
GcalRangeTree* gcal_range_tree_copy (GcalRangeTree *self);
GcalRangeTree* gcal_range_tree_ref (GcalRangeTree *self);
void gcal_range_tree_unref (GcalRangeTree *self);
void gcal_range_tree_add_range (GcalRangeTree *self,
guint16 start,
guint16 end,
gpointer data);
void gcal_range_tree_remove_range (GcalRangeTree *self,
guint16 start,
guint16 end,
gpointer data);
void gcal_range_tree_traverse (GcalRangeTree *self,
GTraverseType type,
GcalRangeTraverseFunc func,
gpointer user_data);
GPtrArray* gcal_range_tree_get_data_at_range (GcalRangeTree *self,
guint16 start,
guint16 end);
guint64 gcal_range_tree_count_entries_at_range (GcalRangeTree *self,
guint16 start,
guint16 end);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GcalRangeTree, gcal_range_tree_unref)
G_END_DECLS
#endif /* GCAL_RANGE_TREE_H */