Esempio n. 1
0
void resolve_value_state (Entry_State *entry, int value_index)
{
	Value_State *value = &(entry->values[value_index]);
	int value_distinguished_csn = get_value_dn_csn (entry, value_index);

	purge_value_state (entry, value_index);

	/* no deletes that effect the state */
	if (max_val (value->delete_csn, entry->attr_delete_csn) <
		max_val (value_distinguished_csn, value->presence_csn))
	{
		value->present = 1;
		return;
	}

	if (value->present)	/* check if it should be removed based on the current state */
	{
		if (!value_distinguished_at_delete (entry, value_index))
		{
			value->present = 0;
		}			
	}
	else	/* not present - check if it should be restored */
	{
		if (value_distinguished_at_delete (entry, value_index))
		{
			value->present = 1;	
		}
	}
}
Esempio n. 2
0
void resolve_value_state (Entry_State *entry, int value_index)
{
	Value_State *value = &(entry->values[value_index]);

	purge_value_state (value);

	/* no deletes that effect the state */
	if (max_val (value->delete_csn, entry->attr_delete_csn) <
		max_val (value->distinguished_csn, value->presense_csn))
		return;

	if (value->present)	/* check if it should be removed based on the current state */
	{
		if (!value_distinguished_at_delete (value, entry->attr_delete_csn))
		{
			/* note that we keep presence csn because we might have to restore
			   the value in the future */
			value->present = 0;
		}			
	}
	else	/* not present - check if it should be restored */
	{
		if (value_distinguished_at_delete (value, entry->attr_delete_csn))
		{
			value->present = 1;	
		}
	}
}
Esempio n. 3
0
// Wrong! it accumulates, does not start over.
int LongsetSubString(const char* A, const char* B) {
    int M = strlen(A) + 1;
    int N = strlen(B) + 1;

    int* dp = new int[M,N]; // 2 D Array, with first row/col 0

    for (int i=0; i<M; ++i) {
        dp[i,0] = 0; // First row
    }
    for (int j=0; j<N; ++j) {
        dp[0,j] = 0; // First col
    }

    for (int i=1; i<M; ++i) {
        for (int j=1; j<N; ++j) {
            dp[i,j] = max_val(dp[i-1,j], dp[i,j-1]);
            if ((A[i-1] == B[j-1]) && (A[i-1] != 0))
                dp[i,j] = max_val(dp[i,j], dp[i-1,j-1] + 1);
        }
    }

    log(dp, M, N);
    int ret = dp[M-1,N-1];
    delete [] dp;
    return ret;
}
Esempio n. 4
0
int KinematicAltBands::first_band_alt_generic(Detection3D* conflict_det, Detection3D* recovery_det,
    double B, double T, double B2, double T2,
    const TrafficState& ownship, const std::vector<TrafficState>& traffic, bool dir, bool green) {
  int upper = (int)(dir ? std::floor((max_val(ownship)-min_val(ownship))/get_step())+1 :
      std::floor((ownship.altitude()-min_val(ownship))/get_step()));
  int lower = dir ? (int)(std::ceil(ownship.altitude()-min_val(ownship))/get_step()) : 0;
  if (ownship.altitude() < min_val(ownship) || ownship.altitude() > max_val(ownship)) {
    return -1;
  } else {
    return first_nat(lower,upper,dir,conflict_det,recovery_det,B,T,B2,T2,ownship,traffic,green);
  }
}
int main(int argc, char * argv[]) {
	double h, *val, max, min;
	int n, nval, i, *vet, size;
	long unsigned int duracao;
	struct timeval start, end;

	scanf("%d",&size);

	/* entrada do numero de dados */
	scanf("%d",&nval);
	/* numero de barras do histograma a serem calculadas */
	scanf("%d",&n);

	/* vetor com os dados */
	val = (double *)malloc(nval*sizeof(double));
	vet = (int *)malloc(n*sizeof(int));

	/* entrada dos dados */
	for(i=0;i<nval;i++) {
		scanf("%lf",&val[i]);
	}

	/* calcula o minimo e o maximo valores inteiros */
	min = floor(min_val(val,nval));
	max = ceil(max_val(val,nval));

	/* calcula o tamanho de cada barra */
	h = (max - min)/n;

	gettimeofday(&start, NULL);

	/* chama a funcao */
	vet = count(min, max, vet, n, h, val, nval);

	gettimeofday(&end, NULL);

	duracao = ((end.tv_sec * 1000000 + end.tv_usec) - \
	(start.tv_sec * 1000000 + start.tv_usec));

	printf("%.2lf",min);
	for(i=1;i<=n;i++) {
		printf(" %.2lf",min + h*i);
	}
	printf("\n");

	/* imprime o histograma calculado */
	printf("%d",vet[0]);
	for(i=1;i<n;i++) {
		printf(" %d",vet[i]);
	}
	printf("\n");

	/* imprime o tempo de duracao do calculo */
	printf("%lu\n",duracao);

	free(vet);
	free(val);

	return 0;
}
Esempio n. 6
0
/* Note we can't trim distinguished_csn (even during regular trimming)
   because in some cases we would not be able to figure out whether
   a value was distinguished or not at the time of deletion. 

   Example 1:							Example2:
   csn order operation					csn	order	operation
   1    1	 make V  distinguished		1	  1		make V distinguished
   3	3	 delete V 					2	  2		make V non distinguished
   4	2	 make V non-distinguished	3	  4		delete V
										4	  3     make V non distinguished (on another server)

   if the csns up to 2 were triimed, when delete operation is received, the state
   is exactly the same in both examples but in example one delete should not go
   through while in example 2 it should

 */
