示例#1
0
int HotkeyManager::FindGroupByID(int id) const
{
	const auto i = std::find_if(groups_info.begin(), groups_info.end(),
		[id](const auto& entry) { return entry.last >= id; });

	return static_cast<int>(std::distance(groups_info.begin(), i));
}
示例#2
0
JSDescription JSDescription::Randomized(
    bool makeGrothProof,
    ZCJoinSplit& params,
    const uint256& joinSplitPubKey,
    const uint256& anchor,
    std::array<libzcash::JSInput, ZC_NUM_JS_INPUTS>& inputs,
    std::array<libzcash::JSOutput, ZC_NUM_JS_OUTPUTS>& outputs,
    std::array<size_t, ZC_NUM_JS_INPUTS>& inputMap,
    std::array<size_t, ZC_NUM_JS_OUTPUTS>& outputMap,
    CAmount vpub_old,
    CAmount vpub_new,
    bool computeProof,
    uint256 *esk, // payment disclosure
    std::function<int(int)> gen
)
{
    // Randomize the order of the inputs and outputs
    inputMap = {0, 1};
    outputMap = {0, 1};

    assert(gen);

    MappedShuffle(inputs.begin(), inputMap.begin(), ZC_NUM_JS_INPUTS, gen);
    MappedShuffle(outputs.begin(), outputMap.begin(), ZC_NUM_JS_OUTPUTS, gen);

    return JSDescription(
        makeGrothProof,
        params, joinSplitPubKey, anchor, inputs, outputs,
        vpub_old, vpub_new, computeProof,
        esk // payment disclosure
    );
}
示例#3
0
文件: uva-10118.cpp 项目: c-a/Impa
  int run(std::array<int, PILES>& pile_heights, std::array<int, 5>& basket,
          int curr) {
    int& res = dp_[calc_dp_index(pile_heights)];
    if (res != -1)
      return res;

    res = curr;

    // Check if the basket is full.
    auto free_pos = std::find(basket.begin(), basket.end(), -1);
    if (free_pos == basket.end())
      return res;

    // Try which pile it's best to take a candy from.
    for (int i = 0; i < PILES; ++i) {
      if (pile_heights[i] > 0) {
        int candy = piles_[i][pile_heights[i] - 1];
        auto candy_pos = std::find(basket.begin(), basket.end(), candy);
        if (candy_pos != basket.end()) {
          pile_heights[i] -= 1;
          *candy_pos = -1;
          res = std::max(res, run(pile_heights, basket, curr+1));
          *candy_pos = candy;
          pile_heights[i] += 1;
        } else {
          pile_heights[i] -= 1;
          *free_pos = candy;
          res = std::max(res, run(pile_heights, basket, curr));
          *free_pos = -1;
          pile_heights[i] += 1;
        }
      }
    }
    return res;
  }
示例#4
0
文件: geometry.hpp 项目: fatto/banana
	Sphere(GLfloat radius)
	{
		using namespace Mathematics;
		GLfloat const R = 1.f/float(rings-1);
		GLfloat const S = 1.f/float(sectors-1);
		
		auto v = vertices.begin();
		auto i = indices.begin();
		for(GLuint r = 0; r < rings; ++r)
		{
			for(GLuint s = 0; s < sectors; ++s)
			{
				float const x = cos(tau * s * S) * sin((tau/2.f) * r * R);
				float const y = sin((-tau/4.f) + ((tau/2.f) * r * R));
				float const z = sin(tau * s * S) * sin((tau/2.f) * r * R);
				v->pos = {{ x * radius, y * radius, z * radius }};
				v->norm = {{ x, y, z }};
				v->text = {{ s * S, r * R }};
				++v;
				
				GLuint cur_row = r * sectors;
				GLuint next_row = (r+1) * sectors;
				i->triang = {{ cur_row + s, next_row + s, next_row + (s+1) }};
				++i;
				i->triang = {{ cur_row + s, next_row + (s+1), cur_row + (s+1) }};
				++i;
			}
		}
	}
