//Másoló konstruktor OAF::OrderedSet::OrderedSet(const OrderedSet& set) { _head = new OSNode(); for (iterator it = set.begin(); it != set.end(); ++it) { insert(*it); } }
void WriteIncludes::writeHeaders(const OrderedSet &headers, bool global) { const QChar openingQuote = global ? QLatin1Char('<') : QLatin1Char('"'); const QChar closingQuote = global ? QLatin1Char('>') : QLatin1Char('"'); const OrderedSet::const_iterator cend = headers.constEnd(); for ( OrderedSet::const_iterator sit = headers.constBegin(); sit != cend; ++sit) { const StringMap::const_iterator hit = m_oldHeaderToNewHeader.constFind(sit.key()); const bool mapped = hit != m_oldHeaderToNewHeader.constEnd(); const QString header = mapped ? hit.value() : sit.key(); if (!header.trimmed().isEmpty()) { m_output << "#include " << openingQuote << header << closingQuote << QLatin1Char('\n'); } } }
//----------------------------------------------------------------------------- int OrderedSet:: add( OrderedSet const& os_rhs ) { int added = 0; std::for_each( os_rhs.cbegin(), os_rhs.cend(), [&] ( OrderedSetBase_t::value_type const& feature ) { int i = this->index(feature) ; if( i != this->not_found ) { this->append(feature); ++added; } } ); return added; }
//----------------------------------------------------------------------------- int OrderedSet:: remove( OrderedSet const& os_rhs ) { int removed = 0; std::for_each( os_rhs.cbegin(), os_rhs.cend(), [&] ( OrderedSetBase_t::value_type const& feature ) { int i = this->index(feature) ; if( i != this->not_found ) { this->removeAt(i); ++removed; } } ); return removed; }
//Két halmaz összehasonlítása bool OAF::OrderedSet::operator==(OrderedSet const& set) const { if(_size != set.size()) { return false; } else { bool l = true; iterator it = begin(); iterator it2 = set.begin(); while (it != end()) { if (*it != *it2) l = false; ++it; ++it2; } return l; } }
void testOrderedSet () { int size = 5; double values [5] = {24,30,0,4,34}; double refValues [5] = {100,110,10,20,50}; OrderedSet *set = new OrderedSet(size); RelativeEntropy *m = new RelativeEntropy(size,values,refValues); set->setObjectiveFunction(m); set->computeObjectiveValues(); set->normalizeObjectiveValues(); set->print(); set->printObjectiveValues(); set->printOptimalPartitionList(0.001); delete m; delete set; }
//|erase| művelet a következő formában: SET - 5 vagy 5 - SET OAF::OrderedSet OAF::OrderedSet::operator- (const int x) const { OrderedSet ret = *this; return ret.erase(x); }
//|insert| művelet a következő formában: SET + 5 vagy 5 + SET OAF::OrderedSet OAF::OrderedSet::operator+ (const int x) const { OrderedSet ret = *this; return ret.insert(x); }
main(int argc, char **argv) { // check input MustBeTrue(argc > 1); // declare ordered set TRACE(); cout << "creating oset ..." << endl; OrderedSet<Tuple<int, int> > oset; // insert data TRACE(); cout << "INSERTING INTO OSET ..." << endl; int data = 1; for (int arg = 1; arg < argc; arg++) { Tuple<int, int> tuple(atoi(argv[arg]), 0); for (int i = 1; i <= 5; i++, data++) { tuple.data = data; TRACE(); cout << "inserting tuple ... " << tuple << endl; if (oset.insert(tuple) != OK) { TRACE(); cout << "insert failed for tuple." << endl; return(2); } } } // print data TRACE(); cout << "ordered set is ... " << oset << endl; // report counts TRACE(); cout << "REPORTING COUNTS IN OSET ..." << endl; for (int arg = 1; arg < argc; arg++) { int argvalue = atoi(argv[arg]); Tuple<int, int> tuple(argvalue, 0); TRACE(); cout << "oset counts for " << argvalue << endl; TRACE(); cout << "counts are ... " << oset.getSize(tuple) << endl; } TRACE(); cout << "total counts are ... " << oset.getSize() << endl; // updating data TRACE(); cout << "UPDATING OSET ..." << endl; for (int arg = 1; arg < argc; arg++) { Tuple<int, int> tuple(atoi(argv[arg]), 0); for (int i = 1; i <= 5; i++, data++) { tuple.data = data; TRACE(); cout << "updating tuple ... " << tuple << endl; if (oset.update(tuple, i) != OK) { TRACE(); cout << "update failed for tuple." << endl; return(2); } } } // print data TRACE(); cout << "ordered set is ... " << oset << endl; // declare ordered set TRACE(); cout << "creating copied oset ..." << endl; OrderedSet<Tuple<int, int> > oset2(oset); // print data TRACE(); cout << "copied ordered set is ... " << oset2 << endl; // updating data TRACE(); cout << "UPDATING COPIED OSET ..." << endl; for (int arg = 1; arg < argc; arg++) { TRACE(); cout << "retrieving data from copied set." << endl; List<Tuple<int, int> > tlist; Tuple<int, int> tuple(atoi(argv[arg]), 0); if (oset2.retrieve(tuple, tlist) != OK) { TRACE(); cout << "retrieve failed for copied oset." << endl; return(2); } for (int i=1; !tlist.isEmpty(); i++) { if (tlist.removeAtEnd(tuple) != OK) { TRACE(); cout << "remove at end failed." << endl; return(2); } TRACE(); cout << "updating tuple ... " << tuple << endl; if (oset2.update(tuple, i) != OK) { TRACE(); cout << "update failed for tuple." << endl; return(2); } TRACE(); cout << "counts are ... " << oset2.getSize(tuple) << endl; } } TRACE(); cout << "UPDATED COPIED ORDERED SET IS ... " << oset2 << endl; TRACE(); cout << "total counts are ... " << oset2.getSize() << endl; // updating data TRACE(); cout << "UPDATING COPIED OSET (2) ..." << endl; for (int arg = 1; arg < argc; arg++) { TRACE(); cout << "retrieving data from copied set." << endl; List<Tuple<int, int> > tlist; Tuple<int, int> tuple(atoi(argv[arg]), 0); if (oset2.retrieve(tuple, tlist) != OK) { TRACE(); cout << "retrieve failed for copied oset." << endl; return(2); } tlist.clear(); TRACE(); cout << "updating clause ... " << tuple << endl; if (oset2.update(tuple, tlist) != OK) { TRACE(); cout << "update failed for tuple." << endl; return(2); } TRACE(); cout << "counts are ... " << oset2.getSize(tuple) << endl; } TRACE(); cout << "UPDATED COPIED ORDERED SET (2) IS ... " << oset2 << endl; TRACE(); cout << "total counts are ... " << oset2.getSize() << endl; // assignment oset2 = oset; TRACE(); cout << "ASSIGNED COPIED ORDERED SET (3) IS ... " << oset2 << endl; // removing data TRACE(); cout << "REMOVING COPIED OSET (2) ..." << endl; for (int arg = 1; arg < argc; arg++) { TRACE(); cout << "retrieving data from copied set." << endl; List<Tuple<int, int> > tlist; Tuple<int, int> tuple(atoi(argv[arg]), 0); if (oset2.retrieve(tuple, tlist) != OK) { TRACE(); cout << "retrieve failed for copied oset." << endl; return(2); } TRACE(); cout << "removing clause ... " << tuple << endl; if (oset2.remove(tuple, 2) != OK) { TRACE(); cout << "remove (2) failed for tuple." << endl; return(2); } if (oset2.remove(tuple, 4) != OK) { TRACE(); cout << "remove (4) failed for tuple." << endl; return(2); } TRACE(); cout << "counts are ... " << oset2.getSize(tuple) << endl; } TRACE(); cout << "REMOVED COPIED ORDERED SET (1) IS ... " << oset2 << endl; TRACE(); cout << "total counts are ... " << oset2.getSize() << endl; // removing data TRACE(); cout << "REMOVING ALL COPIED OSET (2) ..." << endl; for (int arg = 1; arg < (argc-1); arg++) { TRACE(); cout << "removing clause ... " << endl; Tuple<int, int> tuple(atoi(argv[arg]), 0); if (oset2.remove(tuple) != OK) { TRACE(); cout << "remove failed for tuple." << endl; return(2); } TRACE(); cout << "counts are ... " << oset2.getSize(tuple) << endl; } TRACE(); cout << "REMOVED COPIED ORDERED SET (2) IS ... " << oset2 << endl; TRACE(); cout << "total counts are ... " << oset2.getSize() << endl; // all done return(0); }