Пример #1
0
//*********************************************************
SetType SetSquad(ifstream & fin, VecPlayerType & pVec,int num, MapSquadType & squadMap){
  char type;
  string pName= "";
  int pRow;
  int pCol;
  char direction;
  SetType squad;
  Player * p;
  BoardClass * bd= BoardClass::GetBd();
  
  fin>> type;
  while(type != 'q' && fin){
    fin>> pName;
    fin>> pRow;
    fin>> pCol;
    fin>> direction;
    p= CreaterPlayer(pName, type);
    bd->BoardClass::PlacePlayer(p, pRow, pCol);
    p->Active();
    p->ResetMomentum();
    p->DropWeapon();
    p->SetDir(direction);
    pVec.push_back(p);
    squad.insert(pName);
    squadMap.insert(make_pair(p->Name(), SquadType(num)));
    fin>> type;
  }
  return squad;
}
Пример #2
0
inline bool lexicographical_equal(const SetType& left, const SetType& right)
{
    if(&left == &right)
        return true;
    else return left.iterative_size() == right.iterative_size()
             && std::equal(left.begin(), left.end(), right.begin()); 
}
void buildSetNames(const SetType & setData,std::vector<std::string> & names)
{
   // pull out all names for this set
   for(typename SetType::const_iterator itr=setData.begin();itr!=setData.end();++itr) {
      Ioss::GroupingEntity * entity = *itr;
      names.push_back(entity->name());
   }
}
 SetType& prompt_set(std::string preface, std::string message = "  Enter element for s2") {
   static SetType s2;
   s2.clear();
   for (;;) {
     std::string e = ics::prompt_string(preface + message + "(QUIT to quit)");
     if (e == "QUIT")
       break;
     s2.insert(e);
   }
   return s2;
 }