示例#5
0
// because files take 8-bit chunks while huffman encoding can have many-lengths,
// sometimes we get an array with something like 5 bits left over, with room for 2 more bits.
// A naive implementation could just slide the array as soon as possible (essentially for every
// byte popped), but here we use first_data to avoid this big-copies too much.
void slide_array(std::array<bool,buffsize>& m, unsigned& first_data, unsigned& next_empty) {
    assert(first_data <= next_empty);
    //cerr << "Sliding buffer with first data: " << first_data << " and next_empty: " << next_empty << endl;
    copy(m.begin()+first_data, m.begin()+next_empty, m.begin());
    // subtract first_data from both indices.
    next_empty -= first_data;
    first_data = 0;
}
void setSubMatrixGradient(Eigen::MatrixBase<DerivedA>& dM, const Eigen::MatrixBase<DerivedB>& dM_submatrix,
    const std::array<int, NRows>& rows, const std::array<int, NCols>& cols, typename DerivedA::Index M_rows, typename DerivedA::Index q_start, typename DerivedA::Index q_subvector_size) {
  if (q_subvector_size == Eigen::Dynamic) {
    q_subvector_size = dM.cols() - q_start;
  }
  int index = 0;
  for (typename std::array<int, NCols>::const_iterator col = cols.begin(); col != cols.end(); ++col) {
    for (typename std::array<int, NRows>::const_iterator row = rows.begin(); row != rows.end(); ++row) {
      dM.template block<1, QSubvectorSize> ((*row) + (*col) * M_rows, q_start, 1, q_subvector_size) = dM_submatrix.row(index++);
    }
  }
}
void DialogEditSIMDRegister::onFloatEdited(QObject* sender,const std::array<NumberEdit*,numBytes/sizeof(Float)>& elements)
{
	const auto changedFloatEdit=dynamic_cast<NumberEdit*>(sender);
	std::size_t floatIndex=std::find(elements.begin(),elements.end(),changedFloatEdit)-elements.begin();
	bool ok=false;
	auto value=readFloat<Float>(elements[floatIndex]->text(),ok);
	if(ok)
	{
		std::memcpy(&value_[floatIndex*sizeof(value)],&value,sizeof(value));
		updateAllEntriesExcept(elements[floatIndex]);
	}
}
示例#8
0
BoolTagFilter::BoolTagFilter(const std::string & key, bool value) :
KeyMultiValueTagFilter(key),
m_Value(value)
{
	if (m_Value)
	{
		const std::array<std::string, 5> s{ { "True", "true", "Yes", "yes", "1" } };
		KeyMultiValueTagFilter::setValues(s.begin(), s.end());
	}
	else
	{
		const std::array<std::string, 5> s{ { "False", "false", "No", "no", "0" } };
		KeyMultiValueTagFilter::setValues(s.begin(), s.end());
	}
}
示例#9
0
static
inline
T
max(const std::array<T, DIM>& arr)
{
    return std::max_element(arr.begin(), arr.end());
}
示例#10
0
static inline bool is_reserved (const char chr) noexcept {
  static const std::array<char,18> reserved
  {{':' , '/' , '?' , '#' , '[' , ']' , '@',
        '!' , '$' , '&' , '\'' , '(' , ')' , '*' , '+' , ',' , ';' , '='}};

  return std::find(reserved.begin(), reserved.end(), chr) not_eq reserved.end();
}
示例#11
0
// NCRScore defined inside each feature namespace so it can use the specific array<> datatype
static float NCRScore(std::array<unsigned char,DATASIZE> &I, std::array<unsigned char,DATASIZE> &M, int N, float m, float i, float K1, float K2)
{
	// some components are precalculated in the model or knowledge data
	// Precalculated lines are commented out but left here or understanding
//	float i = std::accumulate(I.begin(),I.end(),0.0F);
//	float i2 = std::inner_product(I.begin(),I.end(),I.begin(),0.0F);
	float im = std::inner_product(I.begin(),I.end(),M.begin(),0.0F);

	float K0 = N*im - i*m;
//	float K1 = N*i2 - i*i;
//	int N = (int)M.size();
//	float K2 = 1.0F / (N*m2 - m*m);

	float score = (K1> 0.0) ? (K0*K0*K2/K1) : 0.0F;
	return score;
}
示例#12
0
	OpenALStream(AudioManagerImpl *manager, MidiSong *song)
		: mManager(manager), mSong(song), mQuit(false), mSource(0)
		, mBufferIdx(0), mSampleRate(0)
	{
		// Using std::fill for mBuffers since VS2013 doesn't support mBuffers{0}.
		std::fill(mBuffers.begin(), mBuffers.end(), 0);
	}
