still modifying ase_lda_t

This commit is contained in:
hyung-hwan 2008-10-08 05:30:16 +00:00
parent 76580ef4eb
commit b461e7f30d
6 changed files with 303 additions and 129 deletions

View File

@ -22,6 +22,7 @@
typedef struct ase_lda_t ase_lda_t;
typedef struct ase_lda_cell_t ase_lda_cell_t;
#define ASE_LDA_COPIER_SIMPLE ase_lda_copysimple
#define ASE_LDA_COPIER_INLINE ase_lda_copyinline
#define ASE_LDA_INVALID ((ase_size_t)-1)
@ -240,6 +241,20 @@ ase_lda_t* ase_lda_setcapa (
ase_size_t capa
);
ase_size_t ase_lda_search (
ase_lda_t* lda,
ase_size_t pos,
const void* dptr,
ase_size_t dlen
);
ase_size_t ase_lda_rsearch (
ase_lda_t* lda,
ase_size_t pos,
const void* dptr,
ase_size_t dlen
);
ase_size_t ase_lda_insert (
ase_lda_t* lda,
ase_size_t index,
@ -283,11 +298,16 @@ ase_size_t ase_lda_rrfindx (
void ase_lda_clear (ase_lda_t* lda);
void* ase_lda_copysimple (
ase_lda_t* lda /* a linear dynamic array */,
void* data /* the pointer to data */,
ase_size_t len /* the length of data */
);
void* ase_lda_copyinline (
ase_lda_t* lda /* a linear dynamic array */,
void* data /* pointer to data to copy */ ,
ase_size_t len /* length of data in bytes */
void* data /* the pointer to data */,
ase_size_t len /* the length of data */
);
#ifdef __cplusplus

View File

@ -1,5 +1,5 @@
/*
* $Id: map.h 398 2008-09-29 10:01:15Z baconevi $
* $Id: map.h 408 2008-10-07 11:30:16Z baconevi $
*
* {License}
*/
@ -183,8 +183,7 @@ struct ase_map_t
};
/******/
#define ASE_MAP_COPIER_SIMPLE ase_map_copysimple
#define ASE_MAP_COPIER_INLINE ase_map_copyinline
/****d* ase.cmn.map/ASE_MAP_SIZE
@ -547,7 +546,17 @@ ase_map_pair_t* ase_map_getnextpair (
ase_size_t* buckno
);
void* ase_map_copyinline (ase_map_t* map, void* dptr, ase_size_t dlen);
void* ase_map_copysimple (
ase_map_t* map /* a linear dynamic array */,
void* data /* the pointer to data */,
ase_size_t len /* the length of data */
);
void* ase_map_copyinline (
ase_map_t* map /* a linear dynamic array */,
void* data /* the pointer to data */,
ase_size_t len /* the length of data */
);
#ifdef __cplusplus
}

View File

@ -162,6 +162,7 @@ struct ase_sll_node_t
};
/******/
#define ASE_SLL_COPIER_SIMPLE ase_sll_copysimple
#define ASE_SLL_COPIER_INLINE ase_sll_copyinline
#define ASE_SLL_MMGR(sll) ((sll)->mmgr)
@ -573,14 +574,24 @@ void ase_sll_walk (
);
/******/
/*
* Causes a singly linked list to remember the pointer and the length.
* Use ASE_SLL_COPIER_SIMPLE instead.
*/
void* ase_sll_copysimple (
ase_sll_t* sll /* a singly linked list */,
void* data /* the pointer to data */,
ase_size_t len /* the length of data */
);
/*
* Causes a singly linked list to copy in data to a node.
* Use ASE_SLL_COPIER_INLINE instead.
*/
void* ase_sll_copyinline (
ase_sll_t* sll /* a singly linked list */,
void* data /* pointer to data to copy */ ,
ase_size_t len /* length of data in bytes */
void* data /* the pointer to data */,
ase_size_t len /* the length of data */
);
#ifdef __cplusplus

View File

