コード例 #1
0
ファイル: ctcp_profile.cpp プロジェクト: Columbitech/rohc
 void CTCPProfile::Compress(const data_t &data, data_t &output) {
     size_t outputInSize = output.size();
     const iphdr* ip = reinterpret_cast<const iphdr*>(&data[0]);
     const tcphdr* tcp = reinterpret_cast<const tcphdr*>(ip+ip->ihl*4);
     
     UpdateIpIdOffset(ip);
     
     if (IR_State == state)
     {
         CreateIR(ip, tcp, output);
     }
     else
     {
         CreateCO(ip, tcp, output);
     }
     
     UpdateIpInformation(ip);
     
     AdvanceState(false, false);
     increaseMsn();
     // Append payload
     // TODO, handle TCP options
     output.insert(output.end(), data.begin() + sizeof(iphdr) + sizeof(tcphdr), data.end());
     
     ++numberOfPacketsSent;
     dataSizeCompressed += output.size() - outputInSize;
     dataSizeUncompressed += data.size();
     
 }
コード例 #2
0
	bool bin_index_t::dir_node::next(data_t& key,data_t& val) const
	{
		validate_key_len(key);
		validate_index();
		
		data_t head(key.begin(),key.begin()+parent.dir_key_len);
		data_t tail(key.begin()+parent.dir_key_len,key.end());

		datas_t::const_iterator it=std::lower_bound(indexes.begin(),indexes.end(),head,data_less_pr());
		if(it==indexes.end())return false;

		if(*it==head)
		{
			validate_sub(head);
			if(sub_node->next(tail,val))
			{
				key=head;
				key.insert(key.end(),tail.begin(),tail.end());
				return true;
			}
		}

		++it;
		if(it==indexes.end())return false;
		head=*it;

		validate_sub(head);
		if(!sub_node->first(tail,val))return false;

		key=head;
		key.insert(key.end(),tail.begin(),tail.end());
		return true;
	}
コード例 #3
0
ファイル: duncomp_profile.cpp プロジェクト: Columbitech/rohc
 void
 DUncompressedProfile::ParseCO(uint8_t packetTypeIndication, data_t &data, data_iterator pos, data_t &output)
 {
     // pti is first byte of IP
     output.push_back(packetTypeIndication);
     // data contains the rest
     output.insert(output.end(), pos, data.end());
     ++numberOfPacketsReceived;
     dataSizeCompressed += distance(pos, data.end()) + 1;
     dataSizeUncompressed += distance(pos, data.end()) + 1;
 }
コード例 #4
0
ファイル: kd-tree.cpp プロジェクト: ssxiexiao/kd-tree
double variation(data_t &dataset, size_t split){
	data_t::iterator i;
	double mean = 0;
	double variation = 0;
	for (i = dataset.begin(); i != dataset.end(); i++){
		mean += i->at(split);
	}
	mean /= dataset.size();
	for (i = dataset.begin(); i != dataset.end(); i++){
		variation += pow(i->at(split) - mean, 2.0);
	}
	variation /= dataset.size();
	return variation;
}
コード例 #5
0
void session_interface::save_data(data_t const &data,std::string &s)
{
    s.clear();
    data_t::const_iterator p;
    for(p=data.begin(); p!=data.end(); ++p) {
        packed header(p->first.size(),p->second.exposed,p->second.value.size());
        char *ptr=(char *)&header;
        s.append(ptr,ptr+sizeof(header));
        s.append(p->first.begin(),p->first.end());
        s.append(p->second.value.begin(),p->second.value.end());
    }
}
コード例 #6
0
///////////////////////////////////////////////////////////////////////////////////
//  dir_node
//
	bool bin_index_t::dir_node::get(const data_t& key,data_t& val) const
	{
		validate_key_len(key);
		validate_index();
		
		data_t head(key.begin(),key.begin()+parent.dir_key_len);
		data_t tail(key.begin()+parent.dir_key_len,key.end());

		if(!std::binary_search(indexes.begin(),indexes.end(),head,data_less_pr()))
			return false;

		validate_sub(head);

		return sub_node->get(tail,val);
	}
コード例 #7
0
	bool bin_index_t::dir_node::set(const data_t& key,const data_t& val)
	{
		validate_key_len(key);
		validate_index();

		data_t head(key.begin(),key.begin()+parent.dir_key_len);
		data_t tail(key.begin()+parent.dir_key_len,key.end());

		bool already_exists=std::binary_search(indexes.begin(),indexes.end(),head,data_less_pr());

        if(!already_exists)create_text_child(head);
		validate_sub(head);

		bool r=sub_node->set(tail,val);
		return r;
	}
コード例 #8
0
	bool bin_index_t::dir_node::first(data_t& key,data_t& val) const
	{
		validate_index();

		if(indexes.empty())return false;

		const data_t& head=indexes.front();
		validate_sub(head);

		data_t tail;
		if(!sub_node->first(tail,val))return false;
		
		key=head;
		key.insert(key.end(),tail.begin(),tail.end());

		return true;
	}
