コード例 #1
0
ファイル: setprod.c プロジェクト: bubuker/keggle_santa
/* ------------------------------------------------------------------------- 
 * --- set_new                 
 * -------------------------------------------------------------------------
 */
Set* set_prod_new(const Set* a, const Set* b)
{
   Set* set;

   assert(set_is_valid(a));
   assert(set_is_valid(b));
   assert(a->head.type != SET_PSEUDO);
   assert(b->head.type != SET_PSEUDO);
   
   if (a->head.type == SET_EMPTY || b->head.type == SET_EMPTY)
      return set_empty_new(a->head.dim + b->head.dim);
   
   set = calloc(1, sizeof(*set));

   assert(set != NULL);

   set->head.refc    = 1;
   set->head.dim     = a->head.dim + b->head.dim;
   set->head.members = a->head.members * b->head.members;
   set->head.type    = SET_PROD;

   set->prod.set_a   = set_copy(a);
   set->prod.set_b   = set_copy(b);

   SID_set2(set->prod, SET_PROD_SID);

   assert(set_prod_is_valid(set));

   return set;
}
コード例 #2
0
ファイル: setprod.c プロジェクト: bubuker/keggle_santa
/* Initialise Iterator. Write into iter
 */
static SetIter* set_prod_iter_init(
   const Set*   set,
   const Tuple* pattern,
   int          offset)
{
   SetIter*     iter;

   assert(set_prod_is_valid(set));
   assert(pattern == NULL || tuple_is_valid(pattern));
   assert(offset     >= 0);
   assert(pattern == NULL || offset <  tuple_get_dim(pattern));

   iter = calloc(1, sizeof(*iter));

   assert(iter != NULL);

   iter->prod.elem = calloc(set->head.dim, sizeof(*iter->prod.elem));

   assert(iter->prod.elem != NULL);

   iter->prod.first = TRUE;
   
   iter->prod.iter_a = set_iter_init_intern(set->prod.set_a, pattern, offset);
   iter->prod.iter_b = set_iter_init_intern(set->prod.set_b, pattern,
      offset + set->prod.set_a->head.dim);

   SID_set2(iter->prod, SET_PROD_ITER_SID);

   assert(set_prod_iter_is_valid(iter));

   return iter;
}
コード例 #3
0
ファイル: setrange.c プロジェクト: aimanqais/gerardus
/* Initialise Iterator. Write into iter
 */
static SetIter* set_range_iter_init(
   const Set*   set,
   const Tuple* pattern,
   int          offset)
{
   const Elem*  elem;
   SetIter*     iter;
   
   assert(set_range_is_valid(set));
   assert(pattern == NULL || tuple_is_valid(pattern));
   assert(offset      >= 0);
   assert(pattern == NULL || offset <  tuple_get_dim(pattern));

   iter = calloc(1, sizeof(*iter));

   assert(iter != NULL);

   if (pattern == NULL)
   {
      iter->range.first = 0;
      iter->range.last  = val_to_idx(set->range.begin, set->range.step, set->range.end);
   }
   else
   {
      elem = tuple_get_elem(pattern, offset);

      switch(elem_get_type(elem))
      {
      case ELEM_NAME :
         iter->range.first = 0;
         iter->range.last  = val_to_idx(set->range.begin, set->range.step, set->range.end);
         break;
      case ELEM_NUMB :
         iter->range.first = set_range_lookup_idx(set, pattern, offset);

         if (iter->range.first >= 0)
            iter->range.last = iter->range.first;
         else
         {
            iter->range.first = 1;
            iter->range.last  = 0;
         }
         break;
      case ELEM_STRG :
         /* This should not happen. Probably a set with mixed
          * numbers and string was generated.
          */
      default :
         abort();
      }
   }
   iter->range.now = iter->range.first;

   SID_set2(iter->range, SET_RANGE_ITER_SID);

   assert(set_range_iter_is_valid(iter));

   return iter;
}
コード例 #4
0
ファイル: setempty.c プロジェクト: aimanqais/gerardus
/* ------------------------------------------------------------------------- 
 * --- set_new                 
 * -------------------------------------------------------------------------
 */
Set* set_empty_new(int dim)
{
   Set* set;

   set = calloc(1, sizeof(*set));

   assert(set != NULL);

   set->head.refc    = 1;
   set->head.dim     = dim;
   set->head.members = 0;
   set->head.type    = SET_EMPTY;

   SID_set2(set->empty, SET_EMPTY_SID);

   assert(set_empty_is_valid(set));
   
   return set;
}
コード例 #5
0
ファイル: setpseudo.c プロジェクト: bubuker/keggle_santa
/* ------------------------------------------------------------------------- 
 * --- set_new                 
 * -------------------------------------------------------------------------
 */
Set* set_pseudo_new()
{
   Set* set;

   set = calloc(1, sizeof(*set));

   assert(set != NULL);

   set->head.refc    = 1;
   set->head.dim     = 0;
   set->head.members = 1;
   set->head.type    = SET_PSEUDO;

   SID_set2(set->pseudo, SET_PSEUDO_SID);

   assert(set_pseudo_is_valid(set));
   
   return set;
}
コード例 #6
0
ファイル: setempty.c プロジェクト: aimanqais/gerardus
/*ARGSUSED*/
static SetIter* iter_init(
   const Set*   set,
   const Tuple* pattern,
   int          offset)
{
   SetIter*        iter;
   
   assert(set_empty_is_valid(set));
   assert(pattern == NULL || tuple_is_valid(pattern));
   assert(offset      == 0);

   iter = calloc(1, sizeof(*iter));

   assert(iter != NULL);
   
   SID_set2(iter->empty, SET_EMPTY_ITER_SID);

   assert(set_empty_iter_is_valid(iter));

   return iter;
}
コード例 #7
0
ファイル: setrange.c プロジェクト: aimanqais/gerardus
/* ------------------------------------------------------------------------- 
 * --- set_new                 
 * -------------------------------------------------------------------------
 */
Set* set_range_new(int begin, int end, int step)
{
   Set* set;

   set = calloc(1, sizeof(*set));

   assert(set != NULL);

   set->head.refc    = 1;
   set->head.dim     = 1;
   set->head.members = 1 + (end - begin) / step;
   set->head.type    = SET_RANGE;

   set->range.begin  = begin;
   set->range.end    = end;
   set->range.step   = step;

   SID_set2(set->range, SET_RANGE_SID);

   assert(set_range_is_valid(set));
   
   return set;
}
コード例 #8
0
ファイル: setpseudo.c プロジェクト: bubuker/keggle_santa
/*ARGSUSED*/
static SetIter* iter_init(
   const Set*   set,
   const Tuple* pattern,
   int          offset)
{
   SetIter*        iter;
   
   assert(set_pseudo_is_valid(set));
   assert(pattern == NULL || tuple_is_valid(pattern));
   assert(pattern == NULL || tuple_get_dim(pattern) == 0);
   assert(offset                 == 0);

   iter = calloc(1, sizeof(*iter));

   assert(iter != NULL);

   iter->pseudo.first = TRUE;
   
   SID_set2(iter->pseudo, SET_PSEUDO_ITER_SID);

   assert(set_pseudo_iter_is_valid(iter));

   return iter;
}