int value_distinguished_at_delete (Value_State *value, int attr_delete_csn)
{
	if (value->distinguished_csn >= 0 &&
		(is_list_empty (value->non_distinguished_csns) ||
		 min_list_val (value->non_distinguished_csns) > 
		 max_val (value->delete_csn, attr_delete_csn)))
		return 1;
	else
		return 0;
}
Esempio n. 7
0
void purge_value_state (Entry_State *entry, int value_index)
{
	Value_State *value = &(entry->values[value_index]);
	int value_distinguished_csn = get_value_dn_csn (entry, value_index);

	if (value_distinguished_csn == -1 && value->presence_csn > value->delete_csn)
		value->delete_csn = NOT_PRESENT;	
	else if (value->delete_csn < max_val (value_distinguished_csn, value->presence_csn))
		value->delete_csn = NOT_PRESENT;	
}
int height_val(node *root)
{
    if(root == NULL)
        return 0;
    
    else
    {
        return max_val(height_val(root -> left), height_val(root -> right)) + 1;
    }
}
Esempio n. 9
0
void purge_value_state (Value_State *value)
{
	/* value state information can be purged once a value was
	   readed/made distinguished because at that point we know that the value
	   existed/was distinguished */
	   
	purge_non_distinguished_csns (value); 

	if (value->delete_csn < max_val (value->distinguished_csn, value->presense_csn))
		value->delete_csn = NOT_PRESENT;	
}
Esempio n. 10
0
int main(void)
{
    int source[LEN] = {5,8,10,6,1,3,7,14,9,4};
    int max;

    show_arr(source, LEN);
    putchar('\n');
    max = max_val(source, LEN);

    printf("%d = is largest value of the array\n", max);

    return 0;
}
Esempio n. 11
0
DB::DB(NetworkInterface *_iface, u_int32_t _dir_duration, u_int8_t _db_id) {
  dir_duration = max_val(_dir_duration, 300); /* 5 min is the minimum duration */

  // sqlite3_config(SQLITE_CONFIG_SERIALIZED);
  db = NULL, end_dump = 0, iface = _iface, db_id = _db_id;
  contacts_cache_idx = 0;

  for(int i=0; i<CONST_NUM_OPEN_DB_CACHE; i++) {
    contacts_cache[i].db = NULL,
      contacts_cache[i].last_open_contacts_db_path[0] = '\0',
      contacts_cache[i].num_contacts_db_insert = 0,
      contacts_cache[i].last_insert = 0;
  }
}
Esempio n. 12
0
void vec2Di::print(const wchar_t* file) const
{
        const vec2Di& v = *this;
        wchar_t format[32] = L"%4d";

        int mx = max_val();
        int mn = min_val();
        if (abs(mn) > mx)
                mx = abs(mn);

        if (mx >= 10000)
                wcscpy(format, L"%7d");
        else if (mx >= 10000)
                wcscpy(format, L"%6d");
        else if (mx >= 1000)
                wcscpy(format, L"%5d");
        else if (mx >= 100)
                wcscpy(format, L"%4d");
        else if(mx >= 10)
                wcscpy(format, L"%3d");
        else if(mx < 10)
                wcscpy(format, L"%2d");
        
        if (file) {
                FILE *fp = _wfopen(file, L"wt");
                if (fp != 0) {
                        fwprintf(fp, L"\n vec: %p\n", this);
                        for (unsigned int i = 0; i < height(); i++) {
                                for (unsigned int j = 0; j < width(); j++)
                                        fwprintf(fp, format, v(i, j));
                                fwprintf(fp, L"\n");
                        }
                        fclose(fp);
                }
        } else {
                wprintf(L"\n vec: %p\n", this);
                for (unsigned int i = 0; i < height(); i++) {
                        for (unsigned int j = 0; j < width(); j++)
                                wprintf(format, v(i, j));
                        wprintf(L"\n");
                }
        }
}
Esempio n. 13
0
void KinematicAltBands::alt_bands_generic(std::vector<Integerval>& l,
    Detection3D* conflict_det, Detection3D* recovery_det,
    double B, double T, double B2, double T2,
    const TrafficState& ownship, const std::vector<TrafficState>& traffic) {
  int max_step = (int)std::floor((max_val(ownship)-min_val(ownship))/get_step())+1;
  int d = -1; // Set to the first index with no conflict
  for (int k = 0; k <= max_step; ++k) {
    j_step_ = k;
    if (d >=0 && conflict_free_traj_step(conflict_det,recovery_det,B,T,B2,T2,ownship,traffic))  {
      continue;
    } else if (d >=0) {
      l.push_back(Integerval(d,k-1));
      d = -1;
    } else if (conflict_free_traj_step(conflict_det,recovery_det,B,T,B2,T2,ownship,traffic)) {
      d = k;
    }
  }
  if (d >= 0) {
    l.push_back(Integerval(d,max_step));
  }
}
Esempio n. 14
0
int main() {
    std::ifstream infile("data_problem018.txt", std::ios::in);
    if (!infile) {
        std::cerr << "File not found!\n";
        exit(-1);
    }

    std::vector< std::vector<int> > tri;
    std::vector< std::vector<int> > val;

    std::string row;

    while (getline(infile, row, '\n')) {
        tri.push_back(split(row));
        val.push_back(split(row));
    }

    int m;
    m = max_val(tri, val);
    std::cout << "The max value is: " << m << std::endl;
    return 0;
}
Esempio n. 15
0
vm::tuple*
agg_configuration::generate_max_int(const field_num field) const
{
   const_iterator end(vals.end());
   const_iterator it(vals.begin());
   vm::tuple *max_tpl((*it)->get_tuple());
   int_val max_val(max_tpl->get_int(field));

   ++it;
   for(; it != end; ++it)
   {
      simple_tuple *sother(*it);
      vm::tuple *other(sother->get_tuple());

      if(max_val < other->get_int(field)) {
         max_val = other->get_int(field);
         max_tpl = other;
      }
   }

   return max_tpl->copy();
}
Esempio n. 16
0
int value_distinguished_at_delete (Entry_State *entry, int value_index)
{
	Value_State *value = &(entry->values[value_index]);
	int value_distinguished_csn = get_value_dn_csn (entry, value_index);
	int	delete_csn;
	int i;

	/* value has never been distinguished */
	if (value_distinguished_csn == -1)
		return 0;

	delete_csn = max_val (entry->attr_delete_csn, value->delete_csn);

	for (i = 0; i < entry->dn_csn_count; i++)
	{
		if (entry->dn_csns[i].csn > delete_csn)
			break;
	}

	/* i is never equal to 0 because the csn of the first element is always
	   smaller than csn of any operation we can receive */
	return (entry->dn_csns[i-1].value_index == value_index);	
}
Esempio n. 17
0
__global__ void nonMaxKernel(float* x_out, float* y_out, float* resp_out,
                             unsigned* count, const unsigned idim0,
                             const unsigned idim1, const T* resp_in,
                             const unsigned edge, const unsigned max_corners) {
    // Responses on the border don't have 8-neighbors to compare, discard them
    const unsigned r = edge + 1;

    const unsigned gx = blockDim.x * blockIdx.x + threadIdx.x + r;
    const unsigned gy = blockDim.y * blockIdx.y + threadIdx.y + r;

    if (gx < idim0 - r && gy < idim1 - r) {
        const T v = resp_in[gy * idim0 + gx];

        // Find maximum neighborhood response
        T max_v;
        max_v = max_val(resp_in[(gy - 1) * idim0 + gx - 1],
                        resp_in[gy * idim0 + gx - 1]);
        max_v = max_val(max_v, resp_in[(gy + 1) * idim0 + gx - 1]);
        max_v = max_val(max_v, resp_in[(gy - 1) * idim0 + gx]);
        max_v = max_val(max_v, resp_in[(gy + 1) * idim0 + gx]);
        max_v = max_val(max_v, resp_in[(gy - 1) * idim0 + gx + 1]);
        max_v = max_val(max_v, resp_in[(gy)*idim0 + gx + 1]);
        max_v = max_val(max_v, resp_in[(gy + 1) * idim0 + gx + 1]);

        // Stores corner to {x,y,resp}_out if it's response is maximum compared
        // to its 8-neighborhood and greater or equal minimum response
        if (v > max_v) {
            unsigned idx = atomicAdd(count, 1u);
            if (idx < max_corners) {
                x_out[idx]    = (float)gx;
                y_out[idx]    = (float)gy;
                resp_out[idx] = (float)v;
            }
        }
    }
}
Esempio n. 18
0
void KinematicAltBands::none_bands(IntervalSet& noneset, Detection3D* conflict_det, Detection3D* recovery_det, const TrafficState& repac,
    int epsh, int epsv, double B, double T, const TrafficState& ownship, const std::vector<TrafficState>& traffic) {
  std::vector<Integerval> altint = std::vector<Integerval>();
  alt_bands_generic(altint,conflict_det,recovery_det,B,T,0,B,ownship,traffic);
  toIntervalSet(noneset,altint,get_step(),min_val(ownship),min_val(ownship),max_val(ownship));
}
Esempio n. 19
0
int Prefs::setOption(int optkey, char *optarg) {
  switch(optkey) {
  case 'A':
    switch(atoi(optarg)) {
    case 0:
      enable_aggregations = aggregations_disabled;
      break;
    case 1:
      enable_aggregations = aggregations_enabled_no_bitmap_dump;
      break;
    case 2:
      enable_aggregations = aggregations_enabled_with_bitmap_dump;
      break;
    default:
      ntop->getTrace()->traceEvent(TRACE_ERROR, "Invalid value for -A: disabling aggregations");
      enable_aggregations = aggregations_disabled;
      break;
    }
    break;

  case 'B':
    if((optarg[0] == '\"') && (strlen(optarg) > 2)) {
      packet_filter = strdup(&optarg[1]);      
      packet_filter[strlen(packet_filter)-1] = '\0';
    } else
      packet_filter = strdup(optarg);
    break;

  case 'c':
    categorization_key = optarg;
    break;

  case 'C':
    dump_timeline = true;
    break;

#ifndef WIN32
  case 'd':
    ntop->setWorkingDir(optarg);
    break;
#endif

  case 'D':
    if(!strcmp(optarg, "all")) dump_hosts_to_db = location_all;
    else if(!strcmp(optarg, "local")) dump_hosts_to_db = location_local_only;
    else if(!strcmp(optarg, "remote")) dump_hosts_to_db = location_remote_only;
    else if(!strcmp(optarg, "none")) dump_hosts_to_db = location_none;
    else ntop->getTrace()->traceEvent(TRACE_ERROR, "Unknown value %s for -D", optarg);
    break;

  case 'e':
    daemonize = true;
    break;

  case 'E':
    if(!strcmp(optarg, "all")) dump_aggregations_to_db = location_all;
    else if(!strcmp(optarg, "local")) dump_aggregations_to_db = location_local_only;
    else if(!strcmp(optarg, "remote")) dump_aggregations_to_db = location_remote_only;
    else if(!strcmp(optarg, "none")) dump_aggregations_to_db = location_none;
    else ntop->getTrace()->traceEvent(TRACE_ERROR, "Unknown value %s for -E", optarg);
    break;

  case 'S':
    if(!strcmp(optarg, "all")) sticky_hosts = location_all;
    else if(!strcmp(optarg, "local")) sticky_hosts = location_local_only;
    else if(!strcmp(optarg, "remote")) sticky_hosts = location_remote_only;
    else if(!strcmp(optarg, "none")) sticky_hosts = location_none;
    else ntop->getTrace()->traceEvent(TRACE_ERROR, "Unknown value %s for -S", optarg);
    break;
  case 'g':
    cpu_affinity = atoi(optarg);
    break;

  case 'm':
    free(local_networks);
    local_networks = strdup(optarg);
    break;

  case 'n':
    dns_mode = atoi(optarg);
    switch(dns_mode) {
    case 0:
      break;
    case 1:
      resolve_all_hosts();
      break;
    case 2:
      disable_dns_resolution();
      break;
    case 3:
      disable_dns_resolution();
      disable_dns_responses_decoding();
      break;
    default:
      help();
    }
    break;

  case 'p':
    ndpi_proto_path = strdup(optarg);
    ntop->setCustomnDPIProtos(ndpi_proto_path);
    break;

  case 'q':
    enable_auto_logout = false;
    break;

  case 'P':
    disable_host_persistency = true;
    break;

  case 'h':
    help();
    break;

  case 'i':
    if(num_interfaces < (MAX_NUM_INTERFACES-1))
      ifNames[num_interfaces++] = strdup(optarg);
    else
      ntop->getTrace()->traceEvent(TRACE_ERROR, "Too many interfaces: discarded %s", optarg);
    break;

  case 'w':
    http_port = atoi(optarg);
    break;

  case 'W':
    https_port = atoi(optarg);
    break;

  case 'r':
    {
      char buf[64], *r;

      snprintf(buf, sizeof(buf), "%s", optarg);
      r = strtok(buf, ":");
      if(r) {
	char *c = strtok(NULL, ":");
	if(c) redis_port = atoi(c);

	if(redis_host) free(redis_host);
	redis_host = strdup(r);
      }
    }
    break;

  case 's':
    change_user = false;
    break;

  case '1':
    free(docs_dir);
    docs_dir = strdup(optarg);
    break;

  case '2':
    free(scripts_dir);
    scripts_dir = strdup(optarg);
    break;

  case '3':
    free(callbacks_dir);
    callbacks_dir = strdup(optarg);
    break;

  case 'l':
    enable_users_login = false;
    break;

  case 'x':
    max_num_hosts = max_val(atoi(optarg), 1024);
    break;

  case 'v':
    ntop->getTrace()->set_trace_level(MAX_TRACE_LEVEL);
    break;

  case 'F':
    dump_flows_on_db = true;
    break;

#ifndef WIN32
  case 'G':
    pid_path = strdup(optarg);
    break;
#endif

  case 'H':
    disable_alerts = true;
    break;

  case 'U':
    free(user);
    user = strdup(optarg);
    break;

  case 'X':
    max_num_flows = max_val(atoi(optarg), 1024);
    break;

  default:
    ntop->getTrace()->traceEvent(TRACE_WARNING, "Unknown option -%c: Ignored.", (char)optkey);
    return(-1);
  }

  return(0);
}
Esempio n. 20
0
int main()
{
    int i, j;
    int mv[MAX_SETS];
    int bval, bpos, bcount, blen;

    while (scanf("%d", &size), size > 0)
    {
        scanf("%d", &n);

        for (i = 0; i < n; i++)
        {
            scanf("%d", &set_size[i]);
            for (j = 0; j < set_size[i]; j++)
                scanf("%d", &set[i][j]);
        }

        bcount = bval = 0;

        bpos = -1;

        for (i = 0; i < n; i++)
        {
            mv[i] = max_val (i);

            if (mv[i] > bval)
            {
                bval = mv[i];
                bpos = i;
                bcount = 1;
            }
            else if (mv[i] == bval)
                bcount++;
        }

        if (bcount != 1)
        {
            blen = size + 1;

            for (i = 0; i < n; i++)
            {
                if (mv[i] != bval)
                    continue;

                if (set_size[i] < blen)
                {
                    blen = set_size[i];
                    bpos = i;
                    bcount = 1;
                }
                else if (set_size[i] == blen)
                    bcount++;
            }
        }

        if (bcount != 1)
        {
            int bestlast;

            bestlast = MAX_VALUE + 1;

            for (i = 0; i < n; i++)
            {
                if (mv[i] != bval || set_size[i] != blen)
                    continue;

                if (set[i][blen-1] < bestlast)
                {
                    bestlast = set[i][blen-1];
                    bpos = i;
                    bcount = 1;
                }
                else if (set[i][blen-1] == bestlast)
                    bcount++;
            }
        }

        printf ("max coverage =%4d :", mv[bpos]);

        for (i=0; i < set_size[bpos]; i++)
            printf ("%3d", set[bpos][i]);
        printf ("\n");
    }

    return 0;
}
Esempio n. 21
0
/*!\brief TODO
//
// \param A TODO
// \param b TODO
// \param x TODO
// \return TODO
// \exception std::invalid_argument Invalid matrix size.
// \exception std::invalid_argument Invalid right-hand side vector size.
//
// TODO: description
// TODO: problem formulation \f$ A \cdot x + b = 0 \f$ !!
*/
bool GaussianElimination::solve( const CMatMxN& A, const VecN& b, VecN& x )
{
   if( A.rows() != A.columns() )
      throw std::invalid_argument( "Invalid matrix size" );

   if( A.rows() != b.size() )
      throw std::invalid_argument( "Invalid right-hand side vector size" );

   const size_t n( b.size() );

   // Allocating helper data
   A_ =  A;
   b_ = -b;
   x.resize( n, false );

   size_t pi, pj;
   lastPrecision_ = real(0);

   // Initializing the pivot vector
   DynamicVector<size_t> p( n );
   for( size_t j=0; j<n; ++j ) {
      p[j] = j;
   }

   // Performing the Gaussian elimination
   for( size_t j=0; j<n; ++j )
   {
      size_t max( j );
      real max_val( std::fabs( A_(p[max],j) ) );

      // Partial search for pivot
      for( size_t i=j+1; i<n; ++i ) {
         if( std::fabs( A_(p[i],j) ) > max_val ) {
            max = i;
            max_val = std::fabs( A_(p[max],j) );
         }
      }

      // Swapping rows such the pivot lies on the diagonal
      std::swap( p[max], p[j] );
      pj = p[j];

      if( !isDefault( A_(pj,j) ) )
      {
         // Eliminating the column below the diagonal
         for( size_t i=j+1; i<n; ++i )
         {
            pi = p[i];
            const real f = A_(pi,j) / A_(pj,j);

            reset( A_(pi,j) );

            for( size_t k=j+1; k<n; ++k ) {
               A_(pi,k) -= A_(pj,k) * f;
            }

            b_[pi] -= b_[pj] * f;
         }
      }
      else {
         // Asserting that the column is zero below the diagonal
         for( size_t i=j+1; i<n; ++i ) {
            BLAZE_INTERNAL_ASSERT( isDefault( A_(p[i],j) ), "Fatal error in Gaussian elimination" );
         }
      }
   }

   // Performing the backward substitution
   for( size_t i=n-1; i<n; --i )
   {
      pi = p[i];
      real rhs = b_[pi];

      for( size_t j=i+1; j<n; ++j ) {
         rhs -= x[j] * A_(pi,j);
      }

      if( std::fabs( A_(pi,i) ) > accuracy ) {
         x[i] = rhs / A_(pi,i);
      }
      else {
         // This will introduce errors in the solution
         reset( x[i] );
         lastPrecision_ = max( lastPrecision_, std::fabs( rhs ) );
      }
   }

   BLAZE_LOG_DEBUG_SECTION( log ) {
      if( lastPrecision_ < threshold_ )
         log << "      Solved the linear system using Gaussian elimination.";
      else
         log << BLAZE_YELLOW << "      WARNING: Did not solve the linear system within accuracy. (" << lastPrecision_ << ")" << BLAZE_OLDCOLOR;
   }

   lastIterations_ = 1;

   return lastPrecision_ < threshold_;
}
Esempio n. 22
0
void LH_MonitoringDial::updateBounds()
{
    bool ok;
    SensorGroup *group = this->selectedSensorGroup(&ok);

    qreal _max = setup_max_->value();
    qreal _min = setup_min_->value();

    bool minExists = false;
    bool maxExists = false;

    if(ok)
    {
        minExists = group->limits.minimum.exists;
        if(group->limits.minimum.exists)
        {
            _min = group->limits.minimum.value;
            setup_min_->setValue(_min);
        }

        maxExists = group->limits.maximum.exists;
        if(group->limits.maximum.exists)
        {
            _max = group->limits.maximum.value;
            setup_max_->setValue(_max);
        }
    }

    setMax(_max);
    setMin(_min);

    //qDebug() << "Min: " << ok << "; minExists: " << minExists << "; min=" << _min << "; min_val():" << min_val() << "; setup_min_:" << setup_min_->value() << "; actual=set:" << (setup_min_->value() == min_val());
    //qDebug() << "Max: " << ok << "; maxExists: " << maxExists << "; max=" << _max << "; max_val():" << max_val() << "; setup_max_:" << setup_max_->value() << "; actual=set:" << (setup_max_->value() == max_val());

    bool _visible = (!minExists || setup_min_->value() == min_val()) && (!maxExists || setup_max_->value() == max_val());
    setup_min_->setVisible(_visible);
    setup_max_->setVisible(_visible);
    setup_minmax_hr_->setVisible(_visible);

    requestRender();
}
Esempio n. 23
0
File: main.cpp Progetto: CCJY/coliru
	static void sync_max(T e) { if (e > max_val()) max_val() = int(e); }
