Beispiel #1
0
inline void AudioDataOutput::convertAndEmit(const QVector<qint16> &leftBuffer, const QVector<qint16> &rightBuffer)
{
    //TODO: Floats
    IntMap map;
    map.insert(Phonon::AudioDataOutput::LeftChannel, leftBuffer);
    map.insert(Phonon::AudioDataOutput::RightChannel, rightBuffer);
    emit dataReady(map);
}
Beispiel #2
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);		
	}
}
	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 #4
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 #5
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 #6
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 #7
0
bool Init()
{
	int nRandom = 0;
	for (int i = 0; i < g_nMax; ++i)
	{
		nRandom = i;
		g_nSummary += nRandom;
		g_dInts.push_back(nRandom);
		g_hmInts.insert(std::make_pair(nRandom, nRandom));
		g_hsInts.insert(nRandom);
		g_lInts.push_back(nRandom);
		g_mInts.insert(std::make_pair(nRandom, nRandom));
		g_mmInts.insert(std::make_pair(nRandom, nRandom));
		g_msInts.insert(nRandom);
		g_sInts.insert(nRandom);
		g_vInts.push_back(nRandom);
	}
	return true;
}
Beispiel #8
0
/// Read comma separated list of integers representing a map. There must be an
/// an even number of integers - even numbers are keys, odd numbers are values.
/// For example the string "1,5,8,1" specifies a map where 1 -> 5 and 8 -> 1.
static IntMap read_map(std::istream &in)
{
  IntMap map;
  std::string contents;
  while (1) {
    auto c = in.get();
    if (!in.good())
      break;
    if (std::isspace(c))
      continue;
    contents.push_back(c);
  }
  // Parse into a list of integers.
  std::vector<long> values;
  const char *p = contents.c_str();
  while (*p != '\0') {
    char *endp;
    auto value = std::strtol(p, &endp, 10);
    if (endp == p) {
      std::cerr << "error: unexpected format\n";
      std::exit(1);
    }
    values.push_back(value);
    p = endp;
    if (*p == ',') {
      ++p;
    } else if (*p != '\0') {
      std::cerr << "error: unexpected format\n";
      std::exit(1);
    }
  }
  if ((values.size() % 2) != 0) {
    std::cerr << "error: odd number of values\n";
    std::exit(1);
  }
  // Add values to map.
  for (unsigned i = 0, e = values.size(); i != e; i += 2) {
    map.insert(std::make_pair(values[i], values[i + 1]));
  }
  return map;
}
Beispiel #9
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 #10
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);
}
static bool
reduce_using_crc(IntMap &map,
                 bool allow_conflicts,
                 std::vector<std::unique_ptr<Step>> &steps)
{
    IntPairs map_entries(begin(map), end(map));
    std::vector<uint32_t> unique_values;
    unique_values.reserve(map_entries.size());
    for (const auto &entry : map_entries) {
        unique_values.push_back(entry.second);
    }
    std::sort(unique_values.begin(), unique_values.end());
    unique_values.erase(std::unique(unique_values.begin(), unique_values.end()),
                        unique_values.end());
    unsigned num_unique_values = unique_values.size();
    uint32_t collision_sentinal;
    if (allow_conflicts) {
        collision_sentinal = find_unused_value(unique_values);
        ++num_unique_values;
    }
    uint32_t best = 0;
    HashCost best_cost = HashCost::max();
    if (allow_conflicts) {
        best_cost.num_collisions = map_entries.size() / 4;
    } else {
        best_cost.num_collisions = 0;
        best_cost.table_size = get_lookup_table_size(map_entries);
        if (best_cost.table_size <= 4)
            return true;
        best_cost.table_size -= 4;
    }
    IntMap tmp;
    tmp.reserve(map_entries.size());
    unsigned min_width = log2_ceil(num_unique_values) - 1;
    for (unsigned width = min_width; width < 32; width++) {
        // Don't check polynomials of higher widths - we are unlikely to get any
        // further improvement.
        if (best != 0 || (1 << width) > best_cost.table_size)
            break;
        for (uint32_t poly = 1 << width; poly < (1 << (width + 1));
                poly++) {
            auto hash = [=](uint32_t x) {
                return crc32(x, poly, poly);
            };
            HashCost cost;
            if (apply_hash_to_map(map_entries, hash, best_cost, collision_sentinal,
                                  tmp, cost)) {
                best = poly;
                best_cost = cost;
            }
        }
    }
    if (best == 0)
        return true;
    auto hash = [=](uint32_t x) {
        return crc32(x, best, best);
    };
    if (best_cost.num_collisions != 0) {
        HashCost dummy;
        apply_hash_to_map(map_entries, hash, HashCost::max(), collision_sentinal,
                          tmp, dummy);
        DataType data_type = pick_datatype(tmp);
        steps.push_back(
            std::unique_ptr<Step>(
                new CrcLookupAndReturnStep(best, std::move(tmp), data_type,
                                           collision_sentinal)
            )
        );
        // Build map containing only conflicting keys.
        IntMap remaining;
        for (const auto &entry : map) {
            uint32_t x = entry.first;
            if (steps.back()->apply(x) != Step::DONE) {
                remaining.insert(entry);
            }
        }
        std::swap(map, remaining);
        return false;
    } else {
        apply_hash_to_map(map_entries, hash, map);
        steps.push_back(std::unique_ptr<Step>(new CrcStep(best)));
        return true;
    }
}