コード例 #1
0
ファイル: vecops.c プロジェクト: Akshay197/arules
static void _rec (void **vec, int n, VCMPFN cmpfn, void *data)
{                               /* --- recursive part of sort */
  void **l, **r;                /* pointers to exchange positions */
  void *x,  *t;                 /* pivot element and exchange buffer */
  int  m;                       /* number of elements in 2nd section */

  do {                          /* sections sort loop */
    l = vec; r = l +n -1;       /* start at left and right boundary */
    if (cmpfn(*l, *r, data) > 0) {  /* bring the first and last */
      t = *l; *l = *r; *r = t; }    /* element into proper order */
    x = vec[n >> 1];            /* get the middle element as pivot */
    if      (cmpfn(x, *l, data) < 0) x = *l;  /* try to find a */
    else if (cmpfn(x, *r, data) > 0) x = *r;  /* better pivot */
    while (1) {                 /* split and exchange loop */
      while (cmpfn(*++l, x, data) < 0)    /* skip left  elements that */
        ;                       /* are smaller than the pivot element */
      while (cmpfn(*--r, x, data) > 0)    /* skip right elements that */
        ;                       /* are greater than the pivot element */
      if (l >= r) {             /* if less than two elements left, */
        if (l <= r) { l++; r--; } break; }       /* abort the loop */
      t = *l; *l = *r; *r = t;  /* otherwise exchange elements */
    }
    m = (int)(vec +n -l);       /* compute the number of elements */
    n = (int)(r -vec +1);       /* right and left of the split */
    if (n > m) {                /* if right section is smaller, */
      if (m >= TH_INSERT)       /* but larger than the threshold, */
        _rec(l, m, cmpfn, data); } /* sort it by a recursive call, */
    else {                      /* if the left section is smaller, */
      if (n >= TH_INSERT)       /* but larger than the threshold, */
        _rec(vec, n, cmpfn, data); /* sort it by a recursive call, */
      vec = l; n = m;           /* then switch to the right section */
    }                           /* keeping its size m in variable n */
  } while (n >= TH_INSERT);     /* while greater than threshold */
}  /* _rec() */
コード例 #2
0
ファイル: cw__test_helpers.cpp プロジェクト: trafi/djinni
bool cw__test_helpers_check_set_record(DjinniRecordHandle * rec) {
    djinni::Handle<DjinniRecordHandle> _rec(rec, set_record___delete);
    try {
        return ::testsuite::TestHelpers::check_set_record(DjinniSetRecord::toCpp(std::move(_rec)));
    }
    CW_TRANSLATE_EXCEPTIONS_RETURN(0);
}
コード例 #3
0
ファイル: vecops.c プロジェクト: Akshay197/arules
void v_sort (void *vec, int n, VCMPFN cmpfn, void *data)
{                               /* --- quick sort for pointer vectors */
  int  k;                       /* size of first section */
  void **l, **r;                /* to traverse the vector */
  void *t;                      /* exchange buffer */

  assert(vec && (n >= 0) && cmpfn);   /* check the function arguments */
  if (n <= 1) return;           /* do not sort less than two elements */
  if (n < TH_INSERT)            /* if fewer elements than threshold */
    k = n;                      /* for insertion sort, note the */
  else {                        /* number of elements, otherwise */
    _rec(vec, n, cmpfn, data);  /* call the recursive function */
    k = TH_INSERT -1;           /* and get the number of elements */
  }                             /* in the first vector section */
  for (l = r = vec; --k > 0; )  /* find the smallest element within */
    if (cmpfn(*++r, *l, data) < 0) l = r;   /* the first k elements */
  r = vec;                      /* swap the smallest element */
  t = *l; *l = *r; *r = t;      /* to front as a sentinel */
  while (--n > 0) {             /* insertion sort loop */
    t = *++r;                   /* note the element to insert */
    for (l = r; cmpfn(*--l, t, data) > 0; ) /* shift right elements */
      l[1] = *l;                /* that are greater than the one to */
    l[1] = t;                   /* insert and store the element to */
  }                             /* insert in the place thus found */
}  /* v_sort() */
コード例 #4
0
ファイル: cpeopleneeds.cpp プロジェクト: KulerOvZuo/SimCity
CPeopleNeeds CPeopleNeeds::operator+ (CPeopleNeeds _C)
{
    CProducts _prod(_C.getProductsNeed());
    CService _serv(_C.getServiceNeed());
    CRecreation _rec(_C.getRecreationNeed());
    double _traffic = _C.getTraffic();
    double _dist = _C.getDisturbance();
    return CPeopleNeeds(productsNeed+_prod,serviceNeed+_serv,recreationNeed+_rec,disturbanceNeed+_dist,traffic+_traffic);
}
コード例 #5
0
ファイル: cpeopleneeds.cpp プロジェクト: KulerOvZuo/SimCity
CPeopleNeeds& CPeopleNeeds::operator+= (CPeopleNeeds const &_C)
{
    CProducts _prod(_C.getProductsNeed());
    CService _serv(_C.getServiceNeed());
    CRecreation _rec(_C.getRecreationNeed());
    double _traffic = _C.getTraffic();
    double _dist = _C.getDisturbance();

    this->productsNeed += _prod;
    this->serviceNeed +=_serv;
    this->recreationNeed +=_rec;
    this->disturbanceNeed +=_dist;
    this->traffic +=_traffic;
    return *this;
}