medit/moo/mooedit/mootextbtree.h

98 lines
2.7 KiB
C
Raw Normal View History

/*
* mootextbtree.h
*
* Copyright (C) 2004-2006 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
* 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)
#define BTREE_MAX_DEPTH 9 /* 2^(3*(9-1)) == 2^24 > 16,777,216 - more than enough */
#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;
struct _MooLineMark;
struct _BTNode {
BTNode *parent;
guint n_marks;
union {
BTNode *children[BTREE_NODE_MAX_CAPACITY];
BTData *data[BTREE_NODE_MAX_CAPACITY];
2006-07-08 07:59:35 -07:00
} u;
guint n_children : BTREE_NODE_EXP + 1;
guint is_bottom : 1;
guint count : (30 - BTREE_NODE_EXP);
};
struct _BTData {
BTNode *parent;
guint n_marks;
struct _MooLineMark **marks;
};
struct _BTree {
BTNode *root;
guint depth;
guint stamp;
};
BTree *_moo_text_btree_new (void);
void _moo_text_btree_free (BTree *tree);
guint _moo_text_btree_size (BTree *tree);
BTData *_moo_text_btree_get_data (BTree *tree,
guint index_);
BTData *_moo_text_btree_insert (BTree *tree,
guint index_);
void _moo_text_btree_delete (BTree *tree,
guint index_,
GSList **removed_marks);
void _moo_text_btree_insert_range (BTree *tree,
int first,
int num);
void _moo_text_btree_delete_range (BTree *tree,
int first,
int num,
GSList **removed_marks);
void _moo_text_btree_update_n_marks (BTree *tree,
BTData *data,
int add);
G_END_DECLS
#endif /* __MOO_TEXT_BTREE_H__ */