1
1

Minor cleanups in list implementation:

- Reconcile lam_list_item base class string debugging name
- Use NULL instead of 0
- Ensure to decrement list length in remove_first()
- Protect function prototypes from C++ munging
- Add lam_list_get_begin() to be symmetrical with lam_list_get_end()

This commit was SVN r497.
Этот коммит содержится в:
Jeff Squyres 2004-01-20 23:19:11 +00:00
родитель 095ac4525e
Коммит b9c2371df6
2 изменённых файлов: 68 добавлений и 41 удалений

Просмотреть файл

@ -9,7 +9,7 @@
*/
lam_class_info_t lam_list_item_cls = {"lam_list_link_item_t", &lam_object_cls,
lam_class_info_t lam_list_item_cls = {"lam_list_item_t", &lam_object_cls,
(class_init_t) lam_list_item_init, (class_destroy_t)lam_obj_destroy};
lam_class_info_t lam_list_cls = {"lam_list_t", &lam_object_cls,
(class_init_t)lam_list_init, (class_destroy_t)lam_list_destroy};
@ -24,7 +24,7 @@ lam_class_info_t lam_list_cls = {"lam_list_t", &lam_object_cls,
void lam_list_item_init(lam_list_item_t *item)
{
SUPER_INIT(item, lam_list_item_cls.cls_parent);
item->lam_list_next = item->lam_list_prev = 0;
item->lam_list_next = item->lam_list_prev = NULL;
item->lam_list_type = 0;
}
@ -38,14 +38,15 @@ void lam_list_item_init(lam_list_item_t *item)
void lam_list_init(lam_list_t *list)
{
SUPER_INIT(list, lam_list_cls.cls_parent);
list->lam_list_head.lam_list_next=&(list->lam_list_tail);
list->lam_list_head.lam_list_prev=(lam_list_item_t *)NULL;
list->lam_list_tail.lam_list_prev=(lam_list_item_t *)NULL;
list->lam_list_tail.lam_list_prev=&(list->lam_list_head);
list->lam_list_head.lam_list_prev = NULL;
list->lam_list_head.lam_list_next = &list->lam_list_tail;
list->lam_list_tail.lam_list_prev = &list->lam_list_head;
list->lam_list_tail.lam_list_next = NULL;
list->lam_list_type = 0;
list->lam_list_length = 0;
}
void lam_list_destroy(lam_list_t *list)
{
/* release all items in list */
@ -53,7 +54,6 @@ void lam_list_destroy(lam_list_t *list)
SUPER_DESTROY(list, lam_list_cls.cls_parent);
}
/**
* Adds item to the end of the list.
@ -65,7 +65,6 @@ void lam_list_destroy(lam_list_t *list)
*/
void lam_list_append(lam_list_t *list, lam_list_item_t *item)
{
/* set new element's previous pointer */
item->lam_list_prev=list->lam_list_tail.lam_list_prev;
@ -148,6 +147,9 @@ lam_list_item_t *lam_list_remove_first(lam_list_t *list)
if ( 0 == list->lam_list_length )
return (lam_list_item_t *)NULL;
/* reset list length counter */
list->lam_list_length--;
/* get pointer to first element on the list */
item = list->lam_list_head.lam_list_next;

Просмотреть файл

@ -34,8 +34,14 @@ typedef struct lam_list_item
struct lam_list_item *lam_list_prev;
} lam_list_item_t;
void lam_list_item_init(lam_list_item_t *item);
void lam_list_item_destroy(lam_list_item_t *item);
#if defined(c_plusplus) || defined(__cplusplus)
extern "C" {
#endif
void lam_list_item_init(lam_list_item_t *item);
void lam_list_item_destroy(lam_list_item_t *item);
#if defined(c_plusplus) || defined(__cplusplus)
}
#endif
#define lam_list_get_next(item) \
((item) ? (((lam_list_item_t*)(item))->lam_list_next) : 0)
@ -54,13 +60,19 @@ typedef struct lam_list
lam_object_t super;
lam_list_item_t lam_list_head;
lam_list_item_t lam_list_tail;
lam_list_type_t lam_list_type;
lam_list_type_t lam_list_type;
volatile size_t lam_list_length;
} lam_list_t;
void lam_list_init(lam_list_t *list);
void lam_list_destroy(lam_list_t *list);
#if defined(c_plusplus) || defined(__cplusplus)
extern "C" {
#endif
void lam_list_init(lam_list_t *list);
void lam_list_destroy(lam_list_t *list);
#if defined(c_plusplus) || defined(__cplusplus)
}
#endif
/*
* Inlined accessor functions
@ -102,6 +114,14 @@ static inline lam_list_item_t* lam_list_get_last(lam_list_t* list)
return list->lam_list_tail.lam_list_prev;
}
/*
* Returns beginning of list, an invalid list entry.
*/
static inline lam_list_item_t* lam_list_get_begin(lam_list_t* list)
{
return &(list->lam_list_head);
}
/*
* Returns end of list, an invalid list entry.
*/
@ -152,42 +172,47 @@ static inline lam_list_item_t *lam_list_remove_item
return item->lam_list_prev;
}
/*
* Adds item to the end of the list but does not retain item.
*/
void lam_list_append(lam_list_t *list, lam_list_item_t *item);
#if defined(c_plusplus) || defined(__cplusplus)
extern "C" {
#endif
/*
* Adds item to the end of the list but does not retain item.
*/
void lam_list_append(lam_list_t *list, lam_list_item_t *item);
/*
* Remove item from the list.
*/
lam_list_item_t* lam_list_remove(lam_list_t *list, lam_list_item_t *item);
/*
* Remove item from the list.
*/
lam_list_item_t* lam_list_remove(lam_list_t *list, lam_list_item_t *item);
/* Adds item to list at index and retains item.
Returns 1 if successful, 0 otherwise.
0 <= idx < length_m
Example: if idx = 2 and list = item1->item2->item3->item4, then
after insert, list = item1->item2->item->item3->item4
*/
int lam_list_insert(lam_list_t *list, lam_list_item_t *item, long long idx);
/* Adds item to list at index and retains item.
Returns 1 if successful, 0 otherwise.
0 <= idx < length_m
Example: if idx = 2 and list = item1->item2->item3->item4, then
after insert, list = item1->item2->item->item3->item4
*/
int lam_list_insert(lam_list_t *list, lam_list_item_t *item, long long idx);
/*
* Adds item to the front of the list and retains item.
*/
void lam_list_prepend(lam_list_t *list, lam_list_item_t *item);
/*
* Adds item to the front of the list and retains item.
*/
void lam_list_prepend(lam_list_t *list, lam_list_item_t *item);
/*
* Removes and returns first item on list.
*/
lam_list_item_t *lam_list_remove_first(lam_list_t *list);
/*
* Removes and returns first item on list.
*/
lam_list_item_t *lam_list_remove_first(lam_list_t *list);
/*
* Removes and returns last item on list.
*/
lam_list_item_t *lam_list_remove_last(lam_list_t *list);
/*
* Removes and returns last item on list.
*/
lam_list_item_t *lam_list_remove_last(lam_list_t *list);
#if defined(c_plusplus) || defined(__cplusplus)
}
#endif
#endif /* LAM_LIST_H */