Changeset 151 in libcf for trunk/src/cf_list.c
- Timestamp:
- 10/31/13 10:17:24 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/cf_list.c
r149 r151 24 24 return CF_ERROR_DS_INVALID_ARGS 25 25 26 /** 리스트 노드 ( CF_Traverser의 구현) */26 /** 리스트 노드 (cf_traverser의 구현) */ 27 27 typedef struct __cf_node__ 28 28 { … … 32 32 } CF_NODE; 33 33 34 /** 리스트 컨텍스트 ( CF_List_Ctx의 구현) */34 /** 리스트 컨텍스트 (cf_ctx의 구현) */ 35 35 typedef struct __cf_list__ 36 36 { … … 48 48 */ 49 49 int 50 CF_List_Create Ctx (CF_List_Ctx * ctx)50 CF_List_Create (cf_ctx * ctx) 51 51 { 52 52 CF_LIST_CONTEXT * context = NULL; 53 53 54 ASSERT_ ARGS (ctx == NULL);55 56 context = (CF_LIST_CONTEXT *) calloc (sizeof (CF_LIST_CONTEXT), 1);54 ASSERT_CTX (ctx); 55 56 context = NEWCTX (CF_LIST_CONTEXT); 57 57 if (context == NULL) 58 58 return CF_ERROR_DS_CREATE_CTX; 59 59 60 *ctx = ( CF_List_Ctx) context;60 *ctx = (cf_ctx) context; 61 61 62 62 return CF_OK; … … 71 71 */ 72 72 int 73 CF_List_Destroy Ctx (CF_List_Ctx ctx)73 CF_List_Destroy (cf_ctx ctx) 74 74 { 75 75 CF_LIST_CONTEXT * context = (CF_LIST_CONTEXT *) ctx; … … 85 85 86 86 /** 87 * 리스트 탐색자( Traverser)를 Front 위치로 설정87 * 리스트 탐색자(traverser)를 Front 위치로 설정 88 88 * 89 89 * \return 성공 시, CF_OK; 실패 시, 오류 코드 … … 93 93 */ 94 94 int 95 CF_List_Front ( CF_List_Ctxctx,96 CF_Traverser * traverser)95 CF_List_Front (cf_ctx ctx, 96 cf_traverser * traverser) 97 97 { 98 98 CF_LIST_CONTEXT * context = (CF_LIST_CONTEXT *) ctx; … … 101 101 ASSERT_TRAVERSER (traverser); 102 102 103 *traverser = ( CF_Traverser *) context->front;104 105 return CF_OK; 106 } 107 108 /** 109 * 리스트 탐색자( Traverser)를 Rear 위치로 설정103 *traverser = (cf_traverser *) context->front; 104 105 return CF_OK; 106 } 107 108 /** 109 * 리스트 탐색자(traverser)를 Rear 위치로 설정 110 110 * 111 111 * \return 성공 시, CF_OK; 실패 시, 오류 코드 … … 115 115 */ 116 116 int 117 CF_List_Rear ( CF_List_Ctxctx,118 CF_Traverser * traverser)117 CF_List_Rear (cf_ctx ctx, 118 cf_traverser * traverser) 119 119 { 120 120 CF_LIST_CONTEXT * context = (CF_LIST_CONTEXT *) ctx; … … 123 123 ASSERT_TRAVERSER (traverser); 124 124 125 *traverser = (CF_Traverser *) context->rear; 126 127 return CF_OK; 128 } 129 130 /** 131 * 리스트에 새 데이터 삽입 125 *traverser = (cf_traverser *) context->rear; 126 127 return CF_OK; 128 } 129 130 /** 131 * 리스트 처음에 새 데이터 삽입 132 * 133 * \return 성공 시, CF_OK; 실패 시, 오류 코드 134 * 135 * \param ctx 리스트 컨텍스트 136 * \param element 삽입할 데이터 주소 137 */ 138 int 139 CF_List_AddFront (cf_ctx ctx, 140 const void * element) 141 { 142 int result = 0; 143 cf_traverser trav = NULL; 144 145 ASSERT_CTX (ctx); 146 147 result = CF_List_Front (ctx, &trav); 148 if (result < 0) 149 return result; 150 151 return CF_List_InsertBefore (ctx, trav, element); 152 } 153 154 /** 155 * 리스트 끝에 새 데이터 삽입 156 * 157 * \return 성공 시, CF_OK; 실패 시, 오류 코드 158 * 159 * \param ctx 리스트 컨텍스트 160 * \param element 삽입할 데이터 주소 161 */ 162 int 163 CF_List_AddRear (cf_ctx ctx, 164 const void * element) 165 { 166 int result = 0; 167 cf_traverser trav = NULL; 168 169 ASSERT_CTX (ctx); 170 171 result = CF_List_Rear (ctx, &trav); 172 if (result < 0) 173 return result; 174 175 return CF_List_InsertAfter (ctx, trav, element); 176 } 177 178 /** 179 * 리스트 탐색자(traverser)의 앞에 새 데이터 삽입 132 180 * 133 181 * \return 성공 시, CF_OK; 실패 시, 오류 코드 … … 135 183 * \param ctx 리스트 컨텍스트 136 184 * \param traverser 리스트 탐색자 137 * \param direction 탐색자의 전/후를 지정138 185 * \param element 삽입할 데이터 주소 139 * 140 * \remarks 141 * traverser가 NULL일 때, 142 * direction이 CF_DIRECTION_BEFORE라면 Front 위치이고 143 * direction이 CF_DIRECTION_AFTER라면 Rear 위치에 삽입 144 */ 145 int 146 CF_List_Insert (CF_List_Ctx ctx, 147 const CF_Traverser traverser, 148 const CF_DIRECTION direction, 149 const void * element) 186 */ 187 int 188 CF_List_InsertBefore (cf_ctx ctx, 189 const cf_traverser traverser, 190 const void * element) 150 191 { 151 192 CF_LIST_CONTEXT * context = (CF_LIST_CONTEXT *) ctx; 152 CF_NODE * node = NULL;153 CF_NODE * newnode = NULL;154 155 ASSERT_CTX (ctx); 156 157 newnode = (CF_NODE *) calloc (sizeof (CF_NODE), 1);193 CF_NODE * node = NULL; 194 CF_NODE * newnode = NULL; 195 196 ASSERT_CTX (ctx); 197 198 newnode = NEWCTX (CF_NODE); 158 199 if (newnode == NULL) 159 200 return CF_ERROR_DS_CREATE_NODE; … … 169 210 } 170 211 171 if (direction == CF_DIRECTION_BEFORE) 212 node = traverser ? (CF_NODE *) traverser : context->front; 213 214 newnode->next = node; 215 if (node) 172 216 { 173 node = traverser ? (CF_NODE *) traverser : context->front; 174 175 newnode->next = node; 176 if (node) 177 { 178 newnode->prev = node->prev; 179 node->prev = newnode; 180 if (newnode->prev) 181 newnode->prev->next = newnode; 182 } 183 184 if (node == context->front) 185 context->front = newnode; 217 newnode->prev = node->prev; 218 node->prev = newnode; 219 if (newnode->prev) 220 newnode->prev->next = newnode; 186 221 } 187 else /* if (direction == CF_DIRECTION_AFTER) */ 222 223 if (node == context->front) 224 context->front = newnode; 225 } NO_CATCH; 226 227 context->size++; 228 229 return CF_OK; 230 } 231 232 /** 233 * 리스트 탐색자(traverser)의 뒤에 새 데이터 삽입 234 * 235 * \return 성공 시, CF_OK; 실패 시, 오류 코드 236 * 237 * \param ctx 리스트 컨텍스트 238 * \param traverser 리스트 탐색자 239 * \param element 삽입할 데이터 주소 240 */ 241 int 242 CF_List_InsertAfter (cf_ctx ctx, 243 const cf_traverser traverser, 244 const void * element) 245 { 246 CF_LIST_CONTEXT * context = (CF_LIST_CONTEXT *) ctx; 247 CF_NODE * node = NULL; 248 CF_NODE * newnode = NULL; 249 250 ASSERT_CTX (ctx); 251 252 newnode = NEWCTX (CF_NODE); 253 if (newnode == NULL) 254 return CF_ERROR_DS_CREATE_NODE; 255 256 newnode->element = (void *) element; 257 258 TRY 259 { 260 if (CF_List_GetSize (ctx) == 0) 188 261 { 189 node = traverser ? (CF_NODE *) traverser : context->rear; 190 191 newnode->prev = node; 192 if (node) 193 { 194 newnode->next = node->next; 195 node->next = newnode; 196 if (newnode->next) 197 newnode->next->prev = newnode; 198 } 199 200 if (node == context->rear) 201 context->rear = newnode; 262 context->front = context->rear = newnode; 263 TRY_BREAK; 202 264 } 265 266 node = traverser ? (CF_NODE *) traverser : context->rear; 267 268 newnode->prev = node; 269 if (node) 270 { 271 newnode->next = node->next; 272 node->next = newnode; 273 if (newnode->next) 274 newnode->next->prev = newnode; 275 } 276 277 if (node == context->rear) 278 context->rear = newnode; 203 279 } NO_CATCH; 204 280 … … 209 285 210 286 /** 287 * 리스트 탐색자(traverser)의 자리에 새 데이터 삽입 288 * 289 * \return 성공 시, CF_OK; 실패 시, 오류 코드 290 * 291 * \param traverser 리스트 탐색자 292 * \param element 할당할 데이터 주소 293 */ 294 int 295 CF_List_Set (const cf_traverser traverser, 296 const void * element) 297 { 298 CF_NODE * node = (CF_NODE *) traverser; 299 300 ASSERT_TRAVERSER (traverser); 301 302 node->element = (void *) element; 303 304 return CF_OK; 305 } 306 307 /** 308 * 탐색자 위치의 데이터를 가져옴 309 * 310 * \return 성공 시, CF_OK; 실패 시, 오류 코드 311 * 312 * \param traverser 리스트 탐색자 313 * \param element 데이터 주소 314 */ 315 int 316 CF_List_Get (const cf_traverser traverser, 317 void ** element) 318 { 319 CF_NODE * node = (CF_NODE *) traverser; 320 321 ASSERT_TRAVERSER (traverser); 322 ASSERT_ARGS (element == NULL); 323 324 *element = node->element; 325 326 return CF_OK; 327 } 328 329 /** 211 330 * 리스트에서 탐색자 위치의 항목을 삭제 212 331 * … … 217 336 */ 218 337 int 219 CF_List_Remove ( CF_List_Ctxctx,220 CF_Traverser * traverser)338 CF_List_Remove (cf_ctx ctx, 339 cf_traverser * traverser) 221 340 { 222 341 CF_LIST_CONTEXT * context = (CF_LIST_CONTEXT *) ctx; … … 263 382 */ 264 383 int 265 CF_List_RemoveAll ( CF_List_Ctx ctx)266 { 267 CF_Traverser traverser = NULL;384 CF_List_RemoveAll (cf_ctx ctx) 385 { 386 cf_traverser traverser = NULL; 268 387 269 388 ASSERT_CTX (ctx); … … 279 398 280 399 /** 281 * 탐색자 위치의 데이터를 가져옴282 *283 * \return 성공 시, CF_OK; 실패 시, 오류 코드284 *285 * \param traverser 리스트 탐색자286 * \param element 데이터 주소287 */288 int289 CF_List_GetElement (const CF_Traverser traverser,290 void ** element)291 {292 CF_NODE * node = (CF_NODE *) traverser;293 294 ASSERT_TRAVERSER (traverser);295 ASSERT_ARGS (element == NULL);296 297 *element = node->element;298 299 return CF_OK;300 }301 302 /**303 400 * 탐색자 위치를 이전으로 이동 304 401 * … … 308 405 */ 309 406 int 310 CF_List_Prev ( CF_Traverser * traverser)407 CF_List_Prev (cf_traverser * traverser) 311 408 { 312 409 CF_NODE * node = (CF_NODE *) *traverser; … … 316 413 317 414 node = node->prev; 318 *traverser = ( CF_Traverser *) node;415 *traverser = (cf_traverser *) node; 319 416 if (node == NULL) 320 417 return CF_ERROR_DS_NO_MORE; … … 331 428 */ 332 429 int 333 CF_List_Next ( CF_Traverser * traverser)430 CF_List_Next (cf_traverser * traverser) 334 431 { 335 432 CF_NODE * node = (CF_NODE *) *traverser; … … 339 436 340 437 node = node->next; 341 *traverser = ( CF_Traverser *) node;438 *traverser = (cf_traverser *) node; 342 439 if (node == NULL) 343 440 return CF_ERROR_DS_NO_MORE; … … 354 451 */ 355 452 int 356 CF_List_GetSize ( CF_List_Ctx ctx)453 CF_List_GetSize (cf_ctx ctx) 357 454 { 358 455 CF_LIST_CONTEXT * context = (CF_LIST_CONTEXT *) ctx;
Note:
See TracChangeset
for help on using the changeset viewer.