示例#13
0
inline bp::list v_to_l(std::array<T, dim> vector) {
    bp::list list;
    for (auto iter = vector.begin(); iter != vector.end(); ++iter) {
        list.append(*iter);
    }
    return list;
}
示例#14
0
文件: main.cpp 项目: CCJY/coliru
char* AddSorted(unsigned int priority, char value)
{
    auto vit = find_venue_value(value);
    if (priority == 0)
    {
        if (vit != venues.end())
            remove_venue(*vit);
    }
    else
    {
        auto pit = find_venue_priority(priority);
        if (pit != venues.end())
        {
            pit->m_value = value;
            if (vit != venues.end())
                remove_venue(*vit);
        }
        else if (pos < 6)
            venues[pos++] = Venue(priority, value);
        else
            return result;
    }
    // sort from greatest priority to least
    std::sort(venues.begin(), venues.end(), std::greater<Venue>());
    
    for (int i = 0; i < venues.size(); ++i)
        result[i] = venues[i].m_value;
    return result;
}
示例#15
0
TArray4s::trange_type
InputData::trange(const Spin s1, const Spin s2, const RangeOV ov1, const RangeOV ov2, const RangeOV ov3, const RangeOV ov4) const {

    const obs_mosym& spin1 = (s1 == alpha ? obs_mosym_alpha_ : obs_mosym_beta_);
    const std::size_t& nocc1 = (s1 == alpha ? nocc_act_alpha_ : nocc_act_beta_);
    const obs_mosym& spin2 = (s2 == alpha ? obs_mosym_alpha_ : obs_mosym_beta_);
    const std::size_t& nocc2 = (s2 == alpha ? nocc_act_alpha_ : nocc_act_beta_);
    const std::size_t first1 = (ov1 == occ ? 0 : nocc1);
    const std::size_t last1 = (ov1 == occ ? nocc1 : nmo_);
    const std::size_t first2 = (ov2 == occ ? 0 : nocc2);
    const std::size_t last2 = (ov2 == occ ? nocc2 : nmo_);
    const std::size_t first3 = (ov3 == occ ? 0 : nocc1);
    const std::size_t last3 = (ov3 == occ ? nocc1 : nmo_);
    const std::size_t first4 = (ov4 == occ ? 0 : nocc2);
    const std::size_t last4 = (ov4 == occ ? nocc2 : nmo_);

    const std::array<TiledArray::TiledRange1, 4> tr_list = {{
            make_trange1(spin1.begin(), spin1.begin() + first1, spin1.begin() + last1),
            make_trange1(spin2.begin(), spin2.begin() + first2, spin2.begin() + last2),
            make_trange1(spin1.begin(), spin1.begin() + first3, spin1.begin() + last3),
            make_trange1(spin2.begin(), spin2.begin() + first4, spin2.begin() + last4)
        }
    };

    return TiledArray::TiledRange(tr_list.begin(), tr_list.end());
}
示例#16
0
文件: main.cpp 项目: CCJY/coliru
char* AddSorted(unsigned int priority, char value)
{
    auto vit = find_venue_value(value);
    if (vit != venues.end()) // if we found the element then we are either changing its priority or deleting it:
    {
        auto pit = find_venue_priority(priority);
        if (priority == 0)
            remove_venue(*vit);
        else if (pit != venues.end()) // if we found an element with the same priority,
        {                             
            pit->m_value = value; // then change the element's m_value to value and
            remove_venue(*vit);   // delete old element
        }
        else // if priority != 0 and there was no duplicate, then just change the priority
            vit->m_priority = priority;
    }
    else if (pos < 6) // if the venue was not found, we are adding a new one
        venues[pos++] = Venue(priority, value);
    else
        return result; // if the element was not found and the array is full, then there is nothing to do
        
    // sort from greatest priority to least
    std::sort(venues.begin(), venues.end(), std::greater<Venue>());
    
    for (int i = 0; i < venues.size(); ++i)
        result[i] = venues[i].m_value;
    return result;
}
示例#17
0
void JsonWriter::writeString(const std::string &string)
{
	static const std::string escaped = "\"\\\b\f\n\r\t";
	
	static const std::array<char, 7> escaped_code = {'\"', '\\', 'b', 'f', 'n', 'r', 't'};
	
	out <<'\"';
	size_t pos=0, start=0;
	for (; pos<string.size(); pos++)
	{
		//we need to check if special character was been already escaped		
		if((string[pos] == '\\') 
			&& (pos+1 < string.size()) 
			&& (std::find(escaped_code.begin(), escaped_code.end(), string[pos+1]) != escaped_code.end()) )
		{
			pos++; //write unchanged, next simbol also checked
		}
		else
		{
			size_t escapedPos = escaped.find(string[pos]);

			if (escapedPos != std::string::npos)
			{
				out.write(string.data()+start, pos - start);
				out << '\\' << escaped_code[escapedPos];
				start = pos+1;
			}			
		}

	}
	out.write(string.data()+start, pos - start);
	out <<'\"';
}
void DialogEditSIMDRegister::onIntegerEdited(QObject* sender,const std::array<NumberEdit*,numBytes/sizeof(Integer)>& elements)
{
	const auto changedElementEdit=dynamic_cast<NumberEdit*>(sender);
	std::size_t elementIndex=std::find(elements.begin(),elements.end(),changedElementEdit)-elements.begin();
	Integer value=readInteger(elements[elementIndex]);
	std::memcpy(&value_[elementIndex*sizeof(value)],&value,sizeof(value));
	updateAllEntriesExcept(elements[elementIndex]);
}
示例#19
0
typename GetSubMatrixGradientArray<QSubvectorSize, Derived, NRows, NCols>::type
getSubMatrixGradient(const Eigen::MatrixBase<Derived>& dM,
  const std::array<int, NRows>& rows,
  const std::array<int, NCols>& cols,
  typename Derived::Index M_rows, int q_start, typename Derived::Index q_subvector_size) {
  if (q_subvector_size == Eigen::Dynamic) {
    q_subvector_size = dM.cols() - q_start;
  }
  Eigen::Matrix<typename Derived::Scalar, NRows * NCols, Derived::ColsAtCompileTime> dM_submatrix(NRows * NCols, q_subvector_size);
  int index = 0;
  for (typename std::array<int, NCols>::const_iterator col = cols.begin(); col != cols.end(); ++col) {
    for (typename std::array<int, NRows>::const_iterator row = rows.begin(); row != rows.end(); ++row) {
      dM_submatrix.row(index++) = dM.template block<1, QSubvectorSize> ((*row) + (*col) * M_rows, q_start, 1, q_subvector_size);
    }
  }
  return dM_submatrix;
}
示例#20
0
static
inline
bool
unique(
        const std::array<T, DIM>& perm)
{
    std::vector<T> copy(perm.begin(), perm.end());
    return unique<T>(copy);
}
示例#21
0
void Active::update(double min_cl, double max_cl)
{
    assert(min_cl <= max_cl);

    static const std::array<double, sc_substates> channel_loads {{
        0.27, 0.35, 0.43, 0.51, 0.59
    }};

    auto state_up_it = std::upper_bound(channel_loads.begin(), channel_loads.end(), min_cl);
    auto state_up = std::distance(channel_loads.begin(), state_up_it);

    auto state_down_it = std::upper_bound(channel_loads.begin(), channel_loads.end(), max_cl);
    auto state_down = std::distance(channel_loads.begin(), state_down_it);

    m_substate = std::max(state_up, state_down);
    m_substate = std::min(sc_substates - 1, m_substate);
    assert(m_substate < sc_substates);
}
示例#22
0
bool IsEmulated(u32 major_version)
{
  if (major_version == static_cast<u32>(Titles::BC & 0xffffffff))
    return true;

  return std::any_of(
      ios_memory_values.begin(), ios_memory_values.end(),
      [major_version](const MemoryValues& values) { return values.ios_number == major_version; });
}
示例#23
0
Correction::Correction(std::array<operande, 10> &multiples, std::array<operande, 10> &order, std::array<operande, 10> &userAnswers, const operande time) :
    _difficultyMode(HARD), _seconds(time), _note(10)
{
    _multiple.isHard = true;

    std::copy(multiples.begin(), multiples.end(), _multiple.multiples.begin());
    std::copy(order.begin(), order.end(), _orderTab.begin());
    std::copy(userAnswers.begin(), userAnswers.end(), _answers.begin());
}
示例#24
0
文件: hid.cpp 项目: JayFoxRox/citra
static void LoadInputDevices() {
    std::transform(Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_BEGIN,
                   Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_END,
                   buttons.begin(), Input::CreateDevice<Input::ButtonDevice>);
    circle_pad = Input::CreateDevice<Input::AnalogDevice>(
        Settings::values.analogs[Settings::NativeAnalog::CirclePad]);
    motion_device = Input::CreateDevice<Input::MotionDevice>(Settings::values.motion_device);
    touch_device = Input::CreateDevice<Input::TouchDevice>(Settings::values.touch_device);
}
示例#25
0
void randFrame(std::array<bool, 32*64> & mem)
{
    static std::default_random_engine generator;
    static std::bernoulli_distribution distribution(0.5);

    for(std::array<bool, 32*64>::iterator it_mem = mem.begin(); it_mem != mem.end(); ++it_mem)
    {
        *it_mem = distribution(generator);
    }
}
示例#26
0
    static void read_bytes(Iterator& begin, const Iterator& end,
        std::array<uint8_t, N>& byte_array, bool reverse=false)
    {
        check_distance(begin, end, byte_array.size());
        #ifdef BOOST_LITTLE_ENDIAN
            // do nothing
        #elif BOOST_BIG_ENDIAN
            reverse = !reverse;
        #else
            #error "Endian isn't defined!"
        #endif

        if (reverse)
            std::reverse_copy(
                begin, begin + byte_array.size(), byte_array.begin());
        else
            std::copy(begin, begin + byte_array.size(), byte_array.begin());
        begin += byte_array.size();
    }
