Exemplo n.º 1
0
uint64_t SerializedBuffer::compute_hash() const noexcept {
	static const int HASH_BASE = 1000000007;
	uint64_t hash = 0;
	if(is_grouped()){
		const auto kd = reinterpret_cast<const uint8_t *>(keys_data());
		const auto ko = keys_offsets();
		const auto vd = reinterpret_cast<const uint8_t *>(values_data());
		const auto vo = values_offsets();
		const auto vgo = value_group_offsets();
		for(identifier_type gi = 0, vi = 0; gi < group_count(); ++gi){
			uint64_t ghash = compute_partial_hash(kd + ko[gi], ko[gi + 1] - ko[gi]);
			while(vo[vi] < vgo[gi + 1]){
				ghash ^= compute_partial_hash(vd + vo[vi], vo[vi + 1] - vo[vi]);
				++vi;
			}
			hash = (hash * HASH_BASE) + ghash;
		}
	}else if(m_values_key_lengths){
		const auto vd = reinterpret_cast<const uint8_t *>(values_data());
		const auto vo = values_offsets();
		for(identifier_type i = 0; i < record_count(); ++i){
			hash ^=
				compute_partial_hash(vd + vo[i], vo[i + 1] - vo[i]) * HASH_BASE +
				m_values_key_lengths[i];
		}
	}else{
		const auto vd = reinterpret_cast<const uint8_t *>(values_data());
		const auto vo = values_offsets();
		for(identifier_type i = 0; i < record_count(); ++i){
			hash ^= compute_partial_hash(vd + vo[i], vo[i + 1] - vo[i]);
		}
	}
	return hash;
}
Exemplo n.º 2
0
void tool_wind_fill_group_combo(void)
{
	int					n,group_idx;
	char				str[256];
	CFStringRef			cf_str;
	HMHelpContentRec	tag;
	
		// old settings
		
	group_idx=GetControl32BitValue(group_combo);
	
		// delete old control and menu
		
	DisposeControl(group_combo);
	
	DeleteMenu(160);
	DisposeMenu(group_menu);
	
		// recreate the menu
		
	CreateNewMenu(group_combo_menu_id,0,&group_menu);
	
	cf_str=CFStringCreateWithCString(kCFAllocatorDefault,"No Group",kCFStringEncodingMacRoman);
	AppendMenuItemTextWithCFString(group_menu,cf_str,0,FOUR_CHAR_CODE('gp01'),NULL);
	CFRelease(cf_str);
	
	AppendMenuItemTextWithCFString(group_menu,NULL,kMenuItemAttrSeparator,0,NULL);
	
	for (n=0;n<map.ngroup;n++) {
		sprintf(str,"%s (%d)",map.groups[n].name,group_count(n));
		cf_str=CFStringCreateWithCString(kCFAllocatorDefault,str,kCFStringEncodingMacRoman);
		AppendMenuItemTextWithCFString(group_menu,cf_str,0,FOUR_CHAR_CODE('gp03'),NULL);
		CFRelease(cf_str);
	}
	
	InsertMenu(group_menu,kInsertHierarchicalMenu);
	
		// recreate the contorl
		
	CreatePopupButtonControl(toolwind,&group_box,NULL,group_combo_menu_id,FALSE,0,0,0,&group_combo);
	Draw1Control(group_combo);
	
		// build the help
	
	tag.version=kMacHelpVersion;
	tag.tagSide=kHMDefaultSide;
	SetRect(&tag.absHotRect,0,0,0,0);
	tag.content[kHMMinimumContentIndex].contentType=kHMCFStringContent;
	tag.content[kHMMinimumContentIndex].u.tagCFString=CFStringCreateWithCString(NULL,"Segment Groups",kCFStringEncodingMacRoman);
	tag.content[kHMMaximumContentIndex].contentType=kHMNoContent;
		
	HMSetControlHelpContent(group_combo,&tag);
	
		// reset the control
		
	SetControl32BitValue(group_combo,group_idx);
}
Exemplo n.º 3
0
/// Set the mole fractions of the components in the mixtures (not the groups)
void UNIFAC::UNIFACMixture::set_mole_fractions(const std::vector<double> &z) {
//    // If the vector fractions are the same as last ones, don't do anything and return
//    if (!mole_fractions.empty() && maxvectordiff(z, mole_fractions) < 1e-15){
//        return;
//    }
    this->mole_fractions = z;
    if (this->N != z.size()) {
        throw CoolProp::ValueError("Size of molar fraction do not match number of components.");
    }
    
    std::map<std::size_t, double> &Xg = m_Xg, &thetag = m_thetag;
    Xg.clear(); thetag.clear();
    
    // Iterate over the fluids
    double X_summer = 0;
    for (std::size_t i = 0; i < this->mole_fractions.size(); ++i) {
        X_summer += this->mole_fractions[i] * pure_data[i].group_count;
    }
    /// Calculations for each group in the total mixture
    for (std::vector<UNIFACLibrary::Group>::iterator it = unique_groups.begin(); it != unique_groups.end(); ++it){
        double X = 0;
        // Iterate over the fluids
        for (std::size_t i = 0; i < this->mole_fractions.size(); ++i) {
            X += this->mole_fractions[i]*group_count(i, it->sgi);
        }
        Xg.insert(std::pair<std::size_t, double>(it->sgi, X));
    }
    /// Now come back through and divide by the sum(z_i*count) for this fluid
    for (std::map<std::size_t, double>::iterator it = Xg.begin(); it != Xg.end(); ++it) {
        it->second /= X_summer;
        //printf("X_{%d}: %g\n", it->first, it->second);
    }
    double theta_summer = 0;
    for (std::vector<UNIFACLibrary::Group>::iterator it = unique_groups.begin(); it != unique_groups.end(); ++it) {
        double cont = Xg.find(it->sgi)->second * it->Q_k;
        theta_summer += cont;
        thetag.insert(std::pair<std::size_t, double>(it->sgi, cont));
    }
    /// Now come back through and divide by the sum(X*Q) for this fluid
    for (std::map<std::size_t, double>::iterator it = thetag.begin(); it != thetag.end(); ++it) {
        it->second /= theta_summer;
        //printf("theta_{%d}: %g\n", it->first, it->second);
    }
}
Exemplo n.º 4
0
double UNIFAQ::UNIFAQMixture::ln_gamma_R(const double tau, std::size_t i, std::size_t itau){
    if (itau == 0) {
        set_temperature(T_r / tau);
        double summer = 0;
        for (std::vector<UNIFAQLibrary::Group>::const_iterator it = unique_groups.begin(); it != unique_groups.end(); ++it) {
            std::size_t k = it->sgi;
            std::size_t count = group_count(i, k);
            if (count > 0){
                summer += count*(m_lnGammag.find(k)->second - pure_data[i].lnGamma.find(k)->second);
            }
        }
        //printf("log(gamma)_{%d}: %g\n", i+1, summer);
        return summer;
    }
    else {
        double dtau = 0.01*tau;
        return (ln_gamma_R(tau + dtau, i, itau - 1) - ln_gamma_R(tau - dtau, i, itau - 1)) / (2 * dtau);
    }
}
Exemplo n.º 5
0
/// Set the mole fractions of the components in the mixtures (not the groups)
void UNIFAQ::UNIFAQMixture::set_mole_fractions(const std::vector<double> &z) {
//    // If the vector fractions are the same as last ones, don't do anything and return
//    if (!mole_fractions.empty() && maxvectordiff(z, mole_fractions) < 1e-15){
//        return;
//    }
    pure_data.clear();
    this->mole_fractions = z;
    std::size_t N = z.size();
    
    /// Calculate the parameters X and theta for the pure components, which does not depend on temperature
    for (std::size_t i = 0; i < N; ++i){
        int totalgroups = 0;
        const UNIFAQLibrary::Component &c = components[i];
        ComponentData cd;
        double summerxq = 0;
        cd.group_count = 0;
        for (std::size_t j = 0; j < c.groups.size(); ++j) {
            const UNIFAQLibrary::ComponentGroup &cg = c.groups[j];
            double x = static_cast<double>(cg.count);
            double theta = static_cast<double>(cg.count*cg.group.Q_k);
            cd.X.insert( std::pair<int,double>(cg.group.sgi, x) );
            cd.theta.insert(std::pair<int, double>(cg.group.sgi, theta));
            cd.group_count += cg.count;
            totalgroups += cg.count;
            summerxq += x*cg.group.Q_k;
        }
        /// Now come back through and divide by the total # groups for this fluid
        for (std::map<std::size_t, double>::iterator it = cd.X.begin(); it != cd.X.end(); ++it) {
            it->second /= totalgroups;
            //printf("X^(%d)_{%d}: %g\n", static_cast<int>(i + 1), static_cast<int>(it->first), it->second);
        }
        /// Now come back through and divide by the sum(X*Q) for this fluid
        for (std::map<std::size_t,double>::iterator it = cd.theta.begin(); it != cd.theta.end(); ++it){
            it->second /= summerxq;
            //printf("theta^(%d)_{%d}: %g\n", static_cast<int>(i+1), static_cast<int>(it->first), it->second);
        }
        pure_data.push_back(cd);
    }
    for (std::size_t i = 0; i < N; ++i) {
        //printf("%g %g %g %g %g %g\n", l[i], phi[i], q[i], r[i], theta[i], ln_Gamma_C[i]);
    }
    
    std::map<std::size_t, double> &Xg = m_Xg, &thetag = m_thetag;
    Xg.clear(); thetag.clear();
    
    // Iterate over the fluids
    double X_summer = 0;
    for (std::size_t i = 0; i < this->mole_fractions.size(); ++i) {
        X_summer += this->mole_fractions[i] * pure_data[i].group_count;
    }
    /// Calculations for each group in the total mixture
    for (std::vector<UNIFAQLibrary::Group>::iterator it = unique_groups.begin(); it != unique_groups.end(); ++it){
        double X = 0;
        // Iterate over the fluids
        for (std::size_t i = 0; i < this->mole_fractions.size(); ++i) {
            X += this->mole_fractions[i]*group_count(i, it->sgi);
        }
        Xg.insert(std::pair<std::size_t, double>(it->sgi, X));
    }
    /// Now come back through and divide by the sum(z_i*count) for this fluid
    for (std::map<std::size_t, double>::iterator it = Xg.begin(); it != Xg.end(); ++it) {
        it->second /= X_summer;
        //printf("X_{%d}: %g\n", it->first, it->second);
    }
    double theta_summer = 0;
    for (std::vector<UNIFAQLibrary::Group>::iterator it = unique_groups.begin(); it != unique_groups.end(); ++it) {
        double cont = Xg.find(it->sgi)->second * it->Q_k;
        theta_summer += cont;
        thetag.insert(std::pair<std::size_t, double>(it->sgi, cont));
    }
    /// Now come back through and divide by the sum(X*Q) for this fluid
    for (std::map<std::size_t, double>::iterator it = thetag.begin(); it != thetag.end(); ++it) {
        it->second /= theta_summer;
        //printf("theta_{%d}: %g\n", it->first, it->second);
    }
}
Exemplo n.º 6
0
void pins_model_init(model_t m) {

    // create the LTS type LTSmin will generate
    lts_type_t ltstype=lts_type_create();

    // set the length of the state
    lts_type_set_state_length(ltstype, state_length());

    // add an "int" type for a state slot
    int int_type = lts_type_add_type(ltstype, "int", NULL);
    lts_type_set_format (ltstype, int_type, LTStypeDirect);

    // add an "action" type for edge labels
    int action_type = lts_type_add_type(ltstype, "action", NULL);
    lts_type_set_format (ltstype, action_type, LTStypeEnum);

    // add a "bool" type for state labels
    int bool_type = lts_type_add_type (ltstype, LTSMIN_TYPE_BOOL, NULL);
    lts_type_set_format(ltstype, bool_type, LTStypeEnum);

    // set state name & type
    for (int i=0; i < state_length(); ++i) {
        char name[3]; sprintf(name, "%d", i);
        lts_type_set_state_name(ltstype,i,name);
        lts_type_set_state_typeno(ltstype,i,int_type);
    }

    // edge label types
    lts_type_set_edge_label_count (ltstype, 1);
    lts_type_set_edge_label_name(ltstype, 0, "action");
    lts_type_set_edge_label_type(ltstype, 0, "action");
    lts_type_set_edge_label_typeno(ltstype, 0, action_type);

    // state label types
    lts_type_set_state_label_count (ltstype, 1);
    lts_type_set_state_label_name (ltstype, 0, "goal");
    lts_type_set_state_label_typeno (ltstype, 0, bool_type);

    // done with ltstype
    lts_type_validate(ltstype);

    // make sure to set the lts-type before anything else in the GB
    GBsetLTStype(m, ltstype);

    // setting all values for all non direct types
    GBchunkPut(m, action_type, chunk_str("switch_a"));
    GBchunkPut(m, action_type, chunk_str("switch_b"));
    GBchunkPut(m, action_type, chunk_str("switch_c"));
    GBchunkPut(m, action_type, chunk_str("switch_d"));
    GBchunkPut(m, action_type, chunk_str("switch_ab"));
    GBchunkPut(m, action_type, chunk_str("switch_ac"));
    GBchunkPut(m, action_type, chunk_str("switch_ad"));
    GBchunkPut(m, action_type, chunk_str("switch_bc"));
    GBchunkPut(m, action_type, chunk_str("switch_bd"));
    GBchunkPut(m, action_type, chunk_str("switch_cd"));
    GBchunkPut(m, bool_type, chunk_str(LTSMIN_VALUE_BOOL_FALSE));
    GBchunkPut(m, bool_type, chunk_str(LTSMIN_VALUE_BOOL_TRUE));

    // set state variable values for initial state
    GBsetInitialState(m, initial_state());

    // set function pointer for the next-state function
    GBsetNextStateLong(m, (next_method_grey_t) next_state);

    // set function pointer for the label evaluation function
    GBsetStateLabelLong(m, (get_label_method_t) state_label);

    // create combined matrix
    matrix_t *cm = malloc(sizeof(matrix_t));
    dm_create(cm, group_count(), state_length());

    // set the read dependency matrix
    matrix_t *rm = malloc(sizeof(matrix_t));
    dm_create(rm, group_count(), state_length());
    for (int i = 0; i < group_count(); i++) {
        for (int j = 0; j < state_length(); j++) {
            if (read_matrix(i)[j]) {
                dm_set(cm, i, j);
                dm_set(rm, i, j);
            }
        }
    }
    GBsetDMInfoRead(m, rm);

    // set the write dependency matrix
    matrix_t *wm = malloc(sizeof(matrix_t));
    dm_create(wm, group_count(), state_length());
    for (int i = 0; i < group_count(); i++) {
        for (int j = 0; j < state_length(); j++) {
            if (write_matrix(i)[j]) {
                dm_set(cm, i, j);
                dm_set(wm, i, j);
            }
        }
    }
    GBsetDMInfoMustWrite(m, wm);

    // set the combined matrix
    GBsetDMInfo(m, cm);

    // set the label dependency matrix
    matrix_t *lm = malloc(sizeof(matrix_t));
    dm_create(lm, label_count(), state_length());
    for (int i = 0; i < label_count(); i++) {
        for (int j = 0; j < state_length(); j++) {
            if (label_matrix(i)[j]) dm_set(lm, i, j);
        }
    }
    GBsetStateLabelInfo(m, lm);

}