Esempio n. 1
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();
}
Esempio n. 2
0
File: main.cpp Progetto: 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;
}
Esempio n. 3
0
File: main.cpp Progetto: 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;
}
Esempio n. 4
0
  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;
  }
Esempio n. 5
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 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++);
    }
  }
}
Esempio n. 7
0
void CAST256::setKey(const BytesVector &key)
{
    const uint8_t keylen = key.size();
    constexpr std::array<uint8_t, 5> allowed_key_lengths = {{16, 20, 24, 28, 32}};

    const auto it = std::find(allowed_key_lengths.begin(), allowed_key_lengths.end(), keylen); 
    if (it == allowed_key_lengths.end())
    {
        throw BadKeyLength("Your key length has to be of length 16, 20, 24, 28 or 32 bytes.", keylen);
    }

    // Pad the key with 0 to get 256 bits length.
    this->key = Padding::zeros(key, 32);
}
Esempio n. 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());
	}
}
Esempio n. 9
0
	void release(const MidiEvent& evt)
	{
		int note_no = MidiEventUtils::getNote(evt);

		auto note = std::find_if(
			notes.begin(),
			notes.end(),
			[note_no](blit_saw_oscillator_note& n) { return n.note_no == note_no; });

		if (note != notes.end())
		{
			// note off
			note->note_no = -1;
		}
	}
Esempio n. 10
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);
	}
Esempio n. 11
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));
}
Esempio n. 12
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());
}
Esempio n. 13
0
static
inline
T
max(const std::array<T, DIM>& arr)
{
    return std::max_element(arr.begin(), arr.end());
}
Esempio n. 14
0
bool Arm64FPRCache::IsCalleeSaved(ARM64Reg reg)
{
  static constexpr std::array<ARM64Reg, 9> callee_regs{{
      Q8,
      Q9,
      Q10,
      Q11,
      Q12,
      Q13,
      Q14,
      Q15,
      INVALID_REG,
  }};

  return std::find(callee_regs.begin(), callee_regs.end(), reg) != callee_regs.end();
}
Esempio n. 15
0
    void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths)
    {
        args.parse_arguments(COMMAND_STRUCTURE);

        if (args.command_arguments.empty())
        {
            print_usage();
            Checks::exit_success(VCPKG_LINE_INFO);
        }
        const auto& topic = args.command_arguments[0];
        if (topic == "triplet" || topic == "triplets" || topic == "triple")
        {
            help_topic_valid_triplet(paths);
            Checks::exit_success(VCPKG_LINE_INFO);
        }

        auto it_topic = Util::find_if(topics, [&](const Topic& t) { return t.name == topic; });
        if (it_topic != topics.end())
        {
            it_topic->print(paths);
            Checks::exit_success(VCPKG_LINE_INFO);
        }

        System::println(System::Color::error, "Error: unknown topic %s", topic);
        help_topics(paths);
        Checks::exit_fail(VCPKG_LINE_INFO);
    }
Esempio n. 16
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;
}
Esempio n. 17
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;
}
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]);
}
Esempio n. 19
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; });
}
Esempio n. 20
0
static
inline
bool
unique(
        const std::array<T, DIM>& perm)
{
    std::vector<T> copy(perm.begin(), perm.end());
    return unique<T>(copy);
}
Esempio n. 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);
}
Esempio n. 22
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());
}
Esempio n. 23
0
bool Arm64GPRCache::IsCalleeSaved(ARM64Reg reg)
{
  static constexpr std::array<ARM64Reg, 11> callee_regs{{
      X28,
      X27,
      X26,
      X25,
      X24,
      X23,
      X22,
      X21,
      X20,
      X19,
      INVALID_REG,
  }};

  return std::find(callee_regs.begin(), callee_regs.end(), EncodeRegTo64(reg)) != callee_regs.end();
}
Esempio n. 24
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);
    }
}
Esempio n. 25
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);
	}
}
Esempio n. 26
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
    }
}
Esempio n. 27
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; 
 }
Esempio n. 28
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());
	}
}
Esempio n. 29
0
	void trigger(const MidiEvent& evt)
	{
		auto note = std::find_if(
			notes.begin(),
			notes.end(),
			[](blit_saw_oscillator_note& n) { return n.note_no < 0; });

		if (note != notes.end())
		{
			note->note_no = MidiEventUtils::getNote(evt);
			note->velocity = MidiEventUtils::getNoteVelocity(evt) / 127.0;
			note->value = 0.0;
			note->t = 0.5;

			//
			double freq = 440.0*(std::pow(2.0, (note->note_no + pitchbend - 69.0) / 12.0));
			note->n = static_cast<int>(sampleRate / 2.0 / freq);
			note->dt = freq / sampleRate;
		}
	}
void DimensionalArray<Elem, DIM>::resize(const std::array<std::size_t, DIM>& lengthsArray, bool cpyValues){
	std::size_t oldSize = this->size();
	std::copy(lengthsArray.begin(), lengthsArray.end(), this->_lengths);
	std::size_t newSize = this->size();
	Elem* tmp = new Elem[newSize];
	/* Initialisation du nouveau vecteur, les anciennes valeurs sont conservées au possible 
	si cpyValues est true */
	if(cpyValues){
		for(std::size_t i=0;i<newSize;++i) (i<oldSize) ? tmp[i] = _val[i] : tmp[i] = Elem();
	}
	delete[] _val; _val = tmp; tmp = nullptr;
}