示例#27
0
void CMemoryWindow::OnDataTypeChanged(wxCommandEvent& ev)
{
	static constexpr std::array<MemoryDataType, 5> map{ {MemoryDataType::U8, MemoryDataType::U16,
																											MemoryDataType::U32, MemoryDataType::ASCII,
																											MemoryDataType::FloatingPoint} };
	if (ev.GetId() == IDM_DATA_TYPE_RBOX)
	{
		memview->SetDataType(map.at(ev.GetSelection()));
	}
	else
	{
		// Event from the CMemoryView indicating type was changed.
		auto itr = std::find(map.begin(), map.end(), static_cast<MemoryDataType>(ev.GetInt()));
		int idx = -1;
		if (itr != map.end())
			idx = static_cast<int>(itr - map.begin());
		m_rbox_data_type->SetSelection(idx);
	}
}
示例#28
0
 std::array<size_t, dims> to_lattice(std::array<double, dims> &arr)
 {
     std::array<size_t, dims> floored;
     std::transform(arr.begin(), arr.end(), floored.begin(),
             [this] (size_t coord)
             {
                 return floor(coord / this->actual_cell_side);
             }
     );
     return floored; 
 }
示例#29
0
// Microbenchmark for verification of a basic P2WPKH script. Can be easily
// modified to measure performance of other types of scripts.
static void VerifyScriptBench(benchmark::State& state)
{
    const int flags = SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_P2SH;
    const int witnessversion = 0;

    // Keypair.
    CKey key;
    static const std::array<unsigned char, 32> vchKey = {
        {
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
        }
    };
    key.Set(vchKey.begin(), vchKey.end(), false);
    CPubKey pubkey = key.GetPubKey();
    uint160 pubkeyHash;
    CHash160().Write(pubkey.begin(), pubkey.size()).Finalize(pubkeyHash.begin());

    // Script.
    CScript scriptPubKey = CScript() << witnessversion << ToByteVector(pubkeyHash);
    CScript scriptSig;
    CScript witScriptPubkey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(pubkeyHash) << OP_EQUALVERIFY << OP_CHECKSIG;
    const CMutableTransaction& txCredit = BuildCreditingTransaction(scriptPubKey);
    CMutableTransaction txSpend = BuildSpendingTransaction(scriptSig, txCredit);
    CScriptWitness& witness = txSpend.vin[0].scriptWitness;
    witness.stack.emplace_back();
    key.Sign(SignatureHash(witScriptPubkey, txSpend, 0, SIGHASH_ALL, txCredit.vout[0].nValue, SigVersion::WITNESS_V0), witness.stack.back());
    witness.stack.back().push_back(static_cast<unsigned char>(SIGHASH_ALL));
    witness.stack.push_back(ToByteVector(pubkey));

    // Benchmark.
    while (state.KeepRunning()) {
        ScriptError err;
        bool success = VerifyScript(
            txSpend.vin[0].scriptSig,
            txCredit.vout[0].scriptPubKey,
            &txSpend.vin[0].scriptWitness,
            flags,
            MutableTransactionSignatureChecker(&txSpend, 0, txCredit.vout[0].nValue),
            &err);
        assert(err == SCRIPT_ERR_OK);
        assert(success);

#if defined(HAVE_CONSENSUS_LIB)
        CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
        stream << txSpend;
        int csuccess = fujicoinconsensus_verify_script_with_amount(
            txCredit.vout[0].scriptPubKey.data(),
            txCredit.vout[0].scriptPubKey.size(),
            txCredit.vout[0].nValue,
            (const unsigned char*)stream.data(), stream.size(), 0, flags, nullptr);
        assert(csuccess == 1);
#endif
    }
}
示例#30
0
void BoolTagFilter::setValue(bool value)
{
	if (m_Value == value)
		return;

	m_Value = value;

	clearValues();

	if (m_Value)
	{
		const std::array<std::string, 5> s{ { "True", "true", "Yes", "yes", "1" } };
		KeyMultiValueTagFilter::setValues(s.begin(), s.end());
	}
	else
	{
		const std::array<std::string, 5> s{ { "False", "false", "No", "no", "0" } };
		KeyMultiValueTagFilter::setValues(s.begin(), s.end());
	}
}