bool ULoadGroupInfo::IsLevelInLoadGroup(FName level, ELoadGroups lg) {
    MapType::iterator it = LoadGroups.find(lg);
    if ( it == LoadGroups.end() ) {
        return false;
    }

    SetType map = it->second;

    SetType::iterator it2 = map.find(level);
    if ( it2 == map.end() ) {
        return false;
    }
    return true;
}
Пример #6
0
bool intersects(const SetType& left, const SetType& right)
{
    typename SetType::const_iterator common_lwb_right_, common_upb_right_;
    if(!common_range(common_lwb_right_, common_upb_right_, right, left))
        return false;

    typename SetType::const_iterator right_ = common_lwb_right_, found_;
    while(right_ != common_upb_right_)
    {
        found_ = left.find(*right_++);
        if(found_ != left.end()) 
            return true; // found a common element
    }
    // found no common element
    return false;    
}
Пример #7
0
// if we ghave already fetched the rows because we recieved a
// size message, return one of those rows. otherwise try to
// get a unique row anf fail noisily if that seems not possible
Row DSUnique :: Get() {
	if ( mPos >= 0 ) {
		Row r = mRows[ mPos++];
		mPos %= mRows.size();
		return Order( r );
	}
	else {
		int n = mRetry;
		while( n-- ) {
			Row r = CompositeDataSource::Get();
			if ( mUniqueRows.find( r ) == mUniqueRows.end() ) {
				mUniqueRows.insert( r );
				return Order( r );
			}
		}
		throw Exception( "cannot find enough unique values" );
	}
}
Пример #8
0
bool overwriteInSet(SetType& m, const typename SetType::value_type& v) {
   std::pair<typename SetType::iterator, bool> result =
     m.insert(v);
   if (!result.second) {
     typename SetType::value_type& theIt = const_cast<typename SetType::value_type&>(*(result.first));
     theIt = v;
   }
   return result.second;
}
Пример #9
0
void process_tile_log(const char* filename) 
{
	ifstream infile(filename);
	char line[1024];	

	SetType uniqueSet;
	RetType ret;
	int repeatHitCounter = 0;
	int totalCounter = 0;
	cout << "==========================\n";

	while ( infile.getline(line, 1024) )
	{
		char* ptr = line;
		for (; *ptr != 'm' && *ptr != '\0'; ptr++)
			;

		// cout << ptr << endl;

		if (*ptr) 
		{
			totalCounter++;

			ret = uniqueSet.insert( string(ptr) );
			if (!ret.second) 
			{
				repeatHitCounter++;
				cout << "ERROR\t" << ptr << endl;
			}
		}

		if (totalCounter >= 100) {
			break;
		}	// µ×ͼÍßƬÎÆÀí»º´æ×î¶à100¸ö£¡
	}
	float rate = totalCounter > 0 ? (repeatHitCounter*1.0f / totalCounter) : 0;
	cout << "repeat hit rate = " << rate << endl;
	cout << "total hit = " << totalCounter << "\t" << "repeat hit = " << repeatHitCounter << endl;
	cout << "==========================\n";

	infile.close();
	uniqueSet.clear();
}
  void process_iterator_commands(SetType& s, std::string preface) {
    std::string allowable[] = {"<","e","*","+","+o","c","*a","ea","f","q",""};
    ics::Iterator<std::string>& i = s.abegin();
    for (;;)
      try {
        std::cout << "\n"+preface+"i = " << i.str() << std::endl;
        std::string i_command = ics::prompt_string(preface+
            "Enter iterator command(<[<]/e[rase]/*/+[+e]/+[+]o/c[ommands]/*a[ll]/ea[ll]/f[or]/q[uit])","",allowable);
        if (i_command == "<")
          std::cout << preface+"  << = " << i << std::endl;
        else if (i_command == "e")
          std::cout << preface+"  erase = " << i.erase() << std::endl;
        else if (i_command == "*")
          std::cout << preface+"  * = " << *i << std::endl;
        else if (i_command == "+")
          ++i;
        else if (i_command == "+o")
          i++;
        else if (i_command == "c")
          process_commands(preface);
        else if (i_command == "*a") {
          std::cout << preface+"  initially i = " << i << std::endl;
          for (; i != s.aend(); ++i)
            std::cout << preface+"  *(all) = " << *i << std::endl;
          std::cout << preface+"  finally i = " << i << std::endl;
        }
        else if (i_command == "ea") {
          std::cout << preface+"  initially i = " << i << std::endl;
         for (; i != s.aend(); ++i)
            std::cout << preface+"  erase(all) = " << i.erase() << std::endl;
          std::cout << preface+"  finally i = " << i << std::endl;
        }
        else if (i_command == "f") {
          for (auto v : s)
            std::cout << preface+"  *(all) = " << v << std::endl;
        }
        else if (i_command == "q")
          break;

      } catch (ics::IcsError& e) {
        std::cout << preface+"  " << e.what() << std::endl;
      }
  };
Пример #11
0
inline bool within(const SetType& sub, const SetType& super)
{
    if(&super == &sub)                   return true;
    if(icl::is_empty(sub))               return true;
    if(icl::is_empty(super))             return false;

    typename SetType::const_iterator common_lwb_, common_upb_;
    if(!common_range(common_lwb_, common_upb_, sub, super))
        return false;

    typename SetType::const_iterator sub_ = common_lwb_, super_;
    while(sub_ != common_upb_)
    {
        super_ = super.find(*sub_++);
        if(super_ == super.end()) 
            return false;
    }
    return true;
}
Пример #12
0
// if we receive size message read rows from kids discarding dupes
// and use those rows to fufill future requests
int DSUnique :: Size() {

	if ( mPos >= 0 ) {			// already have size
		return mRows.size();
	}

	int n = CompositeDataSource::Size();
	while( n-- ) {
		Row r = CompositeDataSource::Get();
		if ( mUniqueRows.find( r ) == mUniqueRows.end() ) {
			mUniqueRows.insert( r );
			mRows.push_back( r );
		}
	}
	//ALib::Dump( std::cout, mRows );
	mPos = 0;
	if ( mRows.size() == 0 ) {
		throw Exception( "Empty result set" );
	}
	return mRows.size();
}
    std::string menu_prompt (std::string preface) {
      std::cout << "\n\n"+preface+"set s = " << s.str() << std::endl;
      std::cout << preface+"Mutators         Accessors              General" << std::endl;
      std::cout << preface+"  i  - insert      m  - empty             l  - load from file" << std::endl;
      std::cout << preface+"  I  - insert      s  - size              it - iterator commands" << std::endl;
      std::cout << preface+"  e  - erase       c  - contains          q  - quit" << std::endl;
      std::cout << preface+"  E  - erase       C  - contains"  << std::endl;
      std::cout << preface+"  x  - clear       <  - <<"        << std::endl;
      std::cout << preface+"  R  - retain      r  - relations" << std::endl;
      std::cout << preface+"  =  - ="      << std::endl;

      std::string allowable[] = {"i","I","e","E","x","R","=","m","s","c","C","<","r","l","it","q",""};
      return ics::prompt_string("\n"+preface+"Enter set command","",allowable);
    }
