added open-addressed hash table

This commit is contained in:
2010-09-08 04:57:43 +00:00
parent af72767aa5
commit 95e975f514
14 changed files with 719 additions and 60 deletions

View File

@ -1,7 +1,7 @@
pkgincludedir = $(includedir)/qse/cmn
pkginclude_HEADERS = \
mem.h xma.h fma.h chr.h str.h lda.h htb.h rbt.h \
mem.h xma.h fma.h chr.h str.h lda.h oht.h htb.h rbt.h \
rex.h sll.h gdl.h dll.h opt.h tio.h \
fio.h pio.h sio.h time.h misc.h main.h stdio.h

View File

@ -52,8 +52,8 @@ CONFIG_CLEAN_VPATH_FILES =
SOURCES =
DIST_SOURCES =
am__pkginclude_HEADERS_DIST = mem.h xma.h fma.h chr.h str.h lda.h \
htb.h rbt.h rex.h sll.h gdl.h dll.h opt.h tio.h fio.h pio.h \
sio.h time.h misc.h main.h stdio.h Mmgr.hpp StdMmgr.hpp \
oht.h htb.h rbt.h rex.h sll.h gdl.h dll.h opt.h tio.h fio.h \
pio.h sio.h time.h misc.h main.h stdio.h Mmgr.hpp StdMmgr.hpp \
Mmged.hpp
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
@ -221,9 +221,9 @@ target_alias = @target_alias@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
pkginclude_HEADERS = mem.h xma.h fma.h chr.h str.h lda.h htb.h rbt.h \
rex.h sll.h gdl.h dll.h opt.h tio.h fio.h pio.h sio.h time.h \
misc.h main.h stdio.h $(am__append_1)
pkginclude_HEADERS = mem.h xma.h fma.h chr.h str.h lda.h oht.h htb.h \
rbt.h rex.h sll.h gdl.h dll.h opt.h tio.h fio.h pio.h sio.h \
time.h misc.h main.h stdio.h $(am__append_1)
all: all-am
.SUFFIXES:

View File

@ -1,5 +1,5 @@
/*
* $Id: htb.h 354 2010-09-03 12:50:08Z hyunghwan.chung $
* $Id: htb.h 355 2010-09-07 10:57:43Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.
@ -157,7 +157,7 @@ struct qse_htb_t
qse_htb_sizer_t sizer; /**< bucket capacity recalculator */
qse_byte_t scale[2]; /**< length scale */
qse_byte_t factor; /**< load factor */
qse_byte_t factor; /**< load factor in percentage */
qse_byte_t filler0;
qse_size_t size;

194
qse/include/qse/cmn/oht.h Normal file
View File

