void BigInt::makeMultiplicationWithNumbersAndDigit(const ContainerType& numbers, RankType digit, ContainerType& result) { result.clear(); result.push_back(0); if (0 == digit) { return; } else if (1 == digit) { result = numbers; } else { for (int rankIndex = 0; rankIndex < numbers.size(); rankIndex++) { RankType multiplication = numbers[rankIndex] * digit; if (result.size() == rankIndex) { result.push_back(multiplication % kBaseValue); } else { result[rankIndex] += multiplication % kBaseValue; } if (result[rankIndex] / kBaseValue) { result[rankIndex] %= kBaseValue; result.push_back(1); } if (multiplication / kBaseValue) { if (result.size() == rankIndex + 1) { result.push_back(multiplication / kBaseValue); } else { result[rankIndex + 1] += multiplication / kBaseValue; } } } } }
void StringContainerToCharPtrArray(const ContainerType &container, unsigned int &out_count, char **&out_list, const char *name_string = NULL) { out_count = 0; out_list = NULL; if (!container.empty()) { C_ListTypeString<unsigned int> tmp_list; tmp_list.FromContainer(container, name_string); out_count = tmp_list.GetCount(); out_list = tmp_list.GetList(); // Mustn't try to free when we leave this scope... tmp_list.Reset(); } }
bool BigInt::isEqualToNumbers(const ContainerType& numbers) const { bool result = _numbers.size() == numbers.size(); if (result) { for (int index = 0; index < _numbers.size(); index++) { if (_numbers[index] != numbers[index]) { result = false; break; } } } return result; }
// This function is given an entire block of the same residue. The rotamerIDs will of course be different. void processResData( const std::string& resName, ContainerType& data, RotamerLibrary& _RotLib, bool switchImportMode ) { // Either there is something fundamental I don't understand, or ... // The dunbrack library has this really annoying thing whereby the 180 and -180 phi/psi torsions, // which are by definition the same thing, are both defined! // We only want one, as both represent the same 10 degree bin! data.erase(std::remove_if(data.begin(),data.end(),removeParseData),data.end()); if( switchImportMode ) { processResData_ByRotID(resName,data,_RotLib); } else { data.erase(std::remove_if(data.begin(),data.end(),removeLowPropensity),data.end()); processResData_ByChis(resName,data,_RotLib); } }
void processResData_ByChis( const std::string& resName, ContainerType& data, RotamerLibrary& _RotLib ) { const double tollerance = 12.0; // Ensure full chi arrays size_t largestSoFar = data[0].chis.size(); for( size_t i = 1; i < data.size(); i++ ) { if( data[i].chis.size() > largestSoFar ) { largestSoFar = data[i].chis.size(); i = 0; // reset } while( data[i].chis.size() < largestSoFar ) { data[i].chis.push_back(0.0); } } size_t done = 0; std::vector<bool> taken(data.size()); while( data.size() > done ) { ContainerType subdata; bool on = false; for( int i = (int)data.size()-1; i >= 0; i-- ) { if( taken[i] != true && (!on || equalChis( subdata[0], data[i], tollerance ) ) ) { subdata.push_back( data[i] ); taken[i] = true; on = true; done++; } } processData( resName, subdata, _RotLib, tollerance ); subdata.clear(); } data.clear(); }
void WeakBlock::specializedVisit(ContainerType& container, SlotVisitor& visitor) { HeapVersion markingVersion = visitor.markingVersion(); size_t count = weakImplCount(); for (size_t i = 0; i < count; ++i) { WeakImpl* weakImpl = &weakImpls()[i]; if (weakImpl->state() != WeakImpl::Live) continue; WeakHandleOwner* weakHandleOwner = weakImpl->weakHandleOwner(); if (!weakHandleOwner) continue; JSValue jsValue = weakImpl->jsValue(); if (container.isMarkedConcurrently(markingVersion, jsValue.asCell())) continue; if (!weakHandleOwner->isReachableFromOpaqueRoots(Handle<Unknown>::wrapSlot(&const_cast<JSValue&>(jsValue)), weakImpl->context(), visitor)) continue; visitor.appendUnbarriered(jsValue); } }
inline bool checkContainerSame(const ContainerType & c1, const ContainerType & c2) { typename ContainerType::const_iterator it1 = c1.begin(); typename ContainerType::const_iterator it2 = c2.begin(); while(it1 != c1.end() && it2 != c2.end()) { if(*it1 != *it2) { return false; } ++it1; ++it2; } if(it1 != c1.end() || it1 != c1.end()) { return false; } return true; }
void processResData_ByRotID( const std::string& resName, ContainerType& data, RotamerLibrary& _RotLib ) { // Sort the data to increase efficiency below std::stable_sort( data.begin(), data.end(), sortPsi); std::stable_sort( data.begin(), data.end(), sortPhi); std::stable_sort( data.begin(), data.end(), sortRotID); ContainerType subdata; while( true ) { if( data.size() > 0 && (subdata.size() == 0 || subdata[0].rotID.compare( data.back().rotID,0,4,0 )) ) { subdata.push_back( data.back() ); data.erase(data.end()-1); // rob the end, not the start (ContainerType<> perfomance reasons!) } else { ASSERT( data.size() == (36*36), ParseException, "Assumption error!"); ASSERT( data[0].phi == -180.0 && data[0].psi == -180.0, ParseException, "Wrong phi/psi"); for( size_t j = 1; j < data.size(); j++ ) { ASSERT( data[j].phi == (-180.0+(j/36)*10) && data[j].psi == (-180.0+(j%36)*10), ParseException, "Wrong phi/psi"); } processData( resName, subdata, _RotLib, 40.0 ); // 40 degree tollerance delta from data[0] subdata.clear(); if( data.size() == 0 ) { return; } } } }
void foreach( ContainerType & cont , Functor func ) { std::for_each(cont.begin(),cont.end(),func); }
void clear() { _buffer.clear(); }
void foreach_reverse( ContainerType & cont , Functor func ) { std::for_each(cont.rbegin(),cont.rend(),func); }
void operator()(const ContainerType& new_bit) { for(typename ContainerType::const_iterator ci = new_bit.begin(); ci != new_bit.end(); ++ci) { my_result += *ci; } }
void parse(std::istream& ) override { // ignore istream, just enter something into the map elements_.insert(std::make_pair("hydrogen", 1.0)); elements_.insert(std::make_pair("oxygen", 16.0)); }
void DataTest::testColumnList() { typedef std::list<int> ContainerType; typedef Column<ContainerType> ColumnType; MetaColumn mc(0, "mc", MetaColumn::FDT_DOUBLE, 2, 3, true); assert (mc.name() == "mc"); assert (mc.position() == 0); assert (mc.length() == 2); assert (mc.precision() == 3); assert (mc.type() == MetaColumn::FDT_DOUBLE); assert (mc.isNullable()); ContainerType* pData = new ContainerType; pData->push_back(1); pData->push_back(2); pData->push_back(3); pData->push_back(4); pData->push_back(5); ColumnType c(mc, pData); assert (c.rowCount() == 5); assert (c[0] == 1); assert (c[1] == 2); assert (c[2] == 3); assert (c[3] == 4); assert (c[4] == 5); assert (c.name() == "mc"); assert (c.position() == 0); assert (c.length() == 2); assert (c.precision() == 3); assert (c.type() == MetaColumn::FDT_DOUBLE); try { int i; i = c[100]; // to silence gcc fail ("must fail"); } catch (RangeException&) { } ColumnType c1 = c; assert (c1.rowCount() == 5); assert (c1[0] == 1); assert (c1[1] == 2); assert (c1[2] == 3); assert (c1[3] == 4); assert (c1[4] == 5); ColumnType c2(c1); assert (c2.rowCount() == 5); assert (c2[0] == 1); assert (c2[1] == 2); assert (c2[2] == 3); assert (c2[3] == 4); assert (c2[4] == 5); ContainerType vi; vi.assign(c.begin(), c.end()); assert (vi.size() == 5); ContainerType::const_iterator it = vi.begin(); ContainerType::const_iterator end = vi.end(); for (int i = 1; it != end; ++it, ++i) assert (*it == i); c.reset(); assert (c.rowCount() == 0); assert (c1.rowCount() == 0); assert (c2.rowCount() == 0); ContainerType* pV1 = new ContainerType; pV1->push_back(1); pV1->push_back(2); pV1->push_back(3); pV1->push_back(4); pV1->push_back(5); ContainerType* pV2 = new ContainerType; pV2->push_back(5); pV2->push_back(4); pV2->push_back(3); pV2->push_back(2); pV2->push_back(1); Column<ContainerType> c3(mc, pV1); Column<ContainerType> c4(mc, pV2); Poco::Data::swap(c3, c4); assert (c3[0] == 5); assert (c3[1] == 4); assert (c3[2] == 3); assert (c3[3] == 2); assert (c3[4] == 1); assert (c4[0] == 1); assert (c4[1] == 2); assert (c4[2] == 3); assert (c4[3] == 4); assert (c4[4] == 5); std::swap(c3, c4); assert (c3[0] == 1); assert (c3[1] == 2); assert (c3[2] == 3); assert (c3[3] == 4); assert (c3[4] == 5); assert (c4[0] == 5); assert (c4[1] == 4); assert (c4[2] == 3); assert (c4[3] == 2); assert (c4[4] == 1); }
iterator end() { return _buffer.end(); }
iterator begin() { return _buffer.begin(); }
ordered_adaptor_iterator(const ContainerType * container, ValueCompare const & cmp): container(container), current_index(container->size()), unvisited_nodes(compare_by_heap_value(container, ValueCompare())) {}
bool onParsed() override { // last chance to check content (i.e size) if( !container.validate() ) return false; parentAssist.insert( container.data ); return true; }
QVariant QJson::parseObject(const QString &json, int &index, DecodeOptions options, bool &success, QString *errorMessage) { Q_ASSERT(json[index] == '{'); index++; skipWhitespace(json, index); ContainerType object; while (checkAvailable(json, index, success, errorMessage)) { if (json[index] == QChar::fromLatin1('}')) { index++; return object; } else { QString key = QJson::parseValue(json, index, options, success, errorMessage).toString(); if (!success) return QVariant(); skipWhitespace(json, index); checkAvailable(json, index, success, errorMessage); if (json[index] == QChar::fromLatin1(':')) index++; else { success = false; if (errorMessage) *errorMessage = QString("Expected colon at position %1").arg(index); return QVariant(); } skipWhitespace(json, index); QVariant value = QJson::parseValue(json, index, options, success, errorMessage); if (!success) return QVariant(); // Add the key / value pair to the object object.insert(key, value); int skippedWhitespaces = skipWhitespace(json, index); checkAvailable(json, index, success, errorMessage); switch (json[index].toLatin1()) { case ',': index++; skipWhitespace(json, index); break; case '}': //'}' will be processed in the next iteration break; default: // Only allow missing comma if there is at least one whitespace instead of the comma! if ((options & AllowMissingComma) && skippedWhitespaces > 0) break; else { success = false; if (errorMessage) *errorMessage = QString("Unexpected character at index %1").arg(index); return QVariant(); } } } } return QVariant(); }
explicit array_view(ContainerType & container) noexcept : m_pointer{ container.data() } , m_size_in_items{ container.size() } { }
virtual void parse(std::istream& ) { // ignore istream, just enter something into the map elements_.insert(std::make_pair("A", 71.03711)); elements_.insert(std::make_pair("R", 156.10111)); }
void truncate_entries() { while(entries.size() > entries_max) { entries.pop_back(); } }
void RotLibConvert_Dunbrack_BBDep::readLib( const std::string& _LibraryFilename, RotamerLibrary& _RotLib ) { StringBuilder sb; std::ifstream* p_torsionFile; try { if( _RotLib.isFinalised() ) throw ProcedureException("readLib() is not allowed, the rotamer library has been finalised, no further import can occur"); // Mappings for things like HIS -> HIE HID HIP _RotLib.addIonisationAliasWorkingDefaults(); // Make sure Alanine and Glycine are defined non-rotamer residues (the library itself ignores them) _RotLib.addAsBlankRotamer("ALA"); _RotLib.addAsBlankRotamer("GLY"); p_torsionFile = new std::ifstream(_LibraryFilename.c_str(), std::ifstream::in); std::ifstream& torsionFile = *p_torsionFile; if( !torsionFile.is_open() ) throw(IOException( "Dunbrack BB-independent torsional definition file not found: '" + _LibraryFilename + "'!" )); ParseData pd; ContainerType data; StringBuilder prevResName(3); StringBuilder currResName(4); StringBuilder cacheLine; while( true ) { if( cacheLine.size() > 0 ) { sb.setTo(cacheLine); cacheLine.clear(); } else if( !(sb << torsionFile) ) { break; } sb.Trim(); if( sb.size() == 0 ) continue; // blank line currResName.setTo(sb,0,3); if( prevResName.size() == 0 ) { prevResName.setTo( currResName ); ASSERT( pd.parse( sb ), ParseException, "Malformed line"); data.push_back( pd ); } else if( prevResName.compare( currResName, 0, 3, 0 ) ) { // Woooo - we found one :-D ASSERT( pd.parse( sb ), ParseException, "Malformed line"); data.push_back( pd ); } else { if( data.size() > 0 ) { processResData( prevResName.toString(), data, _RotLib, switchImportMode ); ASSERT( data.size() == 0, CodeException, "CodeFail"); } prevResName.setTo( currResName ); cacheLine.setTo( sb ); // we havent actually processed the current line! Store it. } } if( data.size() > 0 ) { processResData( prevResName.toString(), data, _RotLib, switchImportMode ); ASSERT( data.size() == 0, CodeException, "CodeFail"); } // Ensure file-handle cleanup p_torsionFile->close(); delete p_torsionFile; } catch( ExceptionBase ex ) { // Ensure file-handle cleanup p_torsionFile->close(); delete p_torsionFile; throw ex; } }
int lowess(const ContainerType& x, const ContainerType& y, double frac, // parameter f int nsteps, ValueType delta, ContainerType& ys, ContainerType& resid_weights, // vector rw ContainerType& weights // vector res ) { bool fit_ok; size_t ns, n(x.size()); if (n < 2) { ys[0] = y[0]; return 1; } // how many points around estimation point should be used for regression: // at least two, at most n points size_t tmp = (size_t)(frac * (double)n); ns = std::max(std::min(tmp, n), (size_t)2); // robustness iterations for (int iter = 1; iter <= nsteps + 1; iter++) { // start of array in C++ at 0 / in FORTRAN at 1 // last: index of prev estimated point // i: index of current point size_t i(0), last(-1), nleft(0), nright(ns -1); // Fit all data points y[i] until the end of the array do { // Identify the neighborhood around the current x[i] // -> get the nearest ns points update_neighborhood(x, n, i, nleft, nright); // Calculate weights and apply fit (original lowest function) fit_ok = lowest(x, y, n, x[i], ys[i], nleft, nright, weights, (iter > 1), resid_weights); // if something went wrong during the fit, use y[i] as the // fitted value at x[i] if (!fit_ok) ys[i] = y[i]; // If we skipped some points (because of how delta was set), go back // and fit them by linear interpolation. if (last < i - 1) { interpolate_skipped_fits(x, i, last, ys); } // Update the last fit counter to indicate we've now fit this point. // Find the next i for which we'll run a regression. update_indices(x, n, delta, i, last, ys); } while (last < n - 1); // compute current residuals for (i = 0; i < n; i++) { weights[i] = y[i] - ys[i]; } // compute robustness weights except last time if (iter > nsteps) break; calculate_residual_weights(n, weights, resid_weights); } return 0; }
AlignmentElement::AlignmentElement(const ContainerType &alignInfo) { insert_iterator<ContainerType> insertIter( m_collection, m_collection.end() ); copy(alignInfo.begin(), alignInfo.end(), insertIter); };
const_iterator cend() const { return _buffer.cend(); }
size_type size() const { return _buffer.size(); }
bool empty() const { return _buffer.empty(); }
const_iterator cbegin() const { return _buffer.cbegin(); }
MSSpectrum &MSSpectrum::select(const std::vector<Size> &indices) { Size snew = indices.size(); ContainerType tmp; tmp.reserve(indices.size()); const Size peaks_old = size(); for (Size i = 0; i < snew; ++i) { tmp.push_back(*(ContainerType::begin() + indices[i])); } ContainerType::swap(tmp); for (Size i = 0; i < float_data_arrays_.size(); ++i) { if (float_data_arrays_[i].size() != peaks_old) { throw Exception::Precondition(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "FloatDataArray[" + String(i) + "] size (" + String(float_data_arrays_[i].size()) + ") does not match spectrum size (" + String(peaks_old) + ")"); } std::vector<float> mda_tmp; mda_tmp.reserve(float_data_arrays_[i].size()); for (Size j = 0; j < snew; ++j) { mda_tmp.push_back(*(float_data_arrays_[i].begin() + indices[j])); } std::swap(float_data_arrays_[i], mda_tmp); } for (Size i = 0; i < string_data_arrays_.size(); ++i) { if (string_data_arrays_[i].size() != peaks_old) { throw Exception::Precondition(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "StringDataArray[" + String(i) + "] size (" + String(string_data_arrays_[i].size()) + ") does not match spectrum size (" + String(peaks_old) + ")"); } std::vector<String> mda_tmp; mda_tmp.reserve(string_data_arrays_[i].size()); for (Size j = 0; j < snew; ++j) { mda_tmp.push_back(*(string_data_arrays_[i].begin() + indices[j])); } std::swap(string_data_arrays_[i], mda_tmp); } for (Size i = 0; i < integer_data_arrays_.size(); ++i) { if (integer_data_arrays_[i].size() != peaks_old) { throw Exception::Precondition(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "IntegerDataArray[" + String(i) + "] size (" + String(integer_data_arrays_[i].size()) + ") does not match spectrum size (" + String(peaks_old) + ")"); } std::vector<Int> mda_tmp; mda_tmp.reserve(integer_data_arrays_[i].size()); for (Size j = 0; j < snew; ++j) { mda_tmp.push_back(*(integer_data_arrays_[i].begin() + indices[j])); } std::swap(integer_data_arrays_[i], mda_tmp); } return *this; }