00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "SortedSet_dh.h"
00031 #include "shellSort_dh.h"
00032 #include "Mem_dh.h"
00033
00034
00035 #undef __FUNC__
00036 #define __FUNC__ "SortedSet_dhCreate"
00037 void
00038 SortedSet_dhCreate (SortedSet_dh * ss, int size)
00039 {
00040 START_FUNC_DH
00041 struct _sortedset_dh *tmp =
00042 (struct _sortedset_dh *) MALLOC_DH (sizeof (struct _sortedset_dh));
00043 CHECK_V_ERROR;
00044 *ss = tmp;
00045
00046 tmp->n = size;
00047 tmp->list = (int *) MALLOC_DH (size * sizeof (int));
00048 CHECK_V_ERROR;
00049 tmp->count = 0;
00050 END_FUNC_DH}
00051
00052 #undef __FUNC__
00053 #define __FUNC__ "SortedSet_dhDestroy"
00054 void
00055 SortedSet_dhDestroy (SortedSet_dh ss)
00056 {
00057 START_FUNC_DH if (ss->list != NULL)
00058 {
00059 FREE_DH (ss->list);
00060 CHECK_V_ERROR;
00061 }
00062 FREE_DH (ss);
00063 CHECK_V_ERROR;
00064 END_FUNC_DH}
00065
00066
00067 #undef __FUNC__
00068 #define __FUNC__ "SortedSet_dhInsert"
00069 void
00070 SortedSet_dhInsert (SortedSet_dh ss, int idx)
00071 {
00072 START_FUNC_DH bool isInserted = false;
00073 int ct = ss->count;
00074 int *list = ss->list;
00075 int i, n = ss->n;
00076
00077
00078 for (i = 0; i < ct; ++i)
00079 {
00080 if (list[i] == idx)
00081 {
00082 isInserted = true;
00083 break;
00084 }
00085 }
00086
00087
00088
00089
00090
00091 if (!isInserted)
00092 {
00093 if (ct == n)
00094 {
00095 int *tmp = (int *) MALLOC_DH (n * 2 * sizeof (int));
00096 CHECK_V_ERROR;
00097 memcpy (tmp, list, n * sizeof (int));
00098 FREE_DH (list);
00099 CHECK_V_ERROR;
00100 list = ss->list = tmp;
00101 ss->n *= 2;
00102 }
00103
00104 list[ct] = idx;
00105 ss->count += 1;
00106 }
00107 END_FUNC_DH}
00108
00109
00110 #undef __FUNC__
00111 #define __FUNC__ "SortedSet_dhGetList"
00112 void
00113 SortedSet_dhGetList (SortedSet_dh ss, int **list, int *count)
00114 {
00115 START_FUNC_DH shellSort_int (ss->count, ss->list);
00116 *list = ss->list;
00117 *count = ss->count;
00118 END_FUNC_DH}