我知道字典在 python 中是原子的,但是(如果我错了,请纠正我)这意味着一次只能完成对字典的一个添加。根据 concurrentHashMap 的 Java 页面:“该表在内部进行了分区,以尝试允许指定数量的并发更新而不会发生争用。” python中的原子插入不会与Java实现的速度相比
编辑:当我写“这意味着一次只能完成对词典的一个添加”时,我的意思是说词典的状态将根据单个词典的添加进行离散化
我有以下内容:
int a = 10001000;
int b = 10000000;
Run Code Online (Sandbox Code Playgroud)
我想要以下输出:
(a&b) = 10000000;
Run Code Online (Sandbox Code Playgroud)
但我的问题是java在使用"&"操作之前转换为二进制,我真的希望能够以上述方式在整数上使用它.可以这样做吗?
我有下面的代码:
map<int,int>& myMap = new map<int,int>();
Run Code Online (Sandbox Code Playgroud)
但我得到以下编译器错误:
no suitable constructor exists to convert from "std::map<int,int, std::less<int>, std::allocator<std::pair<const int, int>>>*" to "std::map<int,int, std::less<int>, std::allocator<std::pair<const int, int>>>".
Run Code Online (Sandbox Code Playgroud)
这是否意味着我必须这样做:
map<int,int>& myMap = *new map<int,int>();
Run Code Online (Sandbox Code Playgroud)
我认为对象可以传递给引用而不首先解除引用(而不是指针)?此外,我知道智能指针存在,但我现在不想尝试使用它们.