2006-04-28 18:22:03 -07:00
|
|
|
/*
|
2005-10-13 07:08:18 -07:00
|
|
|
* mootextbtree.h
|
|
|
|
*
|
2006-02-23 06:03:17 -08:00
|
|
|
* Copyright (C) 2004-2006 by Yevgen Muntyan <muntyan@math.tamu.edu>
|
2005-10-13 07:08:18 -07:00
|
|
|
*
|
|
|
|
* 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 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* See COPYING file that comes with this distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __MOO_TEXT_BTREE_H__
|
|
|
|
#define __MOO_TEXT_BTREE_H__
|
|
|
|
|
|
|
|
#ifndef MOOEDIT_COMPILATION
|
|
|
|
#error "This file may not be included"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
|
|
|
|
|
|
|
#define BTREE_NODE_EXP 4
|
|
|
|
#define BTREE_NODE_MAX_CAPACITY (1 << BTREE_NODE_EXP)
|
|
|
|
#define BTREE_NODE_MIN_CAPACITY (BTREE_NODE_MAX_CAPACITY >> 1)
|
2005-12-09 05:57:58 -08:00
|
|
|
#define BTREE_MAX_DEPTH 9 /* 2^(3*(9-1)) == 2^24 > 16,777,216 - more than enough */
|
2005-10-13 07:08:18 -07:00
|
|
|
#define BTREE_MAX_DEPTH_EXP 4 /* 2^4 > 8 */
|
|
|
|
|
|
|
|
typedef struct _BTNode BTNode;
|
|
|
|
typedef struct _BTData BTData;
|
|
|
|
typedef struct _BTIter BTIter;
|
|
|
|
typedef struct _BTree BTree;
|
|
|
|
|
2005-12-09 05:57:58 -08:00
|
|
|
struct _MooLineMark;
|
2005-10-13 07:08:18 -07:00
|
|
|
|
|
|
|
|
|
|
|
struct _BTNode {
|
|
|
|
BTNode *parent;
|
2005-12-09 05:57:58 -08:00
|
|
|
guint n_marks;
|
2005-10-13 07:08:18 -07:00
|
|
|
|
|
|
|
union {
|
|
|
|
BTNode *children[BTREE_NODE_MAX_CAPACITY];
|
|
|
|
BTData *data[BTREE_NODE_MAX_CAPACITY];
|
2006-07-08 07:59:35 -07:00
|
|
|
} u;
|
2005-10-13 07:08:18 -07:00
|
|
|
|
|
|
|
guint n_children : BTREE_NODE_EXP + 1;
|
|
|
|
guint is_bottom : 1;
|
|
|
|
guint count : (30 - BTREE_NODE_EXP);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _BTData {
|
|
|
|
BTNode *parent;
|
2005-12-09 05:57:58 -08:00
|
|
|
guint n_marks;
|
|
|
|
|
|
|
|
struct _MooLineMark **marks;
|
2005-10-13 07:08:18 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _BTree {
|
|
|
|
BTNode *root;
|
|
|
|
guint depth;
|
|
|
|
guint stamp;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-04-28 18:22:03 -07:00
|
|
|
BTree *_moo_text_btree_new (void);
|
|
|
|
void _moo_text_btree_free (BTree *tree);
|
2005-10-13 07:08:18 -07:00
|
|
|
|
2006-04-28 18:22:03 -07:00
|
|
|
guint _moo_text_btree_size (BTree *tree);
|
2005-10-13 07:08:18 -07:00
|
|
|
|
2006-04-28 18:22:03 -07:00
|
|
|
BTData *_moo_text_btree_get_data (BTree *tree,
|
2005-10-13 07:08:18 -07:00
|
|
|
guint index_);
|
|
|
|
|
2006-04-28 18:22:03 -07:00
|
|
|
BTData *_moo_text_btree_insert (BTree *tree,
|
2006-06-21 02:50:36 -07:00
|
|
|
guint index_);
|
2006-04-28 18:22:03 -07:00
|
|
|
void _moo_text_btree_delete (BTree *tree,
|
2005-12-10 20:26:39 -08:00
|
|
|
guint index_,
|
|
|
|
GSList **removed_marks);
|
2005-10-13 07:08:18 -07:00
|
|
|
|
2006-04-28 18:22:03 -07:00
|
|
|
void _moo_text_btree_insert_range (BTree *tree,
|
2005-10-13 07:08:18 -07:00
|
|
|
int first,
|
2006-06-21 02:50:36 -07:00
|
|
|
int num);
|
2006-04-28 18:22:03 -07:00
|
|
|
void _moo_text_btree_delete_range (BTree *tree,
|
2005-10-13 07:08:18 -07:00
|
|
|
int first,
|
2005-12-10 20:26:39 -08:00
|
|
|
int num,
|
|
|
|
GSList **removed_marks);
|
2005-10-13 07:08:18 -07:00
|
|
|
|
2006-04-28 18:22:03 -07:00
|
|
|
void _moo_text_btree_update_n_marks (BTree *tree,
|
2005-12-10 20:23:32 -08:00
|
|
|
BTData *data,
|
|
|
|
int add);
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
|
|
|
|
G_END_DECLS
|
|
|
|
|
|
|
|
#endif /* __MOO_TEXT_BTREE_H__ */
|