コード例 #9
0
ファイル: kd-tree.cpp プロジェクト: ssxiexiao/kd-tree
void construct(point &root, data_t dataset){
	if (dataset.size() == 0)
		return;
	root = new point_t();
	vector< double > buff;
	for (size_t i = 0; i < dataset.at(0).size(); i++){
		buff.push_back(variation(dataset, i));
	}
	size_t split = 0;
	double min;
	for (size_t i = 0; i < buff.size(); i++){
		if (i == 0){
			min = buff.at(i);
		}
		else{
			if (min < buff.at(i)){
				min = buff.at(i);
				split = i;
			}
		}
	}
	sort(dataset.begin(), dataset.end(), [split](vec_t a, vec_t b){ return a.at(split) < b.at(split); });
	size_t middle = dataset.size() / 2;
	root->split = split;
	for (size_t i = 0; i < dataset.at(middle).size(); i++){
		root->node.push_back(dataset.at(middle).at(i));
	}
	root->dim = root->node.size();
	data_t lDataset, rDataset;
	for (size_t i = 0; i < middle; i++){
		lDataset.push_back(dataset.at(i));
	}
	for (size_t i = middle + 1; i < dataset.size(); i++){
		rDataset.push_back(dataset.at(i));
	}
	construct(root->left, lDataset);
	construct(root->right, rDataset);
	if (root->left)
		root->left->parent = root;
	if (root->right)
		root->right->parent = root;
	return;
}
コード例 #10
0
//min-max splits based on impurity measure
bool impurity_splitW_noMiss(data_t data,  int& f_split, double& v_split,  double imp, boost::numeric::ublas::vector<int>& c_total,args_t& myargs, double (*impurityHandle)(int, boost::numeric::ublas::vector<int>&,double)) {
	int NF=myargs.features;
	int num_c=myargs.num_c;
	double alpha=myargs.alpha;
	f_split = -1;
	double min = MY_DBL_MAX, cf;
	int n = data.size(), i,j ;
	double imp_l=0.0, imp_r=0.0, imp_m=0.0, imp_max=0.0; //impurity on the left

	double mind;
	double v_split_d;
	for (int f = 1; f < NF; f++) { //for each feature
		cf=myargs.Costs[f];
		sort(data.begin(), data.end(), boost::bind(mysortf, _1,_2, f));
		boost::numeric::ublas::vector<int> c_l(num_c,0); //number of examples in each class on the left
		boost::numeric::ublas::vector<int> c_r(c_total); //number of examples in each class on the right
		
		mind = MY_DBL_MAX;
		//assume no missing data
		for( i=0;i<n-1;i++){
			c_l[data[i]->label]++;
			c_r[data[i]->label]--;
			// do not consider splitting here if data is the same as next
			if (data[i]->features[f] == data[i+1]->features[f])
				continue;
			imp_l=(*impurityHandle)(num_c, c_l, alpha);
			imp_r=(*impurityHandle)(num_c, c_r, alpha);
			imp_max=(imp_l < imp_r) ? imp_r: imp_l;
			if(imp_max<mind){
				mind=imp_max;
				v_split_d = (data[i]->features[f] + data[i+1]->features[f])/2;
			}
		}

		if ((imp-mind>0.0000001) && (cf/(imp-mind) < min)) {
			min = cf/(imp-mind);
			f_split = f;
			v_split = v_split_d;
		}
	}	
	return min != MY_DBL_MAX;
}
コード例 #11
0
        std::string encode(const data_t& data) const {
            auto end = reinterpret_cast<const uint8_t*>(&*data.end());
            uint8_t tmp[base_t::digits_per_unit];
            char out[base_t::digits_per_unit];

            std::string text;
            text.reserve(this->estimate(data.size()));
            auto in = reinterpret_cast<const uint8_t*>(data.data());
            size_t n = 0;
            while (in < end) {
                n = this->stretch(in, tmp, end);
                for (size_t i = 0; i < n; ++i) {
                    out[i] = this->digit(tmp[i]);
                }
                text.append(out, n);
            }
            if (this->padding and n != 0 and n != sizeof(out)) {
                text.append(sizeof(out) - n, '=');
            }
            return text;
        }
コード例 #12
0
ファイル: ctcp_profile.cpp プロジェクト: Columbitech/rohc
    void CTCPProfile::CreateIR(const ROHC::iphdr *ip, const ROHC::tcphdr *tcp, data_t &output) {
        size_t headerStartIdx = output.size();
        
        if (!largeCID && cid)
        {
            output.push_back(CreateShortCID(cid));
        }
        
        output.push_back(IRv2Packet);
        
        if (largeCID)
        {
            SDVLEncode(back_inserter(output), cid);
        }
        
        output.push_back(static_cast<uint8_t>(ProfileID()));
        
        size_t crcPos = output.size();
        
        // Add zero crc for now
        output.push_back(0);
        
        create_ipv4_static(ip, output);
        
        create_tcp_static(tcp, output);
        
        create_ipv4_regular_innermost_dynamic(ip, output);
        
        //create_tcp_dynamic(msn, reorder_ratio, udp, output);
        
        // Calculate CRC
        uint8_t crc = CRC8(output.begin() + headerStartIdx, output.end());
        output[crcPos] = crc;
        
		IncreasePacketCount(PT_IR);
        
        ++numberOfIRPacketsSent;
        ++numberOfIRPacketsSinceReset;
    }
コード例 #13
0
	void bin_index_t::file_node::align_key(const data_t& key,index_t& res) const
	{
		res.key.resize(aligned_key_len);
		std::copy(key.begin(),key.end(),res.key.begin());
		std::fill(res.key.begin()+key_len,res.key.end(),0);
	}
コード例 #14
0
ファイル: Boundary.hpp プロジェクト: biochem-fan/cuemol2
 iterator end() { return m_verts.end(); }
コード例 #15
0
ファイル: Boundary.hpp プロジェクト: biochem-fan/cuemol2
 const_iterator end() const { return m_verts.end(); }
コード例 #16
0
ファイル: secure_cell.hpp プロジェクト: neuroradiology/themis
 secure_cell_t(const data_t& password):
   _password(password.begin(), password.end()),
   _res(0){}