Beispiel #1
0
void TeletextBrowser::ChannelSwitched(int ChannelNumber) {
   cChannel *chan=Channels.GetByNumber(ChannelNumber);
   
   if (!chan)
      return;
      
   tChannelID chid=chan->GetChannelID();
   if (chid==channel || chid==tChannelID::InvalidID)
      return;
      
   channel=chid;
   
   //store page number of current channel
   IntMap::iterator it;
   channelPageMap[currentChannelNumber] = currentPage;
   currentChannelNumber=ChannelNumber;
   
   currentPage=0x100;
   currentSubPage=0;
      
   //see if last page number on this channel was stored
   it=channelPageMap.find(ChannelNumber);
   if (it != channelPageMap.end()) { //found
      currentPage=(*it).second;
   }
   
   //on the one hand this must work in background mode, when the plugin is not active.
   //on the other hand, if active, the page should be shown.
   //so this self-Pointer.
   if (self) {
      self->ShowPage();
   }
}
	int find(int a, int b, int jLen, int bLen) {
		int result = 0;
		IntMap Brus;
		int j;
		int jm = b - jLen + 1;
		for (j = a; j <= jm; ++j) {
			int BrusScore = 9999;
			int k;
			int km = j + jLen - bLen;
			for (k = j; k <= km; ++k) {
				IntMap::const_iterator bf = Brus.find(k);
				if (bf == Brus.end()) {
					// not calculated yet
					int bs = 0;
					int l;
					int lm = k + bLen - 1;
					for (l = k; l <= lm; ++l) {
						bs += isLucky(l);
					}
					Brus[k] = bs;
					BrusScore = min(BrusScore, bs);
				} else {
					BrusScore = min(BrusScore, bf->second);
				}
			}
			result = max(result, BrusScore);
		}
		return result;
	}
	int rec(int mask) {
		if (m.find(mask) != m.end()) {
			return m[mask];
		}
		int &res = m[mask];

		res = 0;

		int i, prev, next;
		prev = 0;
		for (i = 1; i < (len-1); ++i) {
			int b = (1<<i);
			if (mask & b) {
				int a = mask ^ b;
				for (next = i+1; ; ++next) {
					if (mask & (1<<next)) {
						break;
					}
				}

				res = max(res, x[prev]*x[next]+rec(a));

				prev = i;
			}
		}
		return res;
	}
Beispiel #4
0
void HashMapTest::testErase()
{
	const int N = 1000;

	typedef HashMap<int, int> IntMap;
	IntMap hm;

	for (int i = 0; i < N; ++i)
	{
		hm.insert(IntMap::ValueType(i, i*2));
	}
	assert (hm.size() == N);
	
	for (int i = 0; i < N; i += 2)
	{
		hm.erase(i);
		IntMap::Iterator it = hm.find(i);
		assert (it == hm.end());
	}
	assert (hm.size() == N/2);
	
	for (int i = 0; i < N; i += 2)
	{
		IntMap::Iterator it = hm.find(i);
		assert (it == hm.end());
	}
	
	for (int i = 1; i < N; i += 2)
	{
		IntMap::Iterator it = hm.find(i);
		assert (it != hm.end());
		assert (*it == i);
	}

	for (int i = 0; i < N; i += 2)
	{
		hm.insert(IntMap::ValueType(i, i*2));
	}
	
	for (int i = 0; i < N; ++i)
	{
		IntMap::Iterator it = hm.find(i);
		assert (it != hm.end());
		assert (it->first == i);
		assert (it->second == i*2);		
	}
}
Beispiel #5
0
 int getRating(const std::string &game)
 {
   int rate = -1;
   if(ratings.find(game) != ratings.end())
     rate = ratings[game];
   if(rate < -1 || rate > 5) rate = -1;
   return rate;
 }
	static void addInt(const string& name, int i)
	{
		ScopedLock<Mutex> l(mutex);
		IntMap::iterator it = sIntMap.find(name);
		if(it == sIntMap.end())
		{
			sIntMap.insert(IntMap::value_type(name, i));
		}
	}
Beispiel #7
0
        IntMap multiplyMap(const IntMap& m, int f)
        {
            IntMap ret;
            for (IntMap::const_iterator it = m.begin(); it != m.end(); ++it)
            {
                ret[it->first] = it->second * f;
            }

            return ret;
        }
