fixed bugs in ase_lda_t

This commit is contained in:
hyung-hwan 2008-10-10 22:04:22 +00:00
parent b2d1b51302
commit ba30f5cf12
2 changed files with 36 additions and 21 deletions

View File

@ -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);

View File

@ -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;