Exemplo n.º 1
0
/*-------------------------------------------------------------------------*/
static vector_t *
intersect_ordered_arr (vector_t *a1, vector_t *a2)

/* Compute the intersection of the two ordered arrays <a1> and <a2>.
 *
 * The result is a new sorted(!) vector with all elements, which are present
 * in both input vectors.
 * This function is called by f_intersect_alists().
 */

{
    vector_t *a3;
    mp_int d, l, i1, i2, a1s, a2s;

    a1s = (mp_int)VEC_SIZE(a1);
    a2s = (mp_int)VEC_SIZE(a2);
    a3 = allocate_array( a1s < a2s ? a1s : a2s);
    for (i1=i2=l=0; i1 < a1s && i2 < a2s; ) {
        d = svalue_cmp(&a1->item[i1], &a2->item[i2]);
        if (d<0)
            i1++;
        else if (d>0)
            i2++;
        else {
            assign_svalue_no_free(&a3->item[l++], &a2->item[(i1++,i2++)] );
        }
    }
    return shrink_array(a3, l);
} /* intersect_ordered_arr() */
Exemplo n.º 2
0
static int
save_outstanding_request( struct protocol_ctrl *ctrl, const uint32_t transaction_id, const uint16_t type, const uint16_t flags ) {
  int i;
  int error = 0;

  // search for an request entry
  for ( i = 0; i < MAX_OUTSTANDING_REQUESTS; i++ ) {
    if ( ctrl->outstanding_requests[ i ].transaction_id == transaction_id && 
      ctrl->outstanding_requests[ i ].type == type ) {
      break;
    }
  }
  /*
   * a request entry is found and the flags is not set to OFPMPF_REQ_MORE.
   * remove the entry from the array.
   */
  if ( i < MAX_OUTSTANDING_REQUESTS  ) {
    if ( ( flags & OFPMPF_REQ_MORE ) == 0 ) {
      shrink_array( ctrl->outstanding_requests, i );
      ctrl->nr_requests--;
    }
  } else {
    /*
     * a request entry is not found but there is to store it and the flags
     * is set to OFPMPF_REQ_MORE
     */
    if ( ctrl->nr_requests < MAX_OUTSTANDING_REQUESTS ) {
      if ( ( flags & OFPMPF_REQ_MORE ) == OFPMPF_REQ_MORE ) {
        ctrl->outstanding_requests[ i ].transaction_id = transaction_id;
        ctrl->outstanding_requests[ i ].type = type;
        ctrl->outstanding_requests[ i ].flags = flags;
        ctrl->nr_requests++;
      }
    } else {
      /*
       * the only error condition to flag no more room to accept further
       * requests
       */
      error = -1;
    }
  }

  return error;
}