Beispiel #8
0
bool utl::renumber (int& num, int& runner, IntMap& old2new)
{
  IntMap::iterator it = old2new.find(num);
  if (it == old2new.end())
    it = old2new.insert(std::make_pair(num,++runner)).first;

  if (num == it->second) return false;

  num = it->second;
  return true;
}
Beispiel #9
0
void HashMapTest::testInsert()
{
	const int N = 1000;

	typedef HashMap<int, int> IntMap;
	IntMap hm;
	
	assert (hm.empty());
	
	for (int i = 0; i < N; ++i)
	{
		std::pair<IntMap::Iterator, bool> res = hm.insert(IntMap::ValueType(i, i*2));
		assert (res.first->first == i);
		assert (res.first->second == i*2);
		assert (res.second);
		IntMap::Iterator it = hm.find(i);
		assert (it != hm.end());
		assert (it->first == i);
		assert (it->second == i*2);
		assert (hm.count(i) == 1);
		assert (hm.size() == i + 1);
	}		
	
	assert (!hm.empty());
	
	for (int i = 0; i < N; ++i)
	{
		IntMap::Iterator it = hm.find(i);
		assert (it != hm.end());
		assert (it->first == i);
		assert (it->second == i*2);
	}
	
	for (int i = 0; i < N; ++i)
	{
		std::pair<IntMap::Iterator, bool> res = hm.insert(IntMap::ValueType(i, 0));
		assert (res.first->first == i);
		assert (res.first->second == i*2);
		assert (!res.second);
	}		
}
Beispiel #10
0
void ListMapTest::testInsert()
{
    const int N = 1000;

    typedef ListMap<int, int> IntMap;
    IntMap hm;

    assert (hm.empty());

    for (int i = 0; i < N; ++i)
    {
        IntMap::Iterator res = hm.insert(IntMap::ValueType(i, i*2));
        assert (res->first == i);
        assert (res->second == i*2);
        IntMap::Iterator it = hm.find(i);
        assert (it != hm.end());
        assert (it->first == i);
        assert (it->second == i*2);
        assert (hm.size() == i + 1);
    }

    assert (!hm.empty());

    for (int i = 0; i < N; ++i)
    {
        IntMap::Iterator it = hm.find(i);
        assert (it != hm.end());
        assert (it->first == i);
        assert (it->second == i*2);
    }

    hm.clear();
    for (int i = 0; i < N; ++i)
    {
        IntMap::Iterator res = hm.insert(IntMap::ValueType(i, 0));
        assert (res->first == i);
        assert (res->second == 0);
    }
}
Beispiel #11
0
  void write()
  {
    Json::Value v;

    for(IntMap::iterator it = ratings.begin();
        it != ratings.end(); it++)
      {
        v[it->first] = it->second;
      }

    std::string filename = get.getPath("ratings.json");
    writeJson(filename, v);
  }
Beispiel #12
0
bool utl::renumber (int& num, const IntMap& old2new, bool msg)
{
  IntMap::const_iterator it = old2new.find(num);
  if (it == old2new.end())
  {
    if (msg)
      std::cerr <<" *** utl::renumber: Old value "<< num
                <<" does not exist in old2new mapping"<< std::endl;
    return false;
  }

  num = it->second;
  return true;
}
Beispiel #13
0
void HashMapTest::testConstIterator()
{
	const int N = 1000;

	typedef HashMap<int, int> IntMap;
	IntMap hm;

	for (int i = 0; i < N; ++i)
	{
		hm.insert(IntMap::ValueType(i, i*2));
	}
	
	std::map<int, int> values;
	IntMap::ConstIterator it = hm.begin();
	while (it != hm.end())
	{
		assert (values.find(it->first) == values.end());
		values[it->first] = it->second;
		++it;
	}
	
	assert (values.size() == N);
}
Beispiel #14
0
void HashMapTest::testIterator()
{
	const int N = 1000;

	typedef HashMap<int, int> IntMap;
	IntMap hm;

	for (int i = 0; i < N; ++i)
	{
		hm.insert(IntMap::ValueType(i, i*2));
	}
	
	std::map<int, int> values;
	IntMap::Iterator it; // do not initialize here to test proper behavior of uninitialized iterators
	it = hm.begin();
	while (it != hm.end())
	{
		assert (values.find(it->first) == values.end());
		values[it->first] = it->second;
		++it;
	}
	
	assert (values.size() == N);
}
Beispiel #15
0
int utl::findKey (const IntMap& iMap, int iVal)
{
  IntMap::const_iterator it = utl::findValue(iMap,iVal);
  return it == iMap.end() ? iVal : it->first;
}
Beispiel #16
0
IntMap::const_iterator utl::findValue (const IntMap& iMap, int iVal)
{
  return std::find_if(iMap.begin(),iMap.end(),cmpInt(iVal));
}