added a sample code snippet for qse_bsearch

This commit is contained in:
hyung-hwan 2010-09-25 03:14:03 +00:00
parent 70f0002cea
commit a5f99ece99
2 changed files with 38 additions and 10 deletions

View File

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

View File

@ -51,12 +51,40 @@ typedef qse_search_comper_t qse_sort_comper_t;
/** /**
* The qse_bsearch() function performs binary search over a sorted array. * The qse_bsearch() function performs binary search over a sorted array.
* See the example below:
* @code
* static int compstr (const void* s1, const void* s2, void* ctx)
* {
* return qse_strcmp ((const qse_char_t*)s1, *(const qse_char_t**)s2);
* }
* int find (const qse_char_t* name)
* {
* static const qse_char_t* tgtnames[] =
* {
* QSE_T("awk"),
* QSE_T("cut"),
* QSE_T("ls"),
* QSE_T("rm"),
* QSE_T("sed"),
* QSE_T("tr"),
* QSE_T("watch")
* };
*
* const qse_char_t** ptr;
* ptr = (const qse_char_t**) qse_bsearch (
* name, tgtnames, QSE_COUNTOF(tgtnames),
* QSE_SIZEOF(qse_char_t*), QSE_NULL, compstr
* );
* return ptr? (ptr - tgtnames): -1;
* }
* @endcode
*/ */
void* qse_bsearch ( void* qse_bsearch (
const void* key, const void* key,
const void* base, const void* base,
qse_size_t nmemb, qse_size_t nmemb,
qse_size_t size, qse_size_t size,
qse_search_comper_t comper, qse_search_comper_t comper,
void* ctx void* ctx
); );
@ -64,11 +92,11 @@ void* qse_bsearch (
/** /**
* The qse_lsearch() function performs linear search over an array. * The qse_lsearch() function performs linear search over an array.
*/ */
void* qse_bsearch ( void* qse_lsearch (
const void* key, const void* key,
const void* base, const void* base,
qse_size_t nmemb, qse_size_t nmemb,
qse_size_t size, qse_size_t size,
qse_search_comper_t comper, qse_search_comper_t comper,
void* ctx void* ctx
); );