@ -7,16 +7,76 @@
#include <ase/cmn/lda.h>
#include "mem.h"
#define DPTR(cell) ASE_LDA_DPTR(cell)
#define DLEN(cell) ASE_LDA_DLEN(cell)
#define TOB(lda,len) ((len)*(lda)->scale)
#define INVALID ASE_LDA_INVALID
#define cell_t ase_lda_cell_t
#define lda_t ase_lda_t
#define cell_t ase_lda_cell_t
#define copier_t ase_lda_copier_t
#define freeer_t ase_lda_freeer_t
#define comper_t ase_lda_comper_t
#define walker_t ase_lda_walker_t
#define size_t ase_size_t
#define mmgr_t ase_mmgr_t
#define TOB(lda,len) ((len)*(lda)->scale)
#define DPTR(cell) ASE_LDA_DPTR(cell)
#define DLEN(cell) ASE_LDA_DLEN(cell)
#define INVALID ASE_LDA_INVALID
static int comp_data (lda_t* lda,
const void* dptr1, size_t dlen1,
const void* dptr2, size_t dlen2)
{
/*
if (dlen1 == dlen2) return ASE_MEMCMP (dptr1, dptr2, TOB(lda,dlen1));
return 1;
*/
size_t min = (dlen1 < dlen2)? dlen1: dlen2;
int n = ASE_MEMCMP (dptr1, dptr2, TOB(lda,min));
if (n == 0 && dlen1 != dlen2)
{
n = (dlen1 > dlen2)? 1: -1;
}
return n;
}
static cell_t* alloc_cell (lda_t* lda, void* dptr, size_t dlen)
{
cell_t* n;
if (lda->copier == ASE_NULL ||
lda->copier == ASE_LDA_COPIER_SIMPLE)
{
n = ASE_MMGR_ALLOC (lda->mmgr, ASE_SIZEOF(cell_t));
if (n == ASE_NULL) return ASE_NULL;
DPTR(n) = dptr;
}
else if (lda->copier == ASE_LDA_COPIER_INLINE)
{
n = ASE_MMGR_ALLOC (lda->mmgr,
ASE_SIZEOF(cell_t) + TOB(lda,dlen));
if (n == ASE_NULL) return ASE_NULL;
ASE_MEMCPY (n + 1, dptr, TOB(lda,dlen));
DPTR(n) = n + 1;
}
else
{
n = ASE_MMGR_ALLOC (lda->mmgr, ASE_SIZEOF(cell_t));
if (n == ASE_NULL) return ASE_NULL;
DPTR(n) = lda->copier (lda, dptr, dlen);
if (DPTR(n) == ASE_NULL)
{
ASE_MMGR_FREE (lda->mmgr, n);
return ASE_NULL;
}
}
DLEN(n) = dlen;
return n;
}
lda_t* ase_lda_open (mmgr_t* mmgr, size_t ext, size_t capa)
{
lda_t* lda;
@ -52,6 +112,8 @@ lda_t* ase_lda_init (lda_t* lda, mmgr_t* mmgr, size_t capa)
lda->capa = 0;
lda->cell = ASE_NULL;
lda->comper = comp_data;
if (ase_lda_setcapa (lda, capa) == ASE_NULL) return ASE_NULL;
return lda;
}
@ -83,6 +145,55 @@ void ase_lda_setmmgr (lda_t* lda, mmgr_t* mmgr)
lda->mmgr = mmgr;
}
int ase_lda_getscale (lda_t* lda)
{
return lda->scale;
}
void ase_lda_setscale (lda_t* lda, int scale)
{
ASE_ASSERTX (scale > 0 && scale <= ASE_TYPE_MAX(ase_byte_t),
"The scale should be larger than 0 and less than or equal to the maximum value that the ase_byte_t type can hold");
if (scale <= 0) scale = 1;
if (scale > ASE_TYPE_MAX(ase_byte_t)) scale = ASE_TYPE_MAX(ase_byte_t);
lda->scale = scale;
}
copier_t ase_lda_getcopier (lda_t* lda)
{
return lda->copier;
}
void ase_lda_setcopier (lda_t* lda, copier_t copier)
{
lda->copier = copier;
}
freeer_t ase_lda_getfreeer (lda_t* lda)
{
return lda->freeer;
}
void ase_lda_setfreeer (lda_t* lda, freeer_t freeer)
{
lda->freeer = freeer;
}
comper_t ase_lda_getcomper (lda_t* lda)
{
return lda->comper;
}
void ase_lda_setcomper (lda_t* lda, comper_t comper)
{
if (comper == ASE_NULL) comper = comp_data;
lda->comper = comper;
}
size_t ase_lda_getsize (lda_t* lda)
{
return lda->size;
@ -142,43 +253,53 @@ lda_t* ase_lda_setcapa (lda_t* lda, size_t capa)
return lda;
}
static cell_t* alloc_cell (lda_t* lda, void* dptr, size_t dlen)
size_t ase_lda_search (lda_t* lda, size_t pos, const void* dptr, size_t dlen)
{
cell_t* n;
size_t i;
if (lda->copier == ASE_NULL)
for (i = pos; i < lda->size; i++)
{
n = ASE_MMGR_ALLOC (lda->mmgr, ASE_SIZEOF(cell_t));
if (n == ASE_NULL) return ASE_NULL;
DPTR(n) = dptr;
}
else if (lda->copier == ASE_LDA_COPIER_INLINE)
{
n = ASE_MMGR_ALLOC (lda->mmgr,
ASE_SIZEOF(cell_t) + TOB(lda,dlen));
if (n == ASE_NULL) return ASE_NULL;
ASE_MEMCPY (n + 1, dptr, TOB(lda,dlen));
DPTR(n) = n + 1;
}
else
{
n = ASE_MMGR_ALLOC (lda->mmgr, ASE_SIZEOF(cell_t));
if (n == ASE_NULL) return ASE_NULL;
DPTR(n) = lda->copier (lda, dptr, dlen);
if (DPTR(n) == ASE_NULL)
{
ASE_MMGR_FREE (lda->mmgr, n);
return ASE_NULL;
}
if (lda->comper(lda,
DPTR(lda->cell[i]), DLEN(lda->cell[i]),
dptr, dlen) == 0) return i;
}
DLEN(n) = dlen;
return n;
return INVALID;
}
size_t ase_lda_insert (lda_t* lda, size_t index, void* dptr, size_t dlen)
size_t ase_lda_rsearch (lda_t* lda, size_t pos, const void* dptr, size_t dlen)
{
size_t i;
if (pos >= lda->size) return INVALID;
for (i = pos + 1; i-- > 0; )
{
if (lda->comper(lda,
DPTR(lda->cell[i]), DLEN(lda->cell[i]),
dptr, dlen) == 0) return i;
}
return INVALID;
}
size_t ase_lda_rrsearch (lda_t* lda, size_t pos, const void* dptr, size_t dlen)
{
size_t i;
if (pos >= lda->size) return INVALID;
for (i = lda->size - pos; i-- > 0; )
{
if (lda->comper(lda,
DPTR(lda->cell[i]), DLEN(lda->cell[i]),
dptr, dlen) == 0) return i;
}
return INVALID;
}
size_t ase_lda_insert (lda_t* lda, size_t pos, void* dptr, size_t dlen)
{
size_t i;
cell_t* cell;
@ -186,14 +307,14 @@ size_t ase_lda_insert (lda_t* lda, size_t index, void* dptr, size_t dlen)
cell = alloc_cell (lda, dptr, dlen);
if (cell == ASE_NULL) return INVALID;
if (index >= lda->capa)
if (pos >= lda->capa)
{
size_t capa;
if (lda->capa <= 0) capa = (index + 1);
if (lda->capa <= 0) capa = (pos + 1);
else
{
do { capa = lda->capa * 2; } while (index >= capa);
do { capa = lda->capa * 2; } while (pos >= capa);
}
if (ase_lda_setcapa(lda,capa) == ASE_NULL)
@ -204,14 +325,14 @@ size_t ase_lda_insert (lda_t* lda, size_t index, void* dptr, size_t dlen)
}
}
for (i = lda->size; i > index; i--)
for (i = lda->size; i > pos; i--)
lda->cell[i] = lda->cell[i-1];
lda->cell[index] = cell;
lda->cell[pos] = cell;
if (index > lda->size) lda->size = index + 1;
if (pos > lda->size) lda->size = pos + 1;
else lda->size++;
return index;
return pos;
}
size_t ase_lda_delete (lda_t* lda, size_t index, size_t count)
@ -283,9 +404,7 @@ size_t ase_lda_adduniq (
}
#if 0
size_t ase_lda_find (
lda_t* lda, size_t index,
const ase_char_t* str, size_t len)
size_t ase_lda_find (lda_t* lda, size_t index, const ase_char_t* str, size_t len)
{
size_t i;
@ -299,9 +418,7 @@ size_t ase_lda_find (
return INVALID;
}
size_t ase_lda_rfind (
lda_t* lda, size_t index,
const ase_char_t* str, size_t len)
size_t ase_lda_rfind (lda_t* lda, size_t index, const ase_char_t* str, size_t len)
{
size_t i;
@ -317,9 +434,7 @@ size_t ase_lda_rfind (
return INVALID;
}
size_t ase_lda_rrfind (
lda_t* lda, size_t index,
const ase_char_t* str, size_t len)
size_t ase_lda_rrfind (lda_t* lda, size_t index, const ase_char_t* str, size_t len)
{
size_t i;
@ -402,6 +517,12 @@ size_t ase_lda_rrfindx (
return INVALID;
}
#endif
void* ase_lda_copysimple (lda_t* lda, void* dptr, size_t dlen)
{
return dptr;
}
void* ase_lda_copyinline (lda_t* lda, void* dptr, size_t dlen)
{
@ -409,4 +530,3 @@ void* ase_lda_copyinline (lda_t* lda, void* dptr, size_t dlen)
return ASE_NULL;
}
#endif

View File

@ -1,5 +1,5 @@
/*
* $Id: map.c 404 2008-09-30 11:14:20Z baconevi $
* $Id: map.c 408 2008-10-07 11:30:16Z baconevi $
*
* {License}
*/
@ -75,7 +75,8 @@ static pair_t* alloc_pair (map_t* map,
NEXT(n) = ASE_NULL;
KLEN(n) = klen;
if (kcop == ASE_NULL)
if (kcop == ASE_NULL ||
kcop == ASE_MAP_COPIER_SIMPLE)
{
KPTR(n) = kptr;
}
@ -95,7 +96,8 @@ static pair_t* alloc_pair (map_t* map,
}
VLEN(n) = vlen;
if (vcop == ASE_NULL)
if (vcop == ASE_NULL ||
vcop == ASE_MAP_COPIER_SIMPLE)
{
VPTR(n) = vptr;
}
@ -150,7 +152,8 @@ static pair_t* change_pair_val (
size_t ovlen = VLEN(pair);
/* place the new value according to the copier */
if (vcop == ASE_NULL)
if (vcop == ASE_NULL ||
vcop == ASE_MAP_COPIER_SIMPLE)
{
VPTR(pair) = vptr;
VLEN(pair) = vlen;
@ -289,16 +292,6 @@ void ase_map_setmmgr (map_t* map, mmgr_t* mmgr)
map->mmgr = mmgr;
}
size_t ase_map_getsize (map_t* map)
{
return map->size;
}
size_t ase_map_getcapa (map_t* map)
{
return map->capa;
}
int ase_map_getscale (map_t* map, ase_map_id_t id)
{
ASE_ASSERTX (id == ASE_MAP_KEY || id == ASE_MAP_VAL,
@ -390,6 +383,16 @@ void ase_map_setsizer (map_t* map, sizer_t sizer)
map->sizer = sizer;
}
size_t ase_map_getsize (map_t* map)
{
return map->size;
}
size_t ase_map_getcapa (map_t* map)
{
return map->capa;
}
pair_t* ase_map_search (map_t* map, const void* kptr, size_t klen)
{
pair_t* pair;
@ -411,7 +414,6 @@ pair_t* ase_map_search (map_t* map, const void* kptr, size_t klen)
return ASE_NULL;
}
int ase_map_put (
map_t* map, void* kptr, size_t klen,
void* vptr, size_t vlen, pair_t** px)
@ -729,6 +731,11 @@ static int reorganize (map_t* map)
return 0;
}
void* ase_map_copysimple (map_t* map, void* dptr, size_t dlen)
{
return dptr;
}
void* ase_map_copyinline (map_t* map, void* dptr, size_t dlen)
{
/* this is a dummy copier */

View File

@ -24,6 +24,7 @@
#define TOB(sll,len) ((len)*(sll)->scale)
#define SIZEOF(x) ASE_SIZEOF(x)
#define size_t ase_size_t
#define mmgr_t ase_mmgr_t
@ -36,6 +37,44 @@ static int comp_data (sll_t* sll,
return 1;
}
static node_t* alloc_node (sll_t* sll, void* dptr, size_t dlen)
{
node_t* n;
if (sll->copier == ASE_NULL ||
sll->copier == ASE_SLL_COPIER_SIMPLE)
{
n = ASE_MMGR_ALLOC (sll->mmgr, SIZEOF(node_t));
if (n == ASE_NULL) return ASE_NULL;
DPTR(n) = dptr;
}
else if (sll->copier == ASE_SLL_COPIER_INLINE)
{
n = ASE_MMGR_ALLOC (sll->mmgr,
SIZEOF(node_t) + TOB(sll,dlen));
if (n == ASE_NULL) return ASE_NULL;
ASE_MEMCPY (n + 1, dptr, TOB(sll,dlen));
DPTR(n) = n + 1;
}
else
{
n = ASE_MMGR_ALLOC (sll->mmgr, SIZEOF(node_t));
if (n == ASE_NULL) return ASE_NULL;
DPTR(n) = sll->copier (sll, dptr, dlen);
if (DPTR(n) == ASE_NULL)
{
ASE_MMGR_FREE (sll->mmgr, n);
return ASE_NULL;
}
}
DLEN(n) = dlen;
NEXT(n) = ASE_NULL;
return n;
}
sll_t* ase_sll_open (mmgr_t* mmgr, size_t ext)
{
sll_t* sll;
@ -50,7 +89,7 @@ sll_t* ase_sll_open (mmgr_t* mmgr, size_t ext)
if (mmgr == ASE_NULL) return ASE_NULL;
}
sll = ASE_MMGR_ALLOC (mmgr, ASE_SIZEOF(sll_t) + ext);
sll = ASE_MMGR_ALLOC (mmgr, SIZEOF(sll_t) + ext);
if (sll == ASE_NULL) return ASE_NULL;
return ase_sll_init (sll, mmgr);
@ -65,7 +104,7 @@ void ase_sll_close (sll_t* sll)
sll_t* ase_sll_init (sll_t* sll, mmgr_t* mmgr)
{
/* do not zero out the extension */
ASE_MEMSET (sll, 0, ASE_SIZEOF(*sll));
ASE_MEMSET (sll, 0, SIZEOF(*sll));
sll->mmgr = mmgr;
sll->size = 0;
@ -95,21 +134,6 @@ void ase_sll_setmmgr (sll_t* sll, mmgr_t* mmgr)
sll->mmgr = mmgr;
}
size_t ase_sll_getsize (sll_t* sll)
{
return SIZE(sll);
}
node_t* ase_sll_gethead (sll_t* sll)
{
return HEAD(sll);
}
node_t* ase_sll_gettail (sll_t* sll)
{
return TAIL(sll);
}
int ase_sll_getscale (sll_t* sll)
{
return sll->scale;
@ -157,41 +181,19 @@ void ase_sll_setcomper (sll_t* sll, comper_t comper)
sll->comper = comper;
}
static node_t* alloc_node (sll_t* sll, void* dptr, size_t dlen)
size_t ase_sll_getsize (sll_t* sll)
{
node_t* n;
if (sll->copier == ASE_NULL)
{
n = ASE_MMGR_ALLOC (sll->mmgr, ASE_SIZEOF(node_t));
if (n == ASE_NULL) return ASE_NULL;
DPTR(n) = dptr;
}
else if (sll->copier == ASE_SLL_COPIER_INLINE)
{
n = ASE_MMGR_ALLOC (sll->mmgr,
ASE_SIZEOF(node_t) + TOB(sll,dlen));
if (n == ASE_NULL) return ASE_NULL;
ASE_MEMCPY (n + 1, dptr, TOB(sll,dlen));
DPTR(n) = n + 1;
}
else
{
n = ASE_MMGR_ALLOC (sll->mmgr, ASE_SIZEOF(node_t));
if (n == ASE_NULL) return ASE_NULL;
DPTR(n) = sll->copier (sll, dptr, dlen);
if (DPTR(n) == ASE_NULL)
{
ASE_MMGR_FREE (sll->mmgr, n);
return ASE_NULL;
}
return SIZE(sll);
}
DLEN(n) = dlen;
NEXT(n) = ASE_NULL;
node_t* ase_sll_gethead (sll_t* sll)
{
return HEAD(sll);
}
return n;
node_t* ase_sll_gettail (sll_t* sll)
{
return TAIL(sll);
}
node_t* ase_sll_search (sll_t* sll, node_t* pos, const void* dptr, size_t dlen)
@ -320,6 +322,11 @@ void ase_sll_walk (sll_t* sll, walker_t walker, void* arg)
}
}
void* ase_sll_copysimple (sll_t* sll, void* dptr, size_t dlen)
{
return dptr;
}
void* ase_sll_copyinline (sll_t* sll, void* dptr, size_t dlen)
{
/* this is a dummy copier */