Пример #14
0
 std::vector<typename SetType::VectorType> getCorners(const SetType & set) {
   typedef typename SetType::VectorType VectorType;
   std::vector<VectorType> cor;
   VectorType v = set.get_r();
   corners(v, set.get_r(), 0, v.dimension(), cor);
   for(typename std::vector<VectorType>::iterator it = cor.begin(); it != cor.end(); ++it){
     *it = set.get_x() + set.get_C() * set.get_r0() + set.get_B() * *it;
   }
   return cor;
 }
Пример #15
0
void GMStandard::multiply ( const SetType & rowSet, const SetType & columnSet, NICE::Vector & y, const NICE::Vector & x) const
{
  if ( x.size() != columnSet.size() ) 
    fthrow(Exception, "Size of the column set is different from the size of the given input vector: " << columnSet.size() << " vs " << x.size());
  
  y.resize( rowSet.size() );

  // memory inefficient
  Matrix Asub ( rowSet.size(), columnSet.size() );

  int ii = 0;
  for ( SetType::const_iterator i = rowSet.begin(); i != rowSet.end(); i++,ii++ )
  {
    int jj = 0;
    for ( SetType::const_iterator j = columnSet.begin(); j != columnSet.end(); j++,jj++ )
      Asub ( ii, jj ) = A( *i, *j ); 
  }

  y.multiply ( Asub, x );
}
Пример #16
0
                            "Hello World \xd1\x88\xd0\xbd\xd1\x83"));

  EXPECT_FALSE(istringEqual("Hello World \xd1\x88\xd0\xbd\xd1\x83\xd1\x80",
                            "Hello World \xd1\x80\xd1\x88\xd0\xbd\xd1\x83"));

  LOG_FREE(Info, "Compare", "Leaving istringEqualMixed")
}


