]> rtime.felk.cvut.cz Git - ulut.git/commitdiff
Added support for static GSA arrays.
authorppisa <ppisa>
Tue, 9 Aug 2005 15:20:45 +0000 (15:20 +0000)
committerppisa <ppisa>
Tue, 9 Aug 2005 15:20:45 +0000 (15:20 +0000)
ulut/ul_gsa.h
ulut/ul_gsacust.h

index b9dd98a23b18d19f557a402e2adbc97bfe549388..1a4bb5bacdf6472f64e22c2607715c7c12340515 100644 (file)
@@ -138,6 +138,11 @@ typedef struct gsa_array_field_t{
   unsigned alloc_count;
 } gsa_array_field_t;
 
   unsigned alloc_count;
 } gsa_array_field_t;
 
+typedef struct gsa_static_array_field_t{
+  void * const *items;
+  unsigned count;
+} gsa_static_array_field_t;
+
 void gsa_cust_init_array_field(gsa_array_field_t *array);
 int gsa_cust_insert_at(gsa_array_field_t *array, void *item, unsigned where);
 int gsa_cust_delete_at(gsa_array_field_t *array, unsigned indx);
 void gsa_cust_init_array_field(gsa_array_field_t *array);
 int gsa_cust_insert_at(gsa_array_field_t *array, void *item, unsigned where);
 int gsa_cust_delete_at(gsa_array_field_t *array, unsigned indx);
@@ -146,8 +151,8 @@ int gsa_cust_delete_at(gsa_array_field_t *array, unsigned indx);
 /* User must provide his/her own compare routine with 
     int cust_cmp_fnc(cust_key_t *a, cust_key_t *b) */
 
 /* User must provide his/her own compare routine with 
     int cust_cmp_fnc(cust_key_t *a, cust_key_t *b) */
 
-/* Declaration of new custom array */
-#define GSA_CUST_DEC(cust_prefix, cust_array_t, cust_item_t, cust_key_t,\
+/*** Base declaration of custom GSA array  ***/
+#define GSA_BASE_CUST_DEC(cust_prefix, cust_array_t, cust_item_t, cust_key_t,\
                cust_array_field, cust_item_key, cust_cmp_fnc) \
 \
 static inline cust_item_t * \
                cust_array_field, cust_item_key, cust_cmp_fnc) \
 \
 static inline cust_item_t * \
