From ba30f5cf12a56ab49e45cb71d60ba35e473c908d Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 10 Oct 2008 22:04:22 +0000 Subject: [PATCH] fixed bugs in ase_lda_t --- ase/include/ase/cmn/lda.h | 14 +++++++++++++ ase/lib/cmn/lda.c | 43 ++++++++++++++++++++------------------- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/ase/include/ase/cmn/lda.h b/ase/include/ase/cmn/lda.h index 9e56ea7b..3ae0cb56 100644 --- a/ase/include/ase/cmn/lda.h +++ b/ase/include/ase/cmn/lda.h @@ -398,11 +398,25 @@ ase_size_t ase_lda_update ( ase_size_t dlen ); +/****f* ase.cmn.lda/ase_lda_delete + * NAME + * ase_lda_delete - delete data + * + * DESCRIPTION + * The ase_lda_delete() function deletes the as many data as the count + * from the index. + * + * RETURN + * The ase_lda_delete() function returns the number of data deleted. + * + * SYNOPSIS + */ ase_size_t ase_lda_delete ( ase_lda_t* lda, ase_size_t index, ase_size_t count ); +/******/ ase_size_t ase_lda_add ( ase_lda_t* lda, ase_char_t* str, ase_size_t len); diff --git a/ase/lib/cmn/lda.c b/ase/lib/cmn/lda.c index 4bf79165..726c1fcf 100644 --- a/ase/lib/cmn/lda.c +++ b/ase/lib/cmn/lda.c @@ -229,14 +229,12 @@ lda_t* ase_lda_setcapa (lda_t* lda, size_t capa) { if (lda->mmgr->realloc != ASE_NULL && lda->node != ASE_NULL) { -wprintf (L"XXXXXXXXXXXXXXXXXX %d, %d\n", (int)capa, (int)ASE_SIZEOF(*lda->node)*capa); tmp = (ase_lda_node_t**)ASE_MMGR_REALLOC ( lda->mmgr, lda->node, ASE_SIZEOF(*lda->node)*capa); if (tmp == ASE_NULL) return ASE_NULL; } else { -wprintf (L"XXXXXXXXXXXXXXXXXX %d, %d\n", (int)capa, (int)ASE_SIZEOF(*lda->node)*capa); tmp = (ase_lda_node_t**) ASE_MMGR_ALLOC ( lda->mmgr, ASE_SIZEOF(*lda->node)*capa); if (tmp == ASE_NULL) return ASE_NULL; @@ -359,6 +357,7 @@ size_t ase_lda_insert (lda_t* lda, size_t pos, void* dptr, size_t dlen) { if (lda->freeer) lda->freeer (lda, DPTR(node), DLEN(node)); + ASE_MMGR_FREE (lda->mmgr, node); return INVALID; } } @@ -368,6 +367,7 @@ size_t ase_lda_insert (lda_t* lda, size_t pos, void* dptr, size_t dlen) /* the buffer is not still enough after resizing */ if (lda->freeer) lda->freeer (lda, DPTR(node), DLEN(node)); + ASE_MMGR_FREE (lda->mmgr, node); return INVALID; } @@ -425,35 +425,33 @@ size_t ase_lda_update (lda_t* lda, size_t pos, void* dptr, size_t dlen) size_t ase_lda_delete (lda_t* lda, size_t index, size_t count) { - size_t i, j, k; + size_t i; if (index >= lda->size) return 0; if (count > lda->size - index) count = lda->size - index; i = index; - j = index + count; - k = index + count; - while (i < k) + for (i = index; i < index + count; i++) { node_t* c = lda->node[i]; - if (lda->freeer != ASE_NULL) - lda->freeer (lda, DPTR(c), DLEN(c)); - ASE_MMGR_FREE (lda->mmgr, c); + if (c != ASE_NULL) + { + if (lda->freeer != ASE_NULL) + lda->freeer (lda, DPTR(c), DLEN(c)); + ASE_MMGR_FREE (lda->mmgr, c); - if (j >= lda->size) - { lda->node[i] = ASE_NULL; - i++; - } - else - { - lda->node[i] = lda->node[j]; - i++; j++; } } + for (i = index + count; i < lda->size; i++) + { + lda->node[i-count] = lda->node[i]; + } + lda->node[lda->size-1] = ASE_NULL; + lda->size -= count; return count; } @@ -465,10 +463,13 @@ void ase_lda_clear (lda_t* lda) for (i = 0; i < lda->size; i++) { node_t* c = lda->node[i]; - if (c && lda->freeer) - lda->freeer (lda, DPTR(c), DLEN(c)); - ASE_MMGR_FREE (lda->mmgr, c); - lda->node[i] = ASE_NULL; + if (c != ASE_NULL) + { + if (lda->freeer) + lda->freeer (lda, DPTR(c), DLEN(c)); + ASE_MMGR_FREE (lda->mmgr, c); + lda->node[i] = ASE_NULL; + } } lda->size = 0;