简体   繁体   English

C ++ parallel_unordered_map C ++ 11 Microsoft使用unsigned long作为键/ HASH函数

[英]C++ concurrent_unordered_map C++11 Microsoft Using unsigned long as key / HASH Function

I'm using Visual Studio 2012 in Windows 7 64 bit. 我正在Windows 7 64位中使用Visual Studio 2012。

I need to use concurrent data structures because I will be using threads. 我需要使用并发数据结构,因为我将使用线程。 I found that microsoft has a few http://msdn.microsoft.com/en-us/library/dd504906.aspx#unordered_map 我发现微软有一些http://msdn.microsoft.com/en-us/library/dd504906.aspx#unordered_map

In general, I have to process 一般来说,我必须处理

receive data into a queue.... process when ready ... keep receiving data. 将数据接收到队列中。准备就绪的过程继续接收数据。

I'm going to use concurrent_unordered_map Class provided by microsoft to have a cuncurrent map that stores a class named TouchInfo.Each TouchInfo object has a unique ID (unsigned long) which is what I used to retrieve the object as it needs to be updated. 我将使用由Microsoft提供的current_unordered_map类具有一个并存的映射,该映射存储名为TouchInfo的类。每个TouchInfo对象都有一个唯一的ID(无符号长),这是我用来检索该对象的原因,因为它需要更新。

At the same time, I need to insert TouchInfo into a concurrent queue... Once the queue hits a number I process the queue... (Different thread) 同时,我需要将TouchInfo插入并发队列中。一旦队列中出现一个数字,我就对该队列进行处理...(不同的线程)

1. My first question is if I need a special hash function of the unsigned long... The unsigned long is an ID (dwID) given by the system from the multi-touch system in Windows 7 (WinUser.h) Since I have no control of the ID, I want to make sure that my hash function is optimized. 1.我的第一个问题是我是否需要unsigned long的特殊哈希函数... unsigned long是系统从Windows 7中的多点触摸系统(WinUser.h)给定的ID(dwID),因为没有ID的控制,我想确保我的哈希函数得到了优化。

typedef struct tagTOUCHINPUT {
    LONG x;
    LONG y;
    HANDLE hSource;
    DWORD dwID;
    DWORD dwFlags;
    DWORD dwMask;
    DWORD dwTime;
    ULONG_PTR dwExtraInfo;
    DWORD cxContact;
    DWORD cyContact;
   } TOUCHINPUT, *PTOUCHINPUT;

Maybe, I don't have to do anything and just declare 也许我不需要做任何事情,只是声明

I seen in the web that some people use Boost to create the Hash... 我在网路上看到有人使用Boost来建立Hash ...

Any input and changes in my design, are completely welcome... 我对设计的任何输入和更改都将受到欢迎...

The Answer to my question is most welcome! 非常欢迎回答我的问题!

Thanks! 谢谢!

concurrent_unordered_map uses std::hash , which has a default implementation for unsigned long . concurrent_unordered_map使用std::hash ,其默认实现为unsigned long It'll work fine right out of the box. 开箱即用就可以了。

The default hash tries to be optimal for most use cases, but there are no guarantees because everyone's data is different. 默认散列试图在大多数用例中都是最佳的,但是不能保证,因为每个人的数据都是不同的。 Definitely benchmark it before going crazy looking at hash functions (there are plenty, and you might waste lots of time). 在疯狂地研究哈希函数之前,一定要对其进行基准测试(有很多,可能会浪费很多时间)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM