示例#1
0
文件: menu.c 项目: suborb/reelvdr
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();
   }
}
示例#2
0
	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;
	}
示例#3
0
	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;
	}
示例#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);		
	}
}
示例#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));
		}
	}
示例#7
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;
}
示例#8
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);
	}		
}
示例#9
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);
    }
}
示例#10
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;
}
示例#11
0
        vector<int> topKFrequent(vector<int>& nums, int k) {
            typedef std::map<int, int> IntMap;
            typedef IntMap::iterator IMIter;

            IntMap countMap;
            for(size_t i = 0, sz = nums.size(); i < sz; ++i)
            {
                if(countMap.find(nums[i]) != countMap.end())
                {
                    countMap[nums[i]] = countMap[nums[i]] + 1;
                }
                else
                {
                    countMap[nums[i]] = 1;
                }
            }

            typedef std::map<int, std::vector<int>* > OrderMap;
            typedef OrderMap::iterator OMIter;
            typedef OrderMap::reverse_iterator OMRter;
            OrderMap orderMap;
            for(IMIter itr = countMap.begin(), end = countMap.end(); itr != end; ++itr)
            {
                if(orderMap.find(itr->second) != orderMap.end())
                {
                    orderMap[itr->second]->push_back(itr->first);
                }
                else
                {
                    std::vector<int>* vec = new std::vector<int>();
                    vec->push_back(itr->first);
                    orderMap[itr->second] = vec;
                }
            }

            std::vector<int> result;
            int count = 0;
            for(OMRter itr = orderMap.rbegin(), end = orderMap.rend(); itr != end && count != k; ++itr)
            {
                std::vector<int>* vec = itr->second;
                for(size_t i = 0, sz = vec->size(); i < sz && count != k; ++i, ++count)
                {
                    result.push_back((*vec)[i]);
                }
            }

            return result;
        }