@@ -162,29 +167,9 @@ cust_prefix##_indx2key(const cust_array_t *array, unsigned indx)\
   { return &(cust_prefix##_indx2item(array, indx)->cust_item_key);}\
 \
 int cust_prefix##_bsearch_indx(const cust_array_t *array, const cust_key_t *key, int mode, unsigned *indxp);\
   { return &(cust_prefix##_indx2item(array, indx)->cust_item_key);}\
 \
 int cust_prefix##_bsearch_indx(const cust_array_t *array, const cust_key_t *key, int mode, unsigned *indxp);\
-int cust_prefix##_insert(cust_array_t *array, cust_item_t *item);\
-int cust_prefix##_delete(cust_array_t *array, const cust_item_t *item);\
-\
-static inline void \
-cust_prefix##_init_array_field(cust_array_t *array)\
-{\
-  gsa_cust_init_array_field(&array->cust_array_field);\
-}\
-\
-static inline int \
-cust_prefix##_insert_at(cust_array_t *array, cust_item_t *item, unsigned indx)\
-{\
-  return gsa_cust_insert_at(&array->cust_array_field, item, indx);\
-}\
-\
-static inline int \
-cust_prefix##_delete_at(cust_array_t *array, unsigned indx)\
-{\
-  return gsa_cust_delete_at(&array->cust_array_field, indx);\
-}\
 \
 static inline  cust_item_t *\
 \
 static inline  cust_item_t *\
-cust_prefix##_at(cust_array_t *array, unsigned indx)\
+cust_prefix##_at(const cust_array_t *array, unsigned indx)\
 {\
   return cust_prefix##_indx2item(array, indx);\
 }\
 {\
   return cust_prefix##_indx2item(array, indx);\
 }\
@@ -236,14 +221,6 @@ cust_prefix##_is_empty(const cust_array_t *array)\
 }\
 \
 static inline cust_item_t *\
 }\
 \
 static inline cust_item_t *\
-cust_prefix##_cut_last(cust_array_t *array)\
-{\
-  if(cust_prefix##_is_empty(array)) return NULL;\
-  return (cust_item_t *)array->cust_array_field.items\
-                          [--array->cust_array_field.count];\
-}\
-\
-static inline cust_item_t *\
 cust_prefix##_first(const cust_array_t *array)\
 {\
   return cust_prefix##_indx2item(array, 0);\
 cust_prefix##_first(const cust_array_t *array)\
 {\
   return cust_prefix##_indx2item(array, 0);\
@@ -265,8 +242,11 @@ static inline unsigned \
 cust_prefix##_last_indx(const cust_array_t *array)\
 {\
   return array->cust_array_field.count-1;\
 cust_prefix##_last_indx(const cust_array_t *array)\
 {\
   return array->cust_array_field.count-1;\
-}\
-/*** Iterators ***/\
+}
+
+/*** Iterators for GSA arrays ***/
+#define GSA_IT_CUST_DEC(cust_prefix, cust_array_t, cust_item_t, cust_key_t) \
+\
 typedef struct {\
   cust_array_t *container;\
   unsigned indx;\
 typedef struct {\
   cust_array_t *container;\
   unsigned indx;\
@@ -313,12 +293,6 @@ cust_prefix##_is_end_it(cust_prefix##_it_t *it)\
   return it->indx>cust_prefix##_last_indx(it->container);\
 }\
 \
   return it->indx>cust_prefix##_last_indx(it->container);\
 }\
 \
-static inline void \
-cust_prefix##_delete_it(cust_prefix##_it_t *it)\
-{\
-  cust_prefix##_delete_at(it->container,it->indx);\
-}\
-\
 static inline int \
 cust_prefix##_find_it(cust_array_t *container, cust_key_t *key, cust_prefix##_it_t *it)\
 {\
 static inline int \
 cust_prefix##_find_it(cust_array_t *container, cust_key_t *key, cust_prefix##_it_t *it)\
 {\
@@ -340,6 +314,60 @@ cust_prefix##_find_after_it(cust_array_t *container, cust_key_t *key, cust_prefi
   return (it->indx=cust_prefix##_find_after_indx(container, key))!=(unsigned)-1;\
 }
 
   return (it->indx=cust_prefix##_find_after_indx(container, key))!=(unsigned)-1;\
 }
 
+/* Declaration of new static custom array without support of runtime modifications */
+#define GSA_STATIC_CUST_DEC(cust_prefix, cust_array_t, cust_item_t, cust_key_t,\
+               cust_array_field, cust_item_key, cust_cmp_fnc) \
+\
+GSA_BASE_CUST_DEC(cust_prefix, cust_array_t, cust_item_t, cust_key_t,\
+               cust_array_field, cust_item_key, cust_cmp_fnc) \
+\
+GSA_IT_CUST_DEC(cust_prefix, const cust_array_t, cust_item_t, cust_key_t)
+
+/*** Declaration of dynamic custom array with  ***/
+#define GSA_CUST_DEC(cust_prefix, cust_array_t, cust_item_t, cust_key_t,\
+               cust_array_field, cust_item_key, cust_cmp_fnc) \
+\
+GSA_BASE_CUST_DEC(cust_prefix, cust_array_t, cust_item_t, cust_key_t,\
+               cust_array_field, cust_item_key, cust_cmp_fnc) \
+\
+int cust_prefix##_insert(cust_array_t *array, cust_item_t *item);\
+int cust_prefix##_delete(cust_array_t *array, const cust_item_t *item);\
+\
+static inline void \
+cust_prefix##_init_array_field(cust_array_t *array)\
+{\
+  gsa_cust_init_array_field(&array->cust_array_field);\
+}\
+\
+static inline int \
+cust_prefix##_insert_at(cust_array_t *array, cust_item_t *item, unsigned indx)\
+{\
+  return gsa_cust_insert_at(&array->cust_array_field, item, indx);\
+}\
+\
+static inline int \
+cust_prefix##_delete_at(cust_array_t *array, unsigned indx)\
+{\
+  return gsa_cust_delete_at(&array->cust_array_field, indx);\
+}\
+\
+static inline cust_item_t *\
+cust_prefix##_cut_last(cust_array_t *array)\
+{\
+  if(cust_prefix##_is_empty(array)) return NULL;\
+  return (cust_item_t *)array->cust_array_field.items\
+                          [--array->cust_array_field.count];\
+}\
+/*** Iterators ***/\
+GSA_IT_CUST_DEC(cust_prefix, cust_array_t, cust_item_t, cust_key_t) \
+\
+static inline void \
+cust_prefix##_delete_it(cust_prefix##_it_t *it)\
+{\
+  cust_prefix##_delete_at(it->container,it->indx);\
+}\
+
+
 /* The next implementation of foreaach is elegant, but can not
    be used in C99 non-conformant C compiler */
 #ifdef WITH_C99
 /* The next implementation of foreaach is elegant, but can not
    be used in C99 non-conformant C compiler */
 #ifdef WITH_C99
index eb276b371094dc5b26af47c21ff61007b0acd0f9..655735fed17ac92b881bb5bc027006e0268cb211 100644 (file)
@@ -30,7 +30,8 @@
 extern "C" {
 #endif
 
 extern "C" {
 #endif
 
-#define GSA_CUST_IMP(cust_prefix, cust_array_t, cust_item_t, cust_key_t,\
+/* Static version of custom GSA arrays. It does not support runtime modifications. */
+#define GSA_STATIC_CUST_IMP(cust_prefix, cust_array_t, cust_item_t, cust_key_t,\
                cust_array_field, cust_item_key, cust_cmp_fnc, cust_ins_fl) \
 \
 int \
                cust_array_field, cust_item_key, cust_cmp_fnc, cust_ins_fl) \
 \
 int \
@@ -74,7 +75,15 @@ cust_prefix##_bsearch_indx(const cust_array_t *array, const cust_key_t *key, \
   }\
   *indx=c;\
   return 1;\
   }\
   *indx=c;\
   return 1;\
-}\
+}
+
+
+/* Dynamic version with full support of insert and delete functions. */
+#define GSA_CUST_IMP(cust_prefix, cust_array_t, cust_item_t, cust_key_t,\
+               cust_array_field, cust_item_key, cust_cmp_fnc, cust_ins_fl) \
+\
+GSA_STATIC_CUST_IMP(cust_prefix, cust_array_t, cust_item_t, cust_key_t,\
+       cust_array_field, cust_item_key, cust_cmp_fnc, cust_ins_fl) \
 \
 int \
 cust_prefix##_insert(cust_array_t *array, cust_item_t *item)\
 \
 int \
 cust_prefix##_insert(cust_array_t *array, cust_item_t *item)\