草庐IT

integer-hashing

全部标签

c++ - "integer constant is too large for ‘long’ 求最大质因数时键入"

我正在解决Euler项目3:Description:Theprimefactorsof13195are5,7,13and29.Whatisthelargestprimefactorofthenumber600851475143?这是我生成答案的代码。但是我需要一个整数类型来保存600851475143。当我在Mac上的GCC上编译它时,我得到:integerconstantistoolargefor‘long’type".我预计longlong可以轻松持有这个数字。我也试过让它未签名。为什么我的代码不能保存这么小的数字?我该怎么做才能让它发挥作用?#include#includeusi

c++ - 为什么我机器上的 hash_map 和 unordered_map 非常慢?

我用这段代码测试了它们(在VisualStudio2010sp1上):#include#include#include#include#includeintmain(){clock_ttime;intLOOP=(1my_map;std::unordered_mapmap_unordered_map;std::hash_mapmy_hash_map;time=clock();for(inti=0;i!=LOOP;++i){my_map[i]=i;}std::cout结果很奇怪:在调试中:map:0.289无序map:10.738HashMap:10.58按任意键继续。..在发布中:map

c++ - int8_t 和 char : converts between pointers to integer types with different sign - but it doesn't

我正在处理一些嵌入式代码,并且正在从头开始编写一些新东西,因此我更愿意坚持使用uint8_t、int8_t等类型。然而,当移植一个函数时:voidfunctionName(char*data)到:voidfunctionName(int8_t*data)在将文字字符串传递给函数时,我收到编译器警告“在指向具有不同符号的整数类型的指针之间转换”。(即调用functionName("putthistextin");时)。现在,我明白了为什么会发生这种情况,并且这些行只是调试,但我想知道人们认为什么是最合适的处理方式,而不是对每个文字字符串进行类型转换。在实践中,我不认为一揽子类型转换比使用

c++ - scanf 与 cin : string as integer processing

我有一个输入字符串“0100”为什么scanf("%i",&n);返回64而cin>>n;给我100?为什么cin以十进制值思考,而scanf以八进制值思考? 最佳答案 Fortheispecifier:  Anynumberofdigits,optionallyprecededbyasign(+or-).Decimaldigitsassumedbydefault(0-9),buta0prefixintroducesoctaldigits(0-7),and0xintroduceshexadecimaldigits(0-f).-sca

c++ - hash_map : why it defines less, 而不是 equal_to

C++,使用VisualStudio2010。关于为什么hash_map的用户定义特征的问题实际上需要总排序。我有一个简单的结构,比如说FOO,它只有一些整数。我想使用hash_map,这是一个哈希表,其键无序,用于存储FOO的结构。.我只需要快速搜索它的关联值,所以这是一个正确的选择:hash_map.但是,我需要为FOO实现自己的哈希函数和一些比较函数.这是hash_map的定义,摘自MSDN:template>,classAllocator=allocator>>classhash_map原来我需要实现hash_compare仿函数:template>classhash_comp

c++ - 出于性能原因替代 stdext::hash_map

我正在开发一个高性能应用程序,其中所有调用都必须合理。我有一张map,在每次交易开始时使用一次来进行我想改进的查找。map在启动时加载,之后不会改变。下面映射中的键是一个std::string但如果需要它可以更改为char数组。C或C++作为解决方案很好。typedefstdext::hash_mapsymbols_t;有没有人知道任何其他可以消除查找或更快的解决方案?提前感谢您的帮助。来自编辑的附加信息:1.hash_map目前有35万个元素。2.每个键值的长度通常在4到10个字符之间。3.从第三方API接收回调信息。回调被赋予一个符号,在进行map查找时用作键值。软件的其余部分由m

以非专用模板作为值的 C++ hash_map

我想要一个std::hash_map将(例如)常规std:string映射到多个不同的特化另一个模板类。这个例子是我想要实现的(虽然它是错误的并且无法编译):templateclassFoo{public:Foo(T_value){this->value=_value;}private:Tvalue;};intmain(){hash_mapvarious_foos;various_foos["foo"]=Foo(17);various_foos["bar"]=Foo(17.4);} 最佳答案 map只能存储单一的值类型,所以不能直接

c++ - 警告 : Comparison between signed and unsigned integer expression

我在codepad.org上运行以下代码时出现此错误。“在成员函数‘doubleXchange::getprice(std::string)’中:第87行:警告:有符号和无符号整数表达式之间的比较”这是我的代码:#include#include#includeusingnamespacestd;classXchange{public:Xchange();//doesnothing(?)doublegetprice(stringsymbol);private:vectorstocks;};doubleXchange::getprice(stringsymbol){for(inti=0;i

c++ - C/C++ : Converting hexadecimal value in char to integer

我将十六进制值存储为字符:charA='0';charB='6';charC='E';...我需要将它们转换为整数。我知道'atoi',但这只适用于十进制编码的字符值。有类似的功能吗? 最佳答案 intv=(A>'9')?(A&~0x20)-'A'+10:(A-'0');对于ASCII是正确的。对于其他字符集,类似的方法也行得通,但您需要使用toupper而不是&~0x20。 关于c++-C/C++:Convertinghexadecimalvalueinchartointeger,我们

c++ - 如何过滤 std::integer_sequence

如果我理论上有一个整数序列,比如std::integer_sequence我如何使用一些编译时谓词过滤它以获得可能更小的std::integer_sequence?为了论证,假设我只想要偶数值,这导致了“我怎样才能使以下static_assert(或接近的东西)通过?”的问题static_assert(std::is_same_v,decltype(FilterEvens(std::integer_sequence{}))>,"Integersequencesshouldbeequal");这个问题的灵感来自于思考我们如何完成删除两个位集(thisquestion)之间的重复项,假设我