@ -0,0 +1,194 @@
/*
* $Id$
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.
QSE is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
QSE is distributed in the hope toht it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with QSE. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file
* This file provides the open-addressed hash table for fixed-size data.
*/
#ifndef _QSE_OHT_T_
#define _QSE_OHT_T_
#include <qse/types.h>
#include <qse/macros.h>
#define QSE_OHT_INVALID_INDEX ((qse_size_t)-1)
enum qse_oht_mark_t
{
QSE_OHT_EMPTY = 0,
QSE_OHT_OCCUPIED = 1 /*,
QSE_OHT_DELETED = 2 */
};
typedef enum qse_oht_mark_t qse_oht_mark_t;
enum qse_oht_walk_t
{
QSE_OHT_WALK_STOP = 0,
QSE_OHT_WALK_FORWARD = 1,
};
typedef enum qse_oht_walk_t qse_oht_walk_t;
typedef struct qse_oht_t qse_oht_t;
/**
* The qse_oht_comper_t type defines a key comparator that is called when
* the list needs to compare data. The comparator must return 0 if the data
* are the same and a non-zero integer otherwise.
*/
typedef int (*qse_oht_comper_t) (
qse_oht_t* oht, /**< open-addressed hash table */
const void* data1, /**< data pointer */
const void* data2 /**< data pointer */
);
typedef void (*qse_oht_copier_t) (
qse_oht_t* oht,
void* dst,
const void* src
);
typedef qse_size_t (*qse_oht_hasher_t) (
qse_oht_t* oht,
const void* data
);
struct qse_oht_t
{
QSE_DEFINE_COMMON_FIELDS(oht)
struct
{
qse_size_t hard;
qse_size_t soft;
} capa;
qse_size_t size;
qse_size_t scale;
qse_oht_hasher_t hasher;
qse_oht_comper_t comper;
qse_oht_copier_t copier;
qse_oht_mark_t* mark;
void* data;
};
typedef qse_oht_walk_t (*qse_oht_walker_t) (
qse_oht_t* oht,
void* data,
void* ctx
);
#ifdef __cplusplus
extern "C" {
#endif
QSE_DEFINE_COMMON_FUNCTIONS (oht)
qse_oht_t* qse_oht_open (
qse_mmgr_t* mmgr,
qse_size_t xtnsize,
qse_size_t scale,
qse_size_t capa,
qse_size_t limit
);
void qse_oht_close (
qse_oht_t* oht
);
qse_oht_t* qse_oht_init (
qse_oht_t* oht,
qse_mmgr_t* mmgr,
qse_size_t scale,
qse_size_t capa,
qse_size_t limit
);
void qse_oht_fini (
qse_oht_t* oht
);
qse_oht_hasher_t qse_oht_gethasher (
qse_oht_t* oht
);
void qse_oht_sethasher (
qse_oht_t* oht,
qse_oht_hasher_t hahser
);
qse_oht_comper_t qse_oht_getcomper (
qse_oht_t* oht
);
void qse_oht_setcomper (
qse_oht_t* oht,
qse_oht_comper_t hahser
);
qse_oht_copier_t qse_oht_getcopier (
qse_oht_t* oht
);
void qse_oht_setcopier (
qse_oht_t* oht,
qse_oht_copier_t hahser
);
qse_size_t qse_oht_search (
qse_oht_t* oht,
void* data
);
qse_size_t qse_oht_insert (
qse_oht_t* oht,
const void* data
);
qse_size_t qse_oht_upsert (
qse_oht_t* oht,
const void* data
);
qse_size_t qse_oht_update (
qse_oht_t* oht,
const void* data
);
qse_size_t qse_oht_delete (
qse_oht_t* oht,
const void* data
);
void qse_oht_clear (
qse_oht_t* oht
);
void qse_oht_walk (
qse_oht_t* oht, /**< open-addressed hash table */
qse_oht_walker_t walker, /**< walker function */
void* ctx /**< context */
);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,5 +1,5 @@
/*
* $Id: sll.h 354 2010-09-03 12:50:08Z hyunghwan.chung $
* $Id: sll.h 355 2010-09-07 10:57:43Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.
@ -123,9 +123,9 @@ struct qse_sll_t
*/
struct qse_sll_node_t
{
void* dptr; /* the pointer to data */
qse_size_t dlen; /* the length of data */
qse_sll_node_t* next; /* the pointer to the next node */
qse_sll_node_t* next; /* point to the next node */
void* dptr; /* data pointer */
qse_size_t dlen; /* data length */
};
#define QSE_SLL_COPIER_SIMPLE ((qse_sll_copier_t)1)

View File

@ -46,7 +46,7 @@
* ptr2 = qse_xma_alloc (xma, 1000); // allocate a 1K block from the zone
* ptr1 = qse_xma_realloc (xma, ptr1, 6000); // resize the 5K block to 6K.
*
* qse_xma_dump (xma, qse_printf); // dump memory blocks
* qse_xma_dump (xma, qse_fprintf, QSE_STDOUT); // dump memory blocks
*
* // the following two lines are not actually needed as the allocator
* // is closed after them.
@ -104,6 +104,8 @@ struct qse_xma_t
#endif
};
typedef int (*qse_xma_dumper_t) (void* target, const qse_char_t* fmt,...);
#ifdef __cplusplus
extern "C" {
#endif
@ -189,8 +191,9 @@ void qse_xma_free (
* more statistical counters.
*/
void qse_xma_dump (
qse_xma_t* xma, /**< memory allocator */
int (*printf)(const qse_char_t* fmt,...) /**< output function */
qse_xma_t* xma, /**< memory allocator */
qse_xma_dumper_t dumper, /**< output function */
void* target /**< first parameter to output function */
);
#ifdef __cplusplus