[109] | 1 | /**
|
---|
[128] | 2 | * \file cf_queue.c
|
---|
[117] | 3 | *
|
---|
[128] | 4 | * \author myusgun <myusgun@gmail.com>
|
---|
| 5 | *
|
---|
[119] | 6 | * \brief 큐 구현
|
---|
[109] | 7 | */
|
---|
| 8 | #include "cf_queue.h"
|
---|
| 9 | #include "cf_list.h"
|
---|
| 10 | #include "cf_error.h"
|
---|
| 11 |
|
---|
| 12 | #include <stdio.h>
|
---|
| 13 |
|
---|
[111] | 14 | /**
|
---|
| 15 | * 큐 컨텍스트 생성
|
---|
| 16 | *
|
---|
[119] | 17 | * \return 성공 시, CF_OK; 실패 시, 오류 코드
|
---|
[111] | 18 | *
|
---|
[119] | 19 | * \param ctx 큐 컨텍스트 포인터
|
---|
[111] | 20 | */
|
---|
[109] | 21 | int
|
---|
| 22 | CF_Queue_CreateCtx (CF_Queue_Ctx * ctx)
|
---|
| 23 | {
|
---|
| 24 | return CF_List_CreateCtx ((CF_List_Ctx *) ctx);
|
---|
| 25 | }
|
---|
| 26 |
|
---|
[111] | 27 | /**
|
---|
| 28 | * 큐 컨텍스트 해제
|
---|
| 29 | *
|
---|
[119] | 30 | * \return 성공 시, CF_OK; 실패 시, 오류 코드
|
---|
[111] | 31 | *
|
---|
[119] | 32 | * \param ctx 큐 컨텍스트
|
---|
[111] | 33 | */
|
---|
[109] | 34 | int
|
---|
| 35 | CF_Queue_DestroyCtx (CF_Queue_Ctx ctx)
|
---|
| 36 | {
|
---|
| 37 | return CF_List_DestroyCtx (ctx);
|
---|
| 38 | }
|
---|
| 39 |
|
---|
[111] | 40 | /**
|
---|
| 41 | * 큐에 삽입
|
---|
| 42 | *
|
---|
[119] | 43 | * \return 성공 시, CF_OK; 실패 시, 오류 코드
|
---|
[111] | 44 | *
|
---|
[119] | 45 | * \param ctx 큐 컨텍스트
|
---|
| 46 | * \param element 데이터 주소
|
---|
[111] | 47 | */
|
---|
[109] | 48 | int
|
---|
| 49 | CF_Queue_Put (CF_Queue_Ctx ctx,
|
---|
| 50 | const void * element)
|
---|
| 51 | {
|
---|
| 52 | int result = 0;
|
---|
| 53 | CF_List_Ctx list = (CF_List_Ctx) ctx;
|
---|
| 54 | CF_Traverser traverser = NULL;
|
---|
| 55 |
|
---|
| 56 | result = CF_List_Rear (list, &traverser);
|
---|
| 57 | if (result < 0)
|
---|
| 58 | return result;
|
---|
| 59 |
|
---|
| 60 | return CF_List_Insert (list, traverser, CF_DIRECTION_AFTER, element);
|
---|
| 61 | }
|
---|
| 62 |
|
---|
[111] | 63 | /**
|
---|
| 64 | * 큐에서 꺼내기
|
---|
| 65 | *
|
---|
[119] | 66 | * \return 성공 시, CF_OK; 실패 시, 오류 코드
|
---|
[111] | 67 | *
|
---|
[119] | 68 | * \param ctx 큐 컨텍스트
|
---|
| 69 | * \param element 데이터 주소
|
---|
[111] | 70 | */
|
---|
[109] | 71 | int
|
---|
| 72 | CF_Queue_Get (CF_Queue_Ctx ctx,
|
---|
| 73 | void ** element)
|
---|
| 74 | {
|
---|
| 75 | int result = 0;
|
---|
| 76 | CF_List_Ctx list = (CF_List_Ctx) ctx;
|
---|
| 77 | CF_Traverser traverser = NULL;
|
---|
| 78 |
|
---|
| 79 | result = CF_Queue_Front (ctx, element);
|
---|
| 80 | if (result < 0)
|
---|
| 81 | return result;
|
---|
| 82 |
|
---|
| 83 | result = CF_List_Front (list, &traverser);
|
---|
| 84 | if (result < 0)
|
---|
| 85 | return result;
|
---|
| 86 |
|
---|
| 87 | return CF_List_Remove (ctx, &traverser);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
[111] | 90 | /**
|
---|
| 91 | * 큐 처음의 데이터 조회
|
---|
| 92 | *
|
---|
[119] | 93 | * \return 성공 시, CF_OK; 실패 시, 오류 코드
|
---|
[111] | 94 | *
|
---|
[119] | 95 | * \param ctx 큐 컨텍스트
|
---|
| 96 | * \param element 데이터 주소
|
---|
[111] | 97 | */
|
---|
[109] | 98 | int
|
---|
| 99 | CF_Queue_Front (CF_Queue_Ctx ctx,
|
---|
| 100 | void ** element)
|
---|
| 101 | {
|
---|
| 102 | int result = 0;
|
---|
| 103 | CF_List_Ctx list = (CF_List_Ctx) ctx;
|
---|
| 104 | CF_Traverser traverser = NULL;
|
---|
| 105 |
|
---|
| 106 | result = CF_List_Front (list, &traverser);
|
---|
| 107 | if (result < 0)
|
---|
| 108 | return result;
|
---|
| 109 |
|
---|
| 110 | return CF_List_GetElement (traverser, element);
|
---|
| 111 | }
|
---|
| 112 |
|
---|
[111] | 113 | /**
|
---|
| 114 | * 큐에 등록된 항목의 수를 가져옴
|
---|
| 115 | *
|
---|
[119] | 116 | * \return 성공 시, 항목 수; 실패 시, 오류 코드
|
---|
[111] | 117 | *
|
---|
[119] | 118 | * \param ctx 큐 컨텍스트
|
---|
[111] | 119 | */
|
---|
[109] | 120 | int
|
---|
| 121 | CF_Queue_GetSize (CF_Queue_Ctx ctx)
|
---|
| 122 | {
|
---|
| 123 | return CF_List_GetSize ((CF_List_Ctx) ctx);
|
---|
| 124 | }
|
---|