added another new hash table implementation based on fr
This commit is contained in:
@ -356,7 +356,6 @@ pdfdir = @pdfdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
runstatedir = @runstatedir@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
srcdir = @srcdir@
|
||||
|
@ -480,7 +480,6 @@ pdfdir = @pdfdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
runstatedir = @runstatedir@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
srcdir = @srcdir@
|
||||
|
@ -15,6 +15,7 @@ bin_PROGRAMS = \
|
||||
fmt01 \
|
||||
fmt02 \
|
||||
htb01 \
|
||||
htl01 \
|
||||
ipad01 \
|
||||
main01 \
|
||||
main02 \
|
||||
|
@ -90,11 +90,12 @@ build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
bin_PROGRAMS = arr01$(EXEEXT) chr01$(EXEEXT) dll$(EXEEXT) \
|
||||
env01$(EXEEXT) fma$(EXEEXT) fmt01$(EXEEXT) fmt02$(EXEEXT) \
|
||||
htb01$(EXEEXT) ipad01$(EXEEXT) main01$(EXEEXT) main02$(EXEEXT) \
|
||||
mbwc01$(EXEEXT) mbwc02$(EXEEXT) oht$(EXEEXT) path01$(EXEEXT) \
|
||||
pma$(EXEEXT) rex01$(EXEEXT) rbt01$(EXEEXT) sll$(EXEEXT) \
|
||||
slmb01$(EXEEXT) str01$(EXEEXT) str02$(EXEEXT) time$(EXEEXT) \
|
||||
tre01$(EXEEXT) uri01$(EXEEXT) xma$(EXEEXT) $(am__EXEEXT_1)
|
||||
htb01$(EXEEXT) htl01$(EXEEXT) ipad01$(EXEEXT) main01$(EXEEXT) \
|
||||
main02$(EXEEXT) mbwc01$(EXEEXT) mbwc02$(EXEEXT) oht$(EXEEXT) \
|
||||
path01$(EXEEXT) pma$(EXEEXT) rex01$(EXEEXT) rbt01$(EXEEXT) \
|
||||
sll$(EXEEXT) slmb01$(EXEEXT) str01$(EXEEXT) str02$(EXEEXT) \
|
||||
time$(EXEEXT) tre01$(EXEEXT) uri01$(EXEEXT) xma$(EXEEXT) \
|
||||
$(am__EXEEXT_1)
|
||||
@WCHAR_TRUE@@WIN32_TRUE@am__append_1 = $(UNICOWS_LIBS)
|
||||
|
||||
#bin_PROGRAMS += rex02
|
||||
@ -188,6 +189,10 @@ am__htb02_SOURCES_DIST = htb02.cpp
|
||||
@ENABLE_CXX_TRUE@am_htb02_OBJECTS = htb02.$(OBJEXT)
|
||||
htb02_OBJECTS = $(am_htb02_OBJECTS)
|
||||
@ENABLE_CXX_TRUE@htb02_DEPENDENCIES = $(am__DEPENDENCIES_3)
|
||||
htl01_SOURCES = htl01.c
|
||||
htl01_OBJECTS = htl01.$(OBJEXT)
|
||||
htl01_LDADD = $(LDADD)
|
||||
htl01_DEPENDENCIES = $(am__DEPENDENCIES_2)
|
||||
am_ipad01_OBJECTS = ipad01.$(OBJEXT)
|
||||
ipad01_OBJECTS = $(am_ipad01_OBJECTS)
|
||||
ipad01_LDADD = $(LDADD)
|
||||
@ -332,7 +337,7 @@ SOURCES = $(arr01_SOURCES) $(arr02_SOURCES) $(arr03_SOURCES) \
|
||||
$(bh01_SOURCES) $(bh02_SOURCES) $(chr01_SOURCES) \
|
||||
$(dll_SOURCES) $(env01_SOURCES) $(fma_SOURCES) \
|
||||
$(fmt01_SOURCES) $(fmt02_SOURCES) $(hl01_SOURCES) \
|
||||
$(htb01_SOURCES) $(htb02_SOURCES) $(ipad01_SOURCES) \
|
||||
$(htb01_SOURCES) $(htb02_SOURCES) htl01.c $(ipad01_SOURCES) \
|
||||
$(main01_SOURCES) $(main02_SOURCES) $(mbwc01_SOURCES) \
|
||||
$(mbwc02_SOURCES) $(oht_SOURCES) $(path01_SOURCES) \
|
||||
$(pma_SOURCES) $(rbt01_SOURCES) $(rbt02_SOURCES) \
|
||||
@ -345,10 +350,10 @@ DIST_SOURCES = $(arr01_SOURCES) $(am__arr02_SOURCES_DIST) \
|
||||
$(am__bh02_SOURCES_DIST) $(chr01_SOURCES) $(dll_SOURCES) \
|
||||
$(env01_SOURCES) $(fma_SOURCES) $(fmt01_SOURCES) \
|
||||
$(fmt02_SOURCES) $(am__hl01_SOURCES_DIST) $(htb01_SOURCES) \
|
||||
$(am__htb02_SOURCES_DIST) $(ipad01_SOURCES) $(main01_SOURCES) \
|
||||
$(main02_SOURCES) $(mbwc01_SOURCES) $(mbwc02_SOURCES) \
|
||||
$(oht_SOURCES) $(path01_SOURCES) $(pma_SOURCES) \
|
||||
$(rbt01_SOURCES) $(am__rbt02_SOURCES_DIST) \
|
||||
$(am__htb02_SOURCES_DIST) htl01.c $(ipad01_SOURCES) \
|
||||
$(main01_SOURCES) $(main02_SOURCES) $(mbwc01_SOURCES) \
|
||||
$(mbwc02_SOURCES) $(oht_SOURCES) $(path01_SOURCES) \
|
||||
$(pma_SOURCES) $(rbt01_SOURCES) $(am__rbt02_SOURCES_DIST) \
|
||||
$(am__rbt03_SOURCES_DIST) $(rex01_SOURCES) $(sll_SOURCES) \
|
||||
$(slmb01_SOURCES) $(am__sp01_SOURCES_DIST) \
|
||||
$(am__sp02_SOURCES_DIST) $(str01_SOURCES) \
|
||||
@ -550,7 +555,6 @@ pdfdir = @pdfdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
runstatedir = @runstatedir@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
srcdir = @srcdir@
|
||||
@ -754,6 +758,10 @@ htb02$(EXEEXT): $(htb02_OBJECTS) $(htb02_DEPENDENCIES) $(EXTRA_htb02_DEPENDENCIE
|
||||
@rm -f htb02$(EXEEXT)
|
||||
$(AM_V_CXXLD)$(CXXLINK) $(htb02_OBJECTS) $(htb02_LDADD) $(LIBS)
|
||||
|
||||
htl01$(EXEEXT): $(htl01_OBJECTS) $(htl01_DEPENDENCIES) $(EXTRA_htl01_DEPENDENCIES)
|
||||
@rm -f htl01$(EXEEXT)
|
||||
$(AM_V_CCLD)$(LINK) $(htl01_OBJECTS) $(htl01_LDADD) $(LIBS)
|
||||
|
||||
ipad01$(EXEEXT): $(ipad01_OBJECTS) $(ipad01_DEPENDENCIES) $(EXTRA_ipad01_DEPENDENCIES)
|
||||
@rm -f ipad01$(EXEEXT)
|
||||
$(AM_V_CCLD)$(LINK) $(ipad01_OBJECTS) $(ipad01_LDADD) $(LIBS)
|
||||
@ -862,6 +870,7 @@ distclean-compile:
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hl01.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/htb01.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/htb02.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/htl01.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipad01.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main01.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main02.Po@am__quote@
|
||||
|
209
qse/samples/cmn/htl01.c
Normal file
209
qse/samples/cmn/htl01.c
Normal file
@ -0,0 +1,209 @@
|
||||
#include <qse/cmn/mem.h>
|
||||
#include <qse/cmn/str.h>
|
||||
#include <qse/cmn/htl.h>
|
||||
#include <qse/si/sio.h>
|
||||
|
||||
#define R(f) \
|
||||
do { \
|
||||
qse_printf (QSE_T("== %s ==\n"), QSE_T(#f)); \
|
||||
if (f() == -1) return -1; \
|
||||
} while (0)
|
||||
|
||||
typedef struct item_t item_t;
|
||||
struct item_t
|
||||
{
|
||||
long a;
|
||||
long x;
|
||||
long y;
|
||||
};
|
||||
|
||||
static qse_htl_walk_t walk1 (qse_htl_t* htl, void* data, void* ctx)
|
||||
{
|
||||
qse_printf (QSE_T("[%ld]\n"), *(long*)data);
|
||||
return QSE_HTL_WALK_FORWARD;
|
||||
}
|
||||
|
||||
static qse_htl_walk_t walk2 (qse_htl_t* htl, void* data, void* ctx)
|
||||
{
|
||||
item_t* item = (item_t*)data;
|
||||
qse_printf (QSE_T("a [%ld] x [%ld] y [%ld]\n"), item->a, item->x, item->y);
|
||||
return QSE_HTL_WALK_FORWARD;
|
||||
}
|
||||
|
||||
static qse_size_t hash_item (qse_htl_t* htl, const void* data)
|
||||
{
|
||||
item_t* item = (item_t*)data;
|
||||
//return item->a + 123445;
|
||||
return qse_genhash (&item->a, QSE_SIZEOF(item->a));
|
||||
}
|
||||
|
||||
static int comp_item (qse_htl_t* htl, const void* data1, const void* data2)
|
||||
{
|
||||
return ((item_t*)data1)->a != ((item_t*)data2)->a;
|
||||
}
|
||||
|
||||
static void* copy_item (qse_htl_t* htl, void* data)
|
||||
{
|
||||
item_t* x = (item_t*)QSE_MMGR_ALLOC (htl->mmgr, QSE_SIZEOF(item_t));
|
||||
if (x) *x = *(item_t*)data;
|
||||
return x;
|
||||
}
|
||||
|
||||
static void free_item (qse_htl_t* htl, void* data)
|
||||
{
|
||||
QSE_MMGR_FREE (htl->mmgr, data);
|
||||
}
|
||||
|
||||
static void* copy_long (qse_htl_t* htl, void* data)
|
||||
{
|
||||
long* x = (long*)QSE_MMGR_ALLOC (htl->mmgr, QSE_SIZEOF(long));
|
||||
if (x) *x = *(long*)data;
|
||||
return x;
|
||||
}
|
||||
|
||||
static void free_long (qse_htl_t* htl, void* data)
|
||||
{
|
||||
QSE_MMGR_FREE (htl->mmgr, data);
|
||||
}
|
||||
|
||||
static int test1 ()
|
||||
{
|
||||
long x;
|
||||
qse_htl_t* htl;
|
||||
qse_htl_node_t* np;
|
||||
|
||||
htl = qse_htl_open (QSE_MMGR_GETDFL(), 0, QSE_SIZEOF(x));
|
||||
if (htl == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("failed to open a table\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
qse_htl_setcopier (htl, copy_long);
|
||||
qse_htl_setfreeer (htl, free_long);
|
||||
|
||||
for (x = 9; x < 20; x++)
|
||||
{
|
||||
if (qse_htl_insert(htl, &x))
|
||||
{
|
||||
qse_printf (QSE_T("SUCCESS: inserted %ld\n"), x);
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("FAILURE: failed to insert %ld\n"), x);
|
||||
}
|
||||
}
|
||||
|
||||
x = 10;
|
||||
if ((np = qse_htl_search(htl, &x)))
|
||||
{
|
||||
qse_printf (QSE_T("SUCCESS: found %ld\n"), *(long*)np->data);
|
||||
QSE_ASSERT (*(long*)np->data == x);
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("FAILURE: failed to found %ld\n"), x);
|
||||
}
|
||||
|
||||
x = 10;
|
||||
if (qse_htl_delete(htl, &x) == 0)
|
||||
{
|
||||
qse_printf (QSE_T("SUCCESS: deleted %ld\n"), x);
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("FAILURE: failed to delete %ld\n"), x);
|
||||
}
|
||||
|
||||
x = 10;
|
||||
qse_printf (QSE_T("searching for %ld\n"), x);
|
||||
np = qse_htl_search(htl, &x);
|
||||
QSE_ASSERT (np == QSE_NULL);
|
||||
if (np)
|
||||
{
|
||||
qse_printf (QSE_T("FAILURE: found something that must not be found - %ld\n"), x);
|
||||
}
|
||||
|
||||
qse_printf (QSE_T("total %lu items\n"), (unsigned long)qse_htl_getsize(htl));
|
||||
qse_htl_walk (htl, walk1, QSE_NULL);
|
||||
qse_htl_close (htl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test2 ()
|
||||
{
|
||||
item_t x;
|
||||
qse_htl_t* htl;
|
||||
qse_htl_node_t* np;
|
||||
|
||||
htl = qse_htl_open (QSE_MMGR_GETDFL(), 0, QSE_SIZEOF(x));
|
||||
if (htl == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("failed to open a table\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
qse_htl_sethasher (htl, hash_item);
|
||||
qse_htl_setcomper (htl, comp_item);
|
||||
qse_htl_setcopier (htl, copy_item);
|
||||
qse_htl_setfreeer (htl, free_item);
|
||||
|
||||
for (x.a = 9; x.a < 20; x.a++)
|
||||
{
|
||||
x.x = x.a * 10;
|
||||
x.y = x.a * 100;
|
||||
|
||||
if (qse_htl_insert(htl, &x))
|
||||
{
|
||||
qse_printf (QSE_T("SUCCESS: inserted %ld\n"), x.a);
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("FAILURE: failed to insert %ld\n"), x.a);
|
||||
}
|
||||
}
|
||||
|
||||
x.a = 10;
|
||||
if ((np = qse_htl_search(htl, &x)))
|
||||
{
|
||||
qse_printf (QSE_T("SUCCESS: found %ld\n"), *(long*)np->data);
|
||||
QSE_ASSERT (*(long*)np->data == x.a);
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("FAILURE: failed to found %ld\n"), x.a);
|
||||
}
|
||||
|
||||
x.a = 10;
|
||||
if (qse_htl_delete(htl, &x) == 0)
|
||||
{
|
||||
qse_printf (QSE_T("SUCCESS: deleted %ld\n"), x.a);
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("FAILURE: failed to delete %ld\n"), x.a);
|
||||
}
|
||||
|
||||
x.a = 10;
|
||||
qse_printf (QSE_T("searching for %ld\n"), x.a);
|
||||
np = qse_htl_search(htl, &x);
|
||||
QSE_ASSERT (np == QSE_NULL);
|
||||
if (np)
|
||||
{
|
||||
qse_printf (QSE_T("FAILURE: found something that must not be found - %ld\n"), x.a);
|
||||
}
|
||||
|
||||
qse_printf (QSE_T("total %lu items\n"), (unsigned long)qse_htl_getsize(htl));
|
||||
qse_htl_walk (htl, walk2, QSE_NULL);
|
||||
qse_htl_close (htl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main ()
|
||||
{
|
||||
qse_open_stdsios ();
|
||||
R (test1);
|
||||
R (test2);
|
||||
qse_close_stdsios ();
|
||||
return 0;
|
||||
}
|
@ -351,7 +351,6 @@ pdfdir = @pdfdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
runstatedir = @runstatedir@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
srcdir = @srcdir@
|
||||
|
@ -352,7 +352,6 @@ pdfdir = @pdfdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
runstatedir = @runstatedir@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
srcdir = @srcdir@
|
||||
|
@ -391,7 +391,6 @@ pdfdir = @pdfdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
runstatedir = @runstatedir@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
srcdir = @srcdir@
|
||||
|
@ -433,7 +433,6 @@ pdfdir = @pdfdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
runstatedir = @runstatedir@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
srcdir = @srcdir@
|
||||
|
Reference in New Issue
Block a user