From c6fc4e27a953c5213cff8400ec8e40f6f051e914 Mon Sep 17 00:00:00 2001 From: Not Zed Date: Mon, 25 Mar 2002 12:11:44 +0000 Subject: When we add a new name, up all of the cache limits, because we're probably 2002-03-25 Not Zed * camel-text-index.c (text_index_add_name): When we add a new name, up all of the cache limits, because we're probably going to be adding more. (text_index_sync): Drop the cache limits back down again, we dont need them when looking words up. ** MERGE camel_index branch. * camel-text-index.[ch]: Added files i forgot to add (eep nearly lost all this work!) * camel-block-file.c (sync_nolock): Fix an infinite loop in syncing. svn path=/trunk/; revision=16242 --- camel/camel-index.h | 159 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 camel/camel-index.h (limited to 'camel/camel-index.h') diff --git a/camel/camel-index.h b/camel/camel-index.h new file mode 100644 index 0000000000..eba57a43b0 --- /dev/null +++ b/camel/camel-index.h @@ -0,0 +1,159 @@ +/* + * Copyright (C) 2001 Ximian Inc. + * + * Authors: Michael Zucchi + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * 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, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef _CAMEL_INDEX_H +#define _CAMEL_INDEX_H + +#include +#include + +#define CAMEL_INDEX(obj) CAMEL_CHECK_CAST (obj, camel_index_get_type (), CamelIndex) +#define CAMEL_INDEX_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_index_get_type (), CamelIndexClass) +#define CAMEL_IS_INDEX(obj) CAMEL_CHECK_TYPE (obj, camel_index_get_type ()) + +typedef struct _CamelIndex CamelIndex; +typedef struct _CamelIndexClass CamelIndexClass; + +#define CAMEL_INDEX_NAME(obj) CAMEL_CHECK_CAST (obj, camel_index_name_get_type (), CamelIndexName) +#define CAMEL_INDEX_NAME_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_index_name_get_type (), CamelIndexNameClass) +#define CAMEL_IS_INDEX_NAME(obj) CAMEL_CHECK_TYPE (obj, camel_index_name_get_type ()) + +typedef struct _CamelIndexName CamelIndexName; +typedef struct _CamelIndexNameClass CamelIndexNameClass; + +#define CAMEL_INDEX_CURSOR(obj) CAMEL_CHECK_CAST (obj, camel_index_cursor_get_type (), CamelIndexCursor) +#define CAMEL_INDEX_CURSOR_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_index_cursor_get_type (), CamelIndexCursorClass) +#define CAMEL_IS_INDEX_CURSOR(obj) CAMEL_CHECK_TYPE (obj, camel_index_cursor_get_type ()) + +typedef struct _CamelIndexCursor CamelIndexCursor; +typedef struct _CamelIndexCursorClass CamelIndexCursorClass; + +typedef char * (*CamelIndexNorm)(CamelIndex *idx, const char *word, void *data); + +/* ********************************************************************** */ + +struct _CamelIndexCursor { + CamelObject parent; + + struct _CamelIndexCursorPrivate *priv; + + CamelIndex *index; +}; + +struct _CamelIndexCursorClass { + CamelObjectClass parent; + + const char * (*next) (CamelIndexCursor *idc); + void (*reset) (CamelIndexCursor *idc); +}; + +guint camel_index_cursor_get_type(void); + +CamelIndexCursor *camel_index_cursor_new(CamelIndex *idx, const char *name); + +const char *camel_index_cursor_next(CamelIndexCursor *idc); +void camel_index_cursor_reset(CamelIndexCursor *idc); + +/* ********************************************************************** */ + +struct _CamelIndexName { + CamelObject parent; + + struct _CamelIndexNamePrivate *priv; + + CamelIndex *index; + + char *name; /* name being indexed */ + + GByteArray *buffer; /* used for normalisation */ + GHashTable *words; /* unique list of words */ +}; + +struct _CamelIndexNameClass { + CamelObjectClass parent; + + int (*sync)(CamelIndexName *name); + void (*add_word)(CamelIndexName *name, const char *word); + size_t (*add_buffer)(CamelIndexName *name, const char *buffer, size_t len); +}; + +guint camel_index_name_get_type (void); + +CamelIndexName *camel_index_name_new(CamelIndex *idx, const char *name); + +void camel_index_name_add_word(CamelIndexName *name, const char *word); +size_t camel_index_name_add_buffer(CamelIndexName *name, const char *buffer, size_t len); + +/* ********************************************************************** */ + +struct _CamelIndex { + CamelObject parent; + + struct _CamelIndexPrivate *priv; + + char *path; + guint32 version; + guint32 flags; + + CamelIndexNorm normalise; + void *normalise_data; +}; + +struct _CamelIndexClass { + CamelObjectClass parent_class; + + int (*sync)(CamelIndex *idx); + int (*compress)(CamelIndex *idx); + + int (*rename)(CamelIndex *idx, const char *path); + + int (*has_name)(CamelIndex *idx, const char *name); + CamelIndexName * (*add_name)(CamelIndex *idx, const char *name); + int (*write_name)(CamelIndex *idx, CamelIndexName *idn); + CamelIndexCursor * (*find_name)(CamelIndex *idx, const char *name); + void (*delete_name)(CamelIndex *idx, const char *name); + CamelIndexCursor * (*find)(CamelIndex *idx, const char *word); + + CamelIndexCursor * (*words)(CamelIndex *idx); + CamelIndexCursor * (*names)(CamelIndex *idx); +}; + +guint camel_index_get_type (void); + +CamelIndex *camel_index_new(const char *path, int flags); +void camel_index_construct(CamelIndex *, const char *path, int flags); +int camel_index_rename(CamelIndex *, const char *path); + +void camel_index_set_normalise(CamelIndex *idx, CamelIndexNorm func, void *data); + +int camel_index_sync(CamelIndex *idx); +int camel_index_compress(CamelIndex *idx); + +int camel_index_has_name(CamelIndex *idx, const char *name); +CamelIndexName *camel_index_add_name(CamelIndex *idx, const char *name); +int camel_index_write_name(CamelIndex *idx, CamelIndexName *idn); +CamelIndexCursor *camel_index_find_name(CamelIndex *idx, const char *name); +void camel_index_delete_name(CamelIndex *idx, const char *name); +CamelIndexCursor *camel_index_find(CamelIndex *idx, const char *word); + +CamelIndexCursor *camel_index_words(CamelIndex *idx); +CamelIndexCursor *camel_index_names(CamelIndex *idx); + +#endif /* ! _CAMEL_INDEX_H */ -- cgit v1.2.3