Esempio n. 24
0
File: main.cpp Progetto: CCJY/coliru
	static int max() { return max_val(); }
Esempio n. 25
0
//read the PPM image from fname
void ppm::read(const std::string &fname) {
    std::ifstream inp(fname.c_str(), std::ios::in | std::ios::binary);
    if (inp.is_open()) {
        std::string line;
        std::getline(inp, line);
        if (line != "P6") {
        	std::stringstream msg;
        	msg << "Unrecognized file format (file: " << fname << ")";
        	tracepoint(com_vanwinkeljan_lttng_test_ppm,
        			error_message,
        			msg.str().c_str());
            return;
        }
        std::getline(inp, line);
        while (line[0] == '#') {
            std::getline(inp, line);
        }
        std::stringstream dimensions(line);

        try {
            dimensions >> width;
            dimensions >> height;
            nr_lines = height;
            nr_columns = width;
        } catch (std::exception &e) {
        	std::stringstream msg;
        	msg << "Header file format error (file: " << fname << ")" << e.what();
        	tracepoint(com_vanwinkeljan_lttng_test_ppm,
        			error_message,
        			msg.str().c_str());
        	return;
        }

        std::getline(inp, line);
        std::stringstream max_val(line);
        try {
            max_val >> max_col_val;
        } catch (std::exception &e) {
        	std::stringstream msg;
        	msg << "Header file format error (file: " << fname << ")" << e.what();
        	tracepoint(com_vanwinkeljan_lttng_test_ppm,
        			error_message,
        			msg.str().c_str());
            return;
        }

        size = width*height;

        r.reserve(size);
        g.reserve(size);
        b.reserve(size);

        char aux;
        for (unsigned int i = 0; i < size; ++i) {
            inp.read(&aux, 1);
            r[i] = (unsigned char) aux;
            inp.read(&aux, 1);
            g[i] = (unsigned char) aux;
            inp.read(&aux, 1);
            b[i] = (unsigned char) aux;
        }
    } else {
Esempio n. 26
0
NetworkInterface::NetworkInterface(const char *name) {
  char pcap_error_buffer[PCAP_ERRBUF_SIZE];
  NDPI_PROTOCOL_BITMASK all;
  u_int32_t num_hashes;
  char _ifname[64];

#ifdef WIN32
  if(name == NULL) name = "1"; /* First available interface */
#endif

  purge_idle_flows_hosts = true;

  if(name == NULL) {
    if(!help_printed)
      ntop->getTrace()->traceEvent(TRACE_WARNING, "No capture interface specified");

    printAvailableInterfaces(false, 0, NULL, 0);

    name = pcap_lookupdev(pcap_error_buffer);

    if(name == NULL) {
      ntop->getTrace()->traceEvent(TRACE_ERROR,
				   "Unable to locate default interface (%s)\n",
				   pcap_error_buffer);
      exit(0);
    }
  } else {
    if(isNumber(name)) {
      /* We need to convert this numeric index into an interface name */
      int id = atoi(name);

      _ifname[0] = '\0';
      printAvailableInterfaces(false, id, _ifname, sizeof(_ifname));

      if(_ifname[0] == '\0') {
	ntop->getTrace()->traceEvent(TRACE_WARNING, "Unable to locate interface Id %d", id);
	printAvailableInterfaces(false, 0, NULL, 0);
	exit(0);
      }
      name = _ifname;
    }
  }

  ifname = strdup(name);

  num_hashes = max_val(4096, ntop->getPrefs()->get_max_num_flows()/4);
  flows_hash = new FlowHash(this, num_hashes, ntop->getPrefs()->get_max_num_flows());

  num_hashes = max_val(4096, ntop->getPrefs()->get_max_num_hosts()/4);
  hosts_hash = new HostHash(this, num_hashes, ntop->getPrefs()->get_max_num_hosts());
  strings_hash = new StringHash(this, num_hashes, ntop->getPrefs()->get_max_num_hosts());

  // init global detection structure
  ndpi_struct = ndpi_init_detection_module(ntop->getGlobals()->get_detection_tick_resolution(),
					   malloc_wrapper, free_wrapper, debug_printf);
  if(ndpi_struct == NULL) {
    ntop->getTrace()->traceEvent(TRACE_ERROR, "Global structure initialization failed");
    exit(-1);
  }

  if(ntop->getCustomnDPIProtos() != NULL)
    ndpi_load_protocols_file(ndpi_struct, ntop->getCustomnDPIProtos());

  ndpi_port_range d_port[MAX_DEFAULT_PORTS];
  memset(d_port, 0, sizeof(d_port));
  ndpi_set_proto_defaults(ndpi_struct, NTOPNG_NDPI_OS_PROTO_ID,
			  (char*)"Operating System", d_port, d_port);


  // enable all protocols
  NDPI_BITMASK_SET_ALL(all);
  ndpi_set_protocol_detection_bitmask2(ndpi_struct, &all);

  last_pkt_rcvd = 0;
  next_idle_flow_purge = next_idle_host_purge = next_idle_aggregated_host_purge = 0;
  cpu_affinity = -1;
  running = false;

#ifdef HAVE_SQLITE
  db = new DB(this);
#endif
}
Esempio n. 27
0
int main(void)
{
        return max_val({1,2});
}
Esempio n. 28
0
template <typename PointInT, typename PointOutT> void 
pcl::SIFTKeypoint<PointInT, PointOutT>::findScaleSpaceExtrema (
    const PointCloudIn &input, KdTree &tree, const Eigen::MatrixXf &diff_of_gauss, 
    std::vector<int> &extrema_indices, std::vector<int> &extrema_scales)
{
  const int k = 25;
  std::vector<int> nn_indices (k);
  std::vector<float> nn_dist (k);

  const int nr_scales = static_cast<int> (diff_of_gauss.cols ());
  std::vector<float> min_val (nr_scales), max_val (nr_scales);

  for (int i_point = 0; i_point < static_cast<int> (input.size ()); ++i_point)
  {
    // Define the local neighborhood around the current point
    const size_t nr_nn = tree.nearestKSearch (i_point, k, nn_indices, nn_dist); //*
    // * note: the neighborhood for finding local extrema is best defined as a small fixed-k neighborhood, regardless of
    //   the configurable search method specified by the user, so we directly employ tree.nearestKSearch here instead 
    //   of using searchForNeighbors

    // At each scale, find the extreme values of the DoG within the current neighborhood
    for (int i_scale = 0; i_scale < nr_scales; ++i_scale)
    {
      min_val[i_scale] = std::numeric_limits<float>::max ();
      max_val[i_scale] = -std::numeric_limits<float>::max ();

      for (size_t i_neighbor = 0; i_neighbor < nr_nn; ++i_neighbor)
      {
        const float &d = diff_of_gauss (nn_indices[i_neighbor], i_scale);

        min_val[i_scale] = (std::min) (min_val[i_scale], d);
        max_val[i_scale] = (std::max) (max_val[i_scale], d);
      }
    }

    // If the current point is an extreme value with high enough contrast, add it as a keypoint 
    for (int i_scale = 1; i_scale < nr_scales - 1; ++i_scale)
    {
      const float &val = diff_of_gauss (i_point, i_scale);

      // Does the point have sufficient contrast?
      if (fabs (val) >= min_contrast_)
      {
        // Is it a local minimum?
        if ((val == min_val[i_scale]) && 
            (val <  min_val[i_scale - 1]) && 
            (val <  min_val[i_scale + 1]))
        {
          extrema_indices.push_back (i_point);
          extrema_scales.push_back (i_scale);
        }
        // Is it a local maximum?
        else if ((val == max_val[i_scale]) && 
                 (val >  max_val[i_scale - 1]) && 
                 (val >  max_val[i_scale + 1]))
        {
          extrema_indices.push_back (i_point);
          extrema_scales.push_back (i_scale);
        }
      }
    }
  }
}