added qse_bsearch(), qse_lsearch(), qse_qsort()
This commit is contained in:
@ -1,9 +1,29 @@
|
||||
pkgincludedir = $(includedir)/qse/cmn
|
||||
|
||||
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
|
||||
alg.h \
|
||||
chr.h \
|
||||
dll.h \
|
||||
fio.h \
|
||||
fma.h \
|
||||
gdl.h \
|
||||
htb.h \
|
||||
lda.h \
|
||||
main.h \
|
||||
mem.h \
|
||||
misc.h \
|
||||
oht.h \
|
||||
opt.h \
|
||||
pio.h \
|
||||
rbt.h \
|
||||
rex.h \
|
||||
sio.h \
|
||||
sll.h \
|
||||
stdio.h \
|
||||
str.h \
|
||||
time.h \
|
||||
tio.h \
|
||||
xma.h
|
||||
|
||||
if ENABLE_CXX
|
||||
pkginclude_HEADERS += Mmgr.hpp StdMmgr.hpp Mmged.hpp
|
||||
|
88
qse/include/qse/cmn/alg.h
Normal file
88
qse/include/qse/cmn/alg.h
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* $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 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 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/>.
|
||||
*/
|
||||
|
||||
#ifndef _QSE_ALG_H_
|
||||
#define _QSE_ALG_H_
|
||||
|
||||
/** @file
|
||||
* This file provides functions for commonly used algorithms.
|
||||
*/
|
||||
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
|
||||
/**
|
||||
* The qse_search_comper_t type defines a search callback function.
|
||||
* The callback function is called by search functions for each comparison
|
||||
* performed. It should return 0 if @a ptr1 and @a ptr2 are
|
||||
* euqal, a positive integer if @a ptr1 is greater than @a ptr2, a negative
|
||||
* if @a ptr2 is greater than @a ptr1. Both @a ptr1 and @a ptr2 are
|
||||
* pointers to any two items in the array. @a ctx which is a pointer to
|
||||
* user-defined data passed to a search function is passed to the callback
|
||||
* with no modification.
|
||||
*/
|
||||
typedef int (*qse_search_comper_t) (
|
||||
const void* ptr1,
|
||||
const void* ptr2,
|
||||
void* ctx
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_sort_comper_t type defines a sort callback function.
|
||||
*/
|
||||
typedef qse_search_comper_t qse_sort_comper_t;
|
||||
|
||||
/**
|
||||
* The qse_bsearch() function performs binary search over a sorted array.
|
||||
*/
|
||||
void* qse_bsearch (
|
||||
const void* key,
|
||||
const void* base,
|
||||
qse_size_t nmemb,
|
||||
qse_size_t size,
|
||||
qse_search_comper_t comper,
|
||||
void* ctx
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_lsearch() function performs linear search over an array.
|
||||
*/
|
||||
void* qse_bsearch (
|
||||
const void* key,
|
||||
const void* base,
|
||||
qse_size_t nmemb,
|
||||
qse_size_t size,
|
||||
qse_search_comper_t comper,
|
||||
void* ctx
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* The qse_qsort() function performs quick-sorting over an array.
|
||||
*/
|
||||
void qse_qsort (
|
||||
void* base,
|
||||
qse_size_t nmemb,
|
||||
qse_size_t size,
|
||||
qse_sort_comper_t comper,
|
||||
void* ctx
|
||||
);
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user