added ase_sll_search()
This commit is contained in:
parent
275c6fb8ec
commit
fda36606e8
@ -110,14 +110,19 @@ struct ase_sll_node_t
|
|||||||
|
|
||||||
#define ASE_SLL_COPIER_INLINE ase_sll_copyinline
|
#define ASE_SLL_COPIER_INLINE ase_sll_copyinline
|
||||||
|
|
||||||
#define ASE_SLL_HEAD(sll) ((sll)->head)
|
#define ASE_SLL_MMGR(sll) ((sll)->mmgr)
|
||||||
#define ASE_SLL_TAIL(sll) ((sll)->tail)
|
#define ASE_SLL_COPIER(sll) ((sll)->copier)
|
||||||
#define ASE_SLL_SIZE(sll) ((sll)->size)
|
#define ASE_SLL_FREEER(sll) ((sll)->freeer)
|
||||||
#define ASE_SLL_SCALE(sll) ((sll)->scale)
|
#define ASE_SLL_COMPER(sll) ((sll)->comper)
|
||||||
|
|
||||||
#define ASE_SLL_DPTR(n) ((n)->dptr)
|
#define ASE_SLL_HEAD(sll) ((sll)->head)
|
||||||
#define ASE_SLL_DLEN(n) ((n)->dlen)
|
#define ASE_SLL_TAIL(sll) ((sll)->tail)
|
||||||
#define ASE_SLL_NEXT(n) ((n)->next)
|
#define ASE_SLL_SIZE(sll) ((sll)->size)
|
||||||
|
#define ASE_SLL_SCALE(sll) ((sll)->scale)
|
||||||
|
|
||||||
|
#define ASE_SLL_DPTR(node) ((node)->dptr)
|
||||||
|
#define ASE_SLL_DLEN(node) ((node)->dlen)
|
||||||
|
#define ASE_SLL_NEXT(node) ((node)->next)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -173,16 +178,22 @@ ase_sll_t* ase_sll_init (
|
|||||||
);
|
);
|
||||||
|
|
||||||
void ase_sll_fini (
|
void ase_sll_fini (
|
||||||
ase_sll_t* sll /* a singly linked list */
|
ase_sll_t* sll /* a singly linked list */
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
/****f* ase.cmn.sll/ase_sll_getextension
|
||||||
* NAME: Gets the pointer to the extension area
|
* NAME
|
||||||
* RETURN:: the pointer to the extension area
|
* ase_sll_getextension - get the pointer to the extension
|
||||||
|
*
|
||||||
|
* DESCRIPTION
|
||||||
|
* The ase_sll_getextension() function returns the pointer to the extension.
|
||||||
|
*
|
||||||
|
* SYNOPSIS
|
||||||
*/
|
*/
|
||||||
void* ase_sll_getextension (
|
void* ase_sll_getextension (
|
||||||
ase_sll_t* sll /* a singly linked list */
|
ase_sll_t* sll /* a singly linked list */
|
||||||
);
|
);
|
||||||
|
/******/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NAME: get the pointer to the memory manager in use
|
* NAME: get the pointer to the memory manager in use
|
||||||
@ -303,20 +314,31 @@ ase_sll_node_t* ase_sll_gettail (
|
|||||||
* ase_sll_search - find a node
|
* ase_sll_search - find a node
|
||||||
*
|
*
|
||||||
* DESCRIPTION
|
* DESCRIPTION
|
||||||
* The ase_sll_search() function traverses the list to find a node containing
|
* The ase_sll_search() function traverses a list to find a node containing
|
||||||
* the same value as the the data pointer and length.
|
* the same value as the the data pointer and length. The traversal begins
|
||||||
|
* from the next node of the positional node. If the positional node is
|
||||||
|
* ASE_NULL, the traversal begins from the head node.
|
||||||
|
*
|
||||||
|
* RETURN
|
||||||
|
* The pointer to the node found. Otherwise, ASE_NULL.
|
||||||
|
*
|
||||||
|
* NOTES
|
||||||
|
* No reverse search is provided because a reverse traversal can not be
|
||||||
|
* achieved efficiently.
|
||||||
*
|
*
|
||||||
* SYNOPSIS
|
* SYNOPSIS
|
||||||
*/
|
*/
|
||||||
ase_sll_node_t* ase_sll_search (
|
ase_sll_node_t* ase_sll_search (
|
||||||
ase_sll_t* sll /* a singly linked list */,
|
ase_sll_t* sll /* a singly linked list */,
|
||||||
const void* dptr /* a data pointer */,
|
ase_sll_node_t* pos /* a positional node */,
|
||||||
ase_size_t dlen /* a data length */
|
const void* dptr /* a data pointer */,
|
||||||
|
ase_size_t dlen /* a data length */
|
||||||
);
|
);
|
||||||
|
/******/
|
||||||
|
|
||||||
/****f* ase.cmn.sll/ase_sll_insert
|
/****f* ase.cmn.sll/ase_sll_insert
|
||||||
* NAME
|
* NAME
|
||||||
* ase_sll_insert - insert data before a positional node given
|
* ase_sll_insert - insert data to a new node
|
||||||
*
|
*
|
||||||
* DESCRIPTION
|
* DESCRIPTION
|
||||||
* There is performance penalty unless the positional node is neither
|
* There is performance penalty unless the positional node is neither
|
||||||
@ -324,6 +346,9 @@ ase_sll_node_t* ase_sll_search (
|
|||||||
* structure such as a doubly linked list if you need to insert data
|
* structure such as a doubly linked list if you need to insert data
|
||||||
* into a random position.
|
* into a random position.
|
||||||
*
|
*
|
||||||
|
* RETURN
|
||||||
|
* The pointer to a new node on success and ASE_NULL on failure:w
|
||||||
|
*
|
||||||
* SYNOPSIS
|
* SYNOPSIS
|
||||||
*/
|
*/
|
||||||
ase_sll_node_t* ase_sll_insert (
|
ase_sll_node_t* ase_sll_insert (
|
||||||
@ -334,10 +359,20 @@ ase_sll_node_t* ase_sll_insert (
|
|||||||
);
|
);
|
||||||
/******/
|
/******/
|
||||||
|
|
||||||
|
/****f* ase.cmn.sll/ase_sll_delete
|
||||||
|
* NAME
|
||||||
|
* ase_sll_delete - delete a node
|
||||||
|
*
|
||||||
|
* DESCRIPTION
|
||||||
|
* The ase_sll_delete() function deletes a node.
|
||||||
|
*
|
||||||
|
* SYNOPSIS
|
||||||
|
*/
|
||||||
void ase_sll_delete (
|
void ase_sll_delete (
|
||||||
ase_sll_t* sll /* a singly linked list */,
|
ase_sll_t* sll /* a singly linked list */,
|
||||||
ase_sll_node_t* pos /* a node to delete */
|
ase_sll_node_t* pos /* a node to delete */
|
||||||
);
|
);
|
||||||
|
/******/
|
||||||
|
|
||||||
/****f* ase.cmn.sll/ase_sll_clear
|
/****f* ase.cmn.sll/ase_sll_clear
|
||||||
* NAME
|
* NAME
|
||||||
@ -345,7 +380,7 @@ void ase_sll_delete (
|
|||||||
*
|
*
|
||||||
* DESCRIPTION
|
* DESCRIPTION
|
||||||
* The ase_sll_clear() function empties a singly linked list by deletinng
|
* The ase_sll_clear() function empties a singly linked list by deletinng
|
||||||
* all data nodes.
|
* all the nodes.
|
||||||
*
|
*
|
||||||
* SYNOPSIS
|
* SYNOPSIS
|
||||||
*/
|
*/
|
||||||
|
@ -192,6 +192,22 @@ static node_t* alloc_node (sll_t* sll, void* dptr, size_t dlen)
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
node_t* ase_sll_search (sll_t* sll, node_t* pos, const void* dptr, size_t dlen)
|
||||||
|
{
|
||||||
|
pos = (pos == ASE_NULL)? pos = sll->head: NEXT(pos);
|
||||||
|
|
||||||
|
while (pos != ASE_NULL)
|
||||||
|
{
|
||||||
|
if (sll->comper (sll, DPTR(pos), DLEN(pos), dptr, dlen) == 0)
|
||||||
|
{
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
pos = NEXT(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ASE_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
node_t* ase_sll_insert (
|
node_t* ase_sll_insert (
|
||||||
sll_t* sll, node_t* pos, void* dptr, size_t dlen)
|
sll_t* sll, node_t* pos, void* dptr, size_t dlen)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user