TEST(Compare, IstringCompare)
{
  LOG_FREE(Info, "Compare", "Entering IstringEqual")

  // make sure insensitive string compare functor works for sets
  typedef std::set<string, IstringCompare> SetType;
  SetType words;
  words.insert("lorem ipsum");

  auto it = words.find("lorem ipsum");
  ASSERT_TRUE(words.end() != it);

  auto it2 = words.find("LOREM IPSUM");
  EXPECT_TRUE(it == it2);

  it2 = words.find("lOrEm IpsUm");
  EXPECT_TRUE(it == it2);

  it2 = words.find("LoReM iPSuM");
  EXPECT_TRUE(it == it2);

  it2 = words.find("dolor sit amet");
  void process_commands(std::string preface) {
    for (;;) try {
      std::string command = menu_prompt(preface);

      if (command == "i") {
        std::string e = ics::prompt_string(preface+"  Enter element to add");
        std::cout << preface+"  insert = " << s.insert(e) << std::endl;
      }

      else if (command == "I") {
        SetType s2(prompt_set(preface));
        std::cout << "  insert = " << s.insert(s2.abegin(),s2.aend()) << std::endl;;
      }

      else if (command == "e") {
        std::string e = ics::prompt_string(preface+"  Enter element to erase");
        std::cout << preface+"  erase = " << s.erase(e) << std::endl;
      }

      else if (command == "E") {
        SetType s2(prompt_set(preface));
        std::cout << "  erase = " << s.erase(s2.abegin(),s2.aend()) << std::endl;;
      }

      else if (command == "x")
        s.clear();

      else if (command == "R") {
        SetType s2(prompt_set(preface));
        std::cout << "  retain = " << s.retain(s2.abegin(),s2.aend()) << std::endl;
      }

      else if (command == "=") {
        SetType s2(prompt_set(preface));
        s = s2;
        std::cout << "  s now = " << s << std::endl;
      }

      else if (command == "m")
        std::cout << preface+"  empty = " << s.empty();

      else if (command == "s")
        std::cout << preface+"  size = " << s.size() << std::endl;


      else if (command == "c") {
        std::string e = ics::prompt_string(preface+"  Enter element to erase");
        std::cout << preface+"  contains = " << s.contains(e) << std::endl;
      }

      else if (command == "C") {
        SetType s2(prompt_set(preface));
        std::cout << "  contains = " << s.contains(s2.abegin(),s2.aend()) << std::endl;
      }

      else if (command == "<")
        std::cout << preface+"  << = " << s.str() << std::endl;

      else if (command == "r") {
        std::cout << preface+"  s == s = " << (s == s) << std::endl;
        std::cout << preface+"  s != s = " << (s != s) << std::endl;
        std::cout << preface+"  s <= s = " << (s <= s) << std::endl;
        std::cout << preface+"  s <  s = " << (s <  s) << std::endl;
        std::cout << preface+"  s >  s = " << (s >  s) << std::endl;
        std::cout << preface+"  s >= s = " << (s >= s) << std::endl;

        SetType s2(prompt_set(preface));
        std::cout << preface+"  s = " << s << " ?? s2 = " << s2 << std::endl;
        std::cout << preface+"  s == s2 = " << (s == s2) << std::endl;
        std::cout << preface+"  s != s2 = " << (s != s2) << std::endl;
        std::cout << preface+"  s <= s2 = " << (s <= s2) << std::endl;
        std::cout << preface+"  s <  s2 = " << (s <  s2) << std::endl;
        std::cout << preface+"  s >  s2 = " << (s >  s2) << std::endl;
        std::cout << preface+"  s >= s2 = " << (s >= s2) << std::endl;
      }

      else if (command == "l") {
        std::ifstream in_set;
        ics::safe_open(in_set,preface+"  Enter file name to read", "load.txt");
        std::string e;
        while (getline(in_set,e))
          s.insert(e);
        in_set.close();
      }

      else if (command == "it")
        process_iterator_commands(s, "it:  "+preface);

      else if (command == "q")
        break;

      else
        std::cout << preface+"\""+command+"\" is unknown command" << std::endl;

    } catch (ics::IcsError& e) {
      std::cout << preface+"  " << e.what() << std::endl;
    }

  };
Пример #18
0
  Expr add(SetType t, Expr e) {

    if(setTypes.find(t) == setTypes.end() ) {
      // mark as processed
      setTypes.insert(t);

      Type elementType = t.getElementType();
      ostringstream oss_type;
      oss_type << language::SetLanguage(language::output::LANG_SMTLIB_V2)
               << elementType;
      string elementTypeAsString = oss_type.str();
      elementTypeAsString.erase(
        remove_if(elementTypeAsString.begin(), elementTypeAsString.end(), nonsense),
        elementTypeAsString.end());

      // define-sort
      ostringstream oss_name;
      oss_name << language::SetLanguage(language::output::LANG_SMTLIB_V2)
               << "(Set " << elementType << ")";
      string name = oss_name.str();
      Type newt = em->mkArrayType(t.getElementType(), em->booleanType());
      mapTypes[t] = newt;

      // diffent types
      vector<Type> t_t;
      t_t.push_back(t);
      t_t.push_back(t);
      vector<Type> elet_t;
      elet_t.push_back(elementType);
      elet_t.push_back(t);

      if(!enableAxioms)
        sout << "(define-fun emptyset" << elementTypeAsString << "    "
             << " ()"
             << " " << name
             << " ( (as const " << name << ") false ) )" << endl;
      setoperators[ make_pair(t, kind::EMPTYSET) ] =
        em->mkVar( std::string("emptyset") + elementTypeAsString,
                   t);

      if(!enableAxioms)
        sout << "(define-fun singleton" << elementTypeAsString << "     "
             << " ( (x " << elementType << ") )"
             << " " << name << ""
             << " (store emptyset" << elementTypeAsString << " x true) )" << endl;
      setoperators[ make_pair(t, kind::SINGLETON) ] =
        em->mkVar( std::string("singleton") + elementTypeAsString,
                   em->mkFunctionType( elementType, t ) );

      if(!enableAxioms)
        sout << "(define-fun union" << elementTypeAsString << "       "
             << " ( (s1 " << name << ") (s2 " << name << ") )"
             << " " << name << ""
             << " ((_ map or) s1 s2))" << endl;
      setoperators[ make_pair(t, kind::UNION) ] =
        em->mkVar( std::string("union") + elementTypeAsString,
                   em->mkFunctionType( t_t, t ) );

      if(!enableAxioms)
        sout << "(define-fun intersection" << elementTypeAsString << ""
             << " ( (s1 " << name << ") (s2 " << name << ") )"
             << " " << name << ""
             << " ((_ map and) s1 s2))" << endl;
      setoperators[ make_pair(t, kind::INTERSECTION) ] =
        em->mkVar( std::string("intersection") + elementTypeAsString,
                   em->mkFunctionType( t_t, t ) );

      if(!enableAxioms)
        sout << "(define-fun setminus" << elementTypeAsString << "    "
             << " ( (s1 " << name << ") (s2 " << name << ") )"
             << " " << name << ""
             << " (intersection" << elementTypeAsString << " s1 ((_ map not) s2)))" << endl;
      setoperators[ make_pair(t, kind::SETMINUS) ] =
        em->mkVar( std::string("setminus") + elementTypeAsString,
                   em->mkFunctionType( t_t, t ) );

      if(!enableAxioms)
        sout << "(define-fun member" << elementTypeAsString << "          "
             << " ( (x " << elementType << ")" << " (s " << name << "))"
             << " Bool"
             << " (select s x) )" << endl;
      setoperators[ make_pair(t, kind::MEMBER) ] =
        em->mkVar( std::string("member") + elementTypeAsString,
                   em->mkPredicateType( elet_t ) );

      if(!enableAxioms)
        sout << "(define-fun subset" << elementTypeAsString << "    "
             << " ( (s1 " << name << ") (s2 " << name << ") )"
             << " Bool"
             <<" (= emptyset" << elementTypeAsString << " (setminus" << elementTypeAsString << " s1 s2)) )" << endl;
      setoperators[ make_pair(t, kind::SUBSET) ] =
        em->mkVar( std::string("subset") + elementTypeAsString,
                   em->mkPredicateType( t_t ) );

      if(enableAxioms) {
        int N = sizeof(setaxioms) / sizeof(setaxioms[0]);
        for(int i = 0; i < N; ++i) {
          string s = setaxioms[i];
          ostringstream oss;
          oss << language::SetLanguage(language::output::LANG_SMTLIB_V2) << elementType;
          boost::replace_all(s, "HOLDA", elementTypeAsString);
          boost::replace_all(s, "HOLDB", oss.str());
          if( s == "" ) continue;
          sout << s << endl;
        }
      }

    }
    Expr ret;
    if(e.getKind() == kind::EMPTYSET) {
      ret = setoperators[ make_pair(t, e.getKind()) ];
    } else {
      vector<Expr> children = e.getChildren();
      children.insert(children.begin(), setoperators[ make_pair(t, e.getKind()) ]);
      ret = em->mkExpr(kind::APPLY, children);
    }
    // cout << "returning " << ret  << endl;
    return ret;
  }