示例#1
0
void mapOr(const HT& leftExp, const HT& rightExp, HT& result)
{
	result.clear();
	vector<int> vl(leftExp.size()), vr(rightExp.size()), vm;
	transform(leftExp.begin(), leftExp.end(), vl.begin(), keySel);   
	transform(rightExp.begin(), rightExp.end(), vr.begin(), keySel); 
	sort(vl.begin(), vl.end());
	sort(vr.begin(), vr.end());
	set_union(vl.cbegin(), vl.cend(), vr.cbegin(), vr.cend(), inserter(vm, vm.begin()));
	int i=0;
	for (auto it = vm.cbegin(); it != vm.cend(); ++it, ++i)
		result.insert(HT::value_type((*it), i));
}
inline
typename HT::size_type
get_keys(HT& ht, typename HT::key_type* keys)
{
  typename HT::size_type num_keys = 0;

  typename HT::size_type stream_id = 0;
  typename HT::size_type num_streams = 1;

  #pragma mta use 100 streams
  #pragma mta for all streams stream_id of num_streams
  {
    typename HT::thread_iterator begin = ht.begin(stream_id, num_streams);
    typename HT::thread_iterator end = ht.end(stream_id, num_streams);

    // Claim a block of indices for the occupied entries in the stream's
    // region.
    typename HT::size_type start_index = mt_incr(num_keys, end - begin);

    // Get the keys from this stream's region.
    for ( ; begin != end; ++begin)
    {
      keys[start_index] = begin->first;
      ++start_index;
    }
  }

  return num_keys;
}
inline
void assign_contiguous_ids(HT& ht, typename HT::size_type starting_value = 0)
{
  typename HT::size_type stream_id = 0;
  typename HT::size_type num_streams = 1;

  #pragma mta use 75 streams
  #pragma mta for all streams stream_id of num_streams
  {
    typename HT::thread_iterator begin_iter = ht.begin(stream_id, num_streams);
    typename HT::thread_iterator end_iter = ht.end(stream_id, num_streams);

    // Claim a block of indices for the occupied entries in the stream's
    // region.
    typename HT::size_type start_index = mt_incr(starting_value,
                                                 end_iter - begin_iter);

    // Assign contiguous ids to the occupied entries in this stream's
    // region.
    for ( ; begin_iter != end_iter; ++begin_iter)
    {
      begin_iter->second = start_index;
      ++start_index;
    }
  }
}
示例#4
0
文件: main.cpp 项目: CCJY/coliru
void debug_buckets(HT const& hashtable) {
    std::multimap<size_t, MyClass const*> debug_map;
    std::transform(hashtable.begin(), hashtable.end(), 
            std::inserter(debug_map, debug_map.end()), 
            [&](MyClass const& mc) { return std::make_pair(hashtable.bucket(mc), &mc); }
        );

    std::cout << "\nDebugging buckets of hashtable\n";
    for (auto& entry : debug_map)
        std::cout << "Debug bucket: " << entry.first << " -> " << *entry.second << "\n";
}
示例#5
0
//***********************************************************************
void erase(HT& T, int start, int finish)
{
	if (!T.empty()) {
		int s = T.size();
		for (int i = start; i < s && i <= finish; ++i) {
			for (HT::iterator it = T.begin(); it != T.end(); ++it)
				if (it->second == i) {
					T.erase(it);
					break;
				}
		}
		for (auto &temp : T)
			if (temp.second >= finish)
				temp.second = temp.second - (finish - start) - 1;
	}
}
示例#6
0
 /// Get a const iterator to first item
 const_iterator begin() const { return m_ht.begin(); }
示例#7
0
 /// Get an iterator to first item
 iterator begin()             { return m_ht.begin(); }