added another new hash table implementation based on fr

This commit is contained in:
2017-11-30 05:46:42 +00:00
parent 02f3adf134
commit 5db7ddc770
49 changed files with 2113 additions and 647 deletions

View File

@ -356,7 +356,6 @@ pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@

View File

@ -396,7 +396,6 @@ pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@

View File

@ -347,7 +347,6 @@ pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@

View File

@ -12,6 +12,7 @@ pkginclude_HEADERS = \
fmt.h \
gdl.h \
htb.h \
htl.h \
hton.h \
hwad.h \
ipad.h \

View File

@ -133,13 +133,13 @@ am__can_run_installinfo = \
*) (install-info --version) >/dev/null 2>&1;; \
esac
am__pkginclude_HEADERS_DIST = alg.h arr.h chr.h cp949.h cp950.h dll.h \
env.h fma.h fmt.h gdl.h htb.h hton.h hwad.h ipad.h main.h \
map.h mb8.h mbwc.h mem.h oht.h opt.h path.h pma.h rbt.h rex.h \
sll.h slmb.h str.h time.h tmr.h tre.h uni.h uri.h utf8.h xma.h \
Mmgr.hpp StdMmgr.hpp HeapMmgr.hpp Mmged.hpp ScopedPtr.hpp \
SharedPtr.hpp StrBase.hpp String.hpp Mpool.hpp Association.hpp \
LinkedList.hpp HashList.hpp HashTable.hpp RedBlackTree.hpp \
RedBlackTable.hpp Array.hpp BinaryHeap.hpp
env.h fma.h fmt.h gdl.h htb.h htl.h hton.h hwad.h ipad.h \
main.h map.h mb8.h mbwc.h mem.h oht.h opt.h path.h pma.h rbt.h \
rex.h sll.h slmb.h str.h time.h tmr.h tre.h uni.h uri.h utf8.h \
xma.h Mmgr.hpp StdMmgr.hpp HeapMmgr.hpp Mmged.hpp \
ScopedPtr.hpp SharedPtr.hpp StrBase.hpp String.hpp Mpool.hpp \
Association.hpp LinkedList.hpp HashList.hpp HashTable.hpp \
RedBlackTree.hpp RedBlackTable.hpp Array.hpp BinaryHeap.hpp
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
@ -361,7 +361,6 @@ pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
@ -373,9 +372,9 @@ top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
pkginclude_HEADERS = alg.h arr.h chr.h cp949.h cp950.h dll.h env.h \
fma.h fmt.h gdl.h htb.h hton.h hwad.h ipad.h main.h map.h \
mb8.h mbwc.h mem.h oht.h opt.h path.h pma.h rbt.h rex.h sll.h \
slmb.h str.h time.h tmr.h tre.h uni.h uri.h utf8.h xma.h \
fma.h fmt.h gdl.h htb.h htl.h hton.h hwad.h ipad.h main.h \
map.h mb8.h mbwc.h mem.h oht.h opt.h path.h pma.h rbt.h rex.h \
sll.h slmb.h str.h time.h tmr.h tre.h uni.h uri.h utf8.h xma.h \
$(am__append_1)
all: all-am

302
qse/include/qse/cmn/htl.h Normal file
View File

@ -0,0 +1,302 @@
/*
* $Id$
*
Copyright (c) 2006-2014 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _QSE_HTL_T_
#define _QSE_HTL_T_
/** \file
* This file provides the hash table for fixed-size data.
*/
#include <qse/types.h>
#include <qse/macros.h>
/**
* The #qse_htl_walk_t type defines walking directions.
*/
enum qse_htl_walk_t
{
QSE_HTL_WALK_STOP = 0,
QSE_HTL_WALK_FORWARD = 1,
};
typedef enum qse_htl_walk_t qse_htl_walk_t;
typedef struct qse_htl_t qse_htl_t;
typedef struct qse_htl_node_t qse_htl_node_t;
/**
* The #qse_htl_hasher_t type defines a data hasher function.
*/
typedef qse_size_t (*qse_htl_hasher_t) (
qse_htl_t* htl,
const void* data
);
/**
* The #qse_htl_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_htl_comper_t) (
qse_htl_t* htl, /**< hash table */
const void* data1, /**< data pointer */
const void* data2 /**< data pointer */
);
/**
* The #qse_htl_feeeer_t type defines a data deallocation function.
*/
typedef void (*qse_htl_freeer_t) (
qse_htl_t* htl,
void* data
);
/**
* The #qse_htl_copier_t type defines a data copier function.
*/
typedef void* (*qse_htl_copier_t) (
qse_htl_t* htl,
void* data
);
/**
* The #qse_htl_walker_t function defines a callback function
* for qse_htl_walk().
*/
typedef qse_htl_walk_t (*qse_htl_walker_t) (
qse_htl_t* htl,
void* data,
void* ctx
);
struct qse_htl_node_t
{
struct qse_htl_node_t* next;
qse_uint32_t reversed;
qse_uint32_t key;
void* data;
};
struct qse_htl_t
{
qse_mmgr_t* mmgr;
int keysize; /* default key size */
int num_elements;
int num_buckets; /* power of 2 */
int next_grow;
int mask;
qse_htl_hasher_t hasher;
qse_htl_comper_t comper;
qse_htl_freeer_t freeer;
qse_htl_copier_t copier;
qse_htl_node_t null;
qse_htl_node_t** buckets;
};
#if defined(__cplusplus)
extern "C" {
#endif
/**
* The qse_htl_open() function creates an hash table.
*/
QSE_EXPORT qse_htl_t* qse_htl_open (
qse_mmgr_t* mmgr,
qse_size_t xtnsize,
int scale
);
/**
* The qse_htl_close() function destroys an hash table.
*/
QSE_EXPORT void qse_htl_close (
qse_htl_t* htl /**< hash table */
);
/**
* The qse_htl_open() function initializes an hash table.
*/
QSE_EXPORT int qse_htl_init (
qse_htl_t* htl,
qse_mmgr_t* mmgr,
int scale
);
/**
* The qse_htl_close() function finalizes an hash table.
*/
QSE_EXPORT void qse_htl_fini (
qse_htl_t* htl /**< hash table */
);
#if defined(QSE_HAVE_INLINE)
static QSE_INLINE qse_mmgr_t* qse_htl_getmmgr (qse_htl_t* htl) { return (htl)->mmgr; }
#else
#define qse_htl_getmmgr(htl) ((htl)->mmgr))
#endif
#if defined(QSE_HAVE_INLINE)
static QSE_INLINE void* qse_htl_getxtn (qse_htl_t* htl) { return QSE_XTN(htl); }
#else
#define qse_htl_getxtn(htl) (QSE_XTN(htl))
#endif
#if defined(QSE_HAVE_INLINE)
static QSE_INLINE int qse_htl_getsize (qse_htl_t* htl) { return htl->num_elements; }
#else
#define qse_htl_getsize(htl) ((htl)->num_elements)
#endif
#if defined(QSE_HAVE_INLINE)
static QSE_INLINE qse_htl_hasher_t qse_htl_gethasher (qse_htl_t* htl) { return htl->hasher; }
static QSE_INLINE qse_htl_comper_t qse_htl_getcomper (qse_htl_t* htl) { return htl->comper; }
static QSE_INLINE qse_htl_freeer_t qse_htl_getfreeer (qse_htl_t* htl) { return htl->freeer; }
static QSE_INLINE void qse_htl_sethasher (qse_htl_t* htl, qse_htl_hasher_t _hasher) { htl->hasher = _hasher; }
static QSE_INLINE void qse_htl_setcomper (qse_htl_t* htl, qse_htl_comper_t _comper) { htl->comper = _comper; }
static QSE_INLINE void qse_htl_setfreeer (qse_htl_t* htl, qse_htl_freeer_t _freeer) { htl->freeer = _freeer; }
static QSE_INLINE void qse_htl_setcopier (qse_htl_t* htl, qse_htl_copier_t _copier) { htl->copier = _copier; }
#else
#define qse_htl_gethasher(htl) ((htl)->hasher)
#define qse_htl_getcomper(htl) ((htl)->comper)
#define qse_htl_getfreeer(htl) ((htl)->freeer)
#define qse_htl_sethasher(htl,_hahser) ((htl)->hasher = _hasher)
#define qse_htl_setcomper(htl,_comper) ((htl)->comper = _comper)
#define qse_htl_setfreeer(htl,_freeer) ((htl)->freeer = _freeer)
#define qse_htl_setcopier(htl,_copier) ((htl)->copier = _copier)
#endif
/**
* The qse_htl_search() function searches a hash table to find a
* matching datum. It returns the index to the slot of an internal array
* where the matching datum is found.
* \return slot index if a match if found,
* #QSE_HTL_NIL if no match is found.
*/
QSE_EXPORT qse_htl_node_t* qse_htl_search (
qse_htl_t* htl, /**< hash table */
void* data /**< data pointer */
);
/**
* The qse_htl_insert() function inserts a new datum. It fails if it finds
* an existing datum.
* \return slot index where the new datum is inserted on success,
* #QSE_HTL_NIL on failure.
*/
QSE_EXPORT qse_htl_node_t* qse_htl_insert (
qse_htl_t* htl, /**< hash table */
void* data /**< data pointer */
);
/**
* The qse_htl_upsert() function inserts a new datum if it finds no matching
* datum or updates an exsting datum if finds a matching datum.
* \return slot index where the datum is inserted or updated.
*/
QSE_EXPORT qse_htl_node_t* qse_htl_upsert (
qse_htl_t* htl, /**< hash table */
void* data /**< data pointer */
);
/**
* The qse_htl_update() function updates an existing datum. It fails if it finds
* no existing datum.
* \return slot index where an existing datum is updated on success,
* #QSE_HTL_NIL on failure.
*/
QSE_EXPORT qse_htl_node_t* qse_htl_update (
qse_htl_t* htl, /**< hash table */
void* data /**< data pointer */
);
/**
* The qse_htl_ensert() function inserts a new item if one is not found.
* It returns an existing item otherwise.
*/
QSE_EXPORT qse_htl_node_t* qse_htl_ensert (
qse_htl_t* htl, /**< hash table */
void* data /**< data pointer */
);
/**
* The qse_htl_delete() function deletes an existing datum. It fails if it finds
* no existing datum.
* \return 0 on success, -1 on failure
*/
QSE_EXPORT int qse_htl_delete (
qse_htl_t* htl, /**< hash table */
void* data /**< data pointer */
);
QSE_EXPORT void* qse_htl_yank (
qse_htl_t* ht,
void* data
);
/**
* The qse_htl_clear() functions deletes all data items.
*/
QSE_EXPORT void qse_htl_clear (
qse_htl_t* htl /**< hash table */
);
/**
* The qse_htl_walk() function executes the callback function @a walker for
* each valid data item.
*/
QSE_EXPORT void qse_htl_walk (
qse_htl_t* htl, /**< hash table */
qse_htl_walker_t walker, /**< callback function */
void* ctx /**< context */
);
/* ------------------------------------------------------------------------- */
QSE_EXPORT qse_uint32_t qse_genhash_update (const void* data, qse_size_t size, qse_uint32_t hash);
QSE_EXPORT qse_uint32_t qse_genhash (const void *data, qse_size_t size);
/*qse_uint32_t qse_foldhash (qse_uint32_t hash, int bits);*/
QSE_EXPORT qse_uint32_t qse_mbshash (const qse_mchar_t* p);
QSE_EXPORT qse_uint32_t qse_wcshash (const qse_wchar_t* p);
#if defined(QSE_CHAR_IS_WCHAR)
# define qse_strhash(x) qse_wcshash (x)
#else
# define qse_strhash(x) qse_mbshash (x)
#endif
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -345,7 +345,6 @@ pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@

View File

@ -345,7 +345,6 @@ pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@

View File

@ -345,7 +345,6 @@ pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@

View File

@ -46,16 +46,52 @@
#define QSE_RAD_ATTR_TYPE_COMBO_IP 13
#define QSE_RAD_ATTR_TYPE_TLV 14
struct qse_raddic_attr_flags_t
{
unsigned int addport : 1; /* add NAS-Port to IP address */
unsigned int has_tag : 1; /* tagged attribute */
unsigned int do_xlat : 1; /* strvalue is dynamic */
unsigned int unknown_attr : 1; /* not in dictionary */
unsigned int array : 1; /* pack multiples into 1 attr */
unsigned int has_value : 1; /* has a value */
unsigned int has_value_alias : 1; /* has a value alias */
unsigned int has_tlv : 1; /* has sub attributes */
unsigned int is_tlv : 1; /* is a sub attribute */
unsigned int encoded : 1; /* has been put into packet */
qse_int8_t tag; /* tag for tunneled attributes */
qse_uint8_t encrypt; /* encryption method */
};
typedef struct qse_raddic_attr_flags_t qse_raddic_attr_flags_t;
struct qse_raddic_attr_t
{
int attr;
int type;
int vendor;
/* ATTR_FLAGS flags;*/
char name[1];
qse_raddic_attr_flags_t flags;
qse_char_t name[1];
};
typedef struct qse_raddic_attr_t qse_raddic_attr_t;
struct qse_raddic_value_t
{
int attr;
int value;
qse_char_t name[1];
};
typedef struct qse_raddic_value_t qse_raddic_value_t;
struct qse_raddic_vendor_t
{
int vendorpec;
int type;
int length;
int flags;
qse_char_t name[1];
};
typedef struct qse_raddic_vendor_t qse_raddic_vendor_t;
typedef struct qse_raddic_t qse_raddic_t;
#if defined(__cplusplus)

View File

@ -347,7 +347,6 @@ pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@

View File

@ -29,25 +29,39 @@
#include <qse/Types.hpp>
#include <qse/Uncopyable.hpp>
#include <qse/cmn/Mmged.hpp>
/////////////////////////////////
QSE_BEGIN_NAMESPACE(QSE)
/////////////////////////////////
class AppRoot: QSE::Uncopyable
class AppRoot: Uncopyable, public Types, public Mmged
{
public:
AppRoot (): _root_only (false) {}
AppRoot (Mmgr* mmgr): Mmged(mmgr), _root_only(false) {}
virtual ~AppRoot () {}
int daemonize (bool chdir_to_root = true, int fork_count = 1) QSE_CPP_NOEXCEPT;
static int chroot (const qse_wchar_t* wpath) QSE_CPP_NOEXCEPT;
static int chroot (const qse_mchar_t* mpath) QSE_CPP_NOEXCEPT;
int chroot (const qse_mchar_t* mpath) QSE_CPP_NOEXCEPT;
int chroot (const qse_wchar_t* wpath) QSE_CPP_NOEXCEPT;
#if 0
int switchUser (uid_t uid, gid_t gid, bool permanently) QSE_CPP_NOEXCEPT;
int restoreUser () QSE_CPP_NOEXCEPT;
#endif
protected:
bool _root_only;
#if 0
uid_t saved_uid;
gid_t saved_gid;
gid_t saved_groups[NGROUPS_MAX];
qse_size_t saved_ngroups;
void on_signal () QSE_CPP_NOEXCEPT;
void on_signal () QSE_CPP_NOEXCEPT;
#endif
};
/////////////////////////////////

View File

@ -354,7 +354,6 @@ pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@

View File

@ -278,6 +278,18 @@ QSE_EXPORT void qse_log_fini (
qse_log_t* log
);
#if defined(QSE_HAVE_INLINE)
static QSE_INLINE qse_mmgr_t* qse_log_getmmgr (qse_log_t* log) { return (log)->mmgr; }
#else
#define qse_log_getmmgr(log) ((log)->mmgr))
#endif
#if defined(QSE_HAVE_INLINE)
static QSE_INLINE void* qse_log_getxtn (qse_log_t* log) { return QSE_XTN(log); }
#else
#define qse_log_getxtn(log) (QSE_XTN(log))
#endif
QSE_EXPORT void qse_log_setident (
qse_log_t* log,
const qse_char_t* ident

View File

@ -345,7 +345,6 @@ pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@