1 /* ****************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
25 * @todo Do performance comparision with array list.
43 typedef struct linked_list_data u_linklist_data_t;
45 typedef struct linked_list_data u_linklist_iterator_t;
47 typedef struct u_linklist
49 u_linklist_data_t *list;
53 struct linked_list_data
56 u_linklist_data_t *next;
60 * API to create link list and initializes the elements.
61 * @return u_linklist_t if Success, NULL otherwise.
63 u_linklist_t *u_linklist_create();
66 * Resets and deletes the link list
67 * Linklist elements are deleted, Calling function must take care of freeing
68 * dynamic memory allocated before freeing the linklist.
69 * @param[in,out] list u_linklist pointer.
70 * @return ::CA_STATUS_OK if Success, ::CA_STATUS_INVALID_PARAM if pointer to list is NULL.
72 CAResult_t u_linklist_free(u_linklist_t **list);
75 * Add data to the head of the link list.
76 * @param[in/out] list pointer of link list.
77 * @param[in] data pointer of data.
78 * @return ::CA_STATUS_OK if Success, ::CA_MEMORY_ALLOC_FAILED if memory allocation fails.
80 CAResult_t u_linklist_add_head(u_linklist_t *list, void *data);
83 * Add data to the tail of the link list.
84 * @param[in/out] list pointer of link list.
85 * @param[in] data pointer of data.
86 * @return ::CA_STATUS_OK if Success, ::CA_MEMORY_ALLOC_FAILED if memory allocation fails.
88 CAResult_t u_linklist_add(u_linklist_t *list, void *data);
92 * This api deletes node pointed by iterator.
93 * Advances iterator to next node in the list.
94 * @param[in/out] list pointer of link list.
95 * @param[in/out] iter pointer of iterator pointing to previous node.
96 * @return ::CA_STATUS_OK if Success, ::CA_STATUS_INVALID_PARAM if iterator is NULL.
98 CAResult_t u_linklist_remove(u_linklist_t *list, u_linklist_iterator_t **iter);
102 * Returns the length of the link list.
103 * @param[in] list pointer of link list.
104 * @return length of the link list.
106 uint32_t u_linklist_length(const u_linklist_t *list);
109 * Initializes the iterator, need to be called before calling u_linklist_get_next.
110 * @param[in] list pointer of link list.
111 * @param[in,out] iter iterator of link list.
114 void u_linklist_init_iterator(const u_linklist_t *list, u_linklist_iterator_t **iter);
117 * Returns the data of the node iterator points to from the link list.
118 * @param[in] iter iterator of link list.
119 * @return the data of node to which iterator is pointing.
121 void *u_linklist_get_data(const u_linklist_iterator_t *iter);
124 * Returns the data of the next node iterator points to from the link list
125 * Advances iterator to next node in the list.
126 * @param[in,out] iter iterator of link list.
127 * @return the data of next node.
129 void *u_linklist_get_next(u_linklist_iterator_t **iter);
135 #endif /* U_LINKLIST_H_ */