2013-04-06 125 views
-1

对于unordered_map我设置这个初始桶数:STL unordered_set如何设置初始桶数

unordered_map<string, dictionaryWord> dictionary(17749); // set initial bucket count to 17749 

似乎这种方式并不为unordered_set工作。

/*line 150*/ unsigned char mask; 
/*line 151*/ unordered_set<QueryID> query_id(109); // set initial bucket count to 109 

编译错误= 1)数字常数之前预期标识符。 2)在数字常量之前预期','或'...'。 并继续与一堆的错误

如何做一个unordered_set相同的事情?

谢谢。

============================================== ===

有没有错误,如果我删除“(109)”

"/usr/bin/make" -f nbproject/Makefile-Release.mk QMAKE= SUBPROJECTS= .clean-conf 
make[1]: Entering directory `/home/petros/NetBeansProjects/ACM_test' 
rm -f -r build/Release 
rm -f dist/Release/GNU-Linux-x86/acm_test 
make[1]: Leaving directory `/home/petros/NetBeansProjects/ACM_test' 


CLEAN SUCCESSFUL (total time: 80ms) 

"/usr/bin/make" -f nbproject/Makefile-Release.mk QMAKE= SUBPROJECTS= .build-conf 
make[1]: Entering directory `/home/petros/NetBeansProjects/ACM_test' 
"/usr/bin/make" -f nbproject/Makefile-Release.mk dist/Release/GNU-Linux-x86/acm_test 
make[2]: Entering directory `/home/petros/NetBeansProjects/ACM_test' 
mkdir -p build/Release/GNU-Linux-x86/ref_impl 
rm -f build/Release/GNU-Linux-x86/ref_impl/core.o.d 
g++ -pthread -O3 -std=c++11 -c -O2 -pthread -O3 -std=c++11 -MMD -MP -MF build/Release/GNU-Linux-x86/ref_impl/core.o.d -o build/Release/GNU-Linux-x86/ref_impl/core.o ref_impl/core.cpp 
ref_impl/core.cpp:151:37: error: expected identifier before numeric constant 
ref_impl/core.cpp:151:37: error: expected ‘,’ or ‘...’ before numeric constant 
ref_impl/core.cpp: In function ‘ErrorCode StartQuery(QueryID, const char*, MatchType, unsigned int)’: 
ref_impl/core.cpp:250:24: error: expected unqualified-id before ‘(’ token 
ref_impl/core.cpp:250:38: error: missing template arguments before ‘)’ token 
ref_impl/core.cpp:250:39: error: expected ‘;’ before ‘query_id’ 
ref_impl/core.cpp:257:19: error: ‘query.SameQueries::query_id’ does not have class type 
ref_impl/core.cpp: In function ‘ErrorCode EndQuery(QueryID)’: 
ref_impl/core.cpp:265:44: error: ‘queries.std::vector<_Tp, _Alloc>::operator[]<SameQueries, std::allocator<SameQueries> >(((std::vector<SameQueries>::size_type)i)).SameQueries::query_id’ does not have class type 
ref_impl/core.cpp:265:58: error: unable to deduce ‘const auto’ from ‘<expression error>’ 
ref_impl/core.cpp:266:38: error: ‘queries.std::vector<_Tp, _Alloc>::operator[]<SameQueries, std::allocator<SameQueries> >(((std::vector<SameQueries>::size_type)i)).SameQueries::query_id’ does not have class type 
ref_impl/core.cpp:267:32: error: ‘queries.std::vector<_Tp, _Alloc>::operator[]<SameQueries, std::allocator<SameQueries> >(((std::vector<SameQueries>::size_type)i)).SameQueries::query_id’ does not have class type 
ref_impl/core.cpp:268:36: error: ‘queries.std::vector<_Tp, _Alloc>::operator[]<SameQueries, std::allocator<SameQueries> >(((std::vector<SameQueries>::size_type)i)).SameQueries::query_id’ does not have class type 
ref_impl/core.cpp: In function ‘void* TaskCode(void*)’: 
ref_impl/core.cpp:463:41: error: ‘quer.SameQueries::query_id’ does not have class type 
ref_impl/core.cpp:463:48: error: unable to deduce ‘auto’ from ‘<expression error>’ 
ref_impl/core.cpp:463:70: error: ‘quer.SameQueries::query_id’ does not have class type 
make[2]: *** [build/Release/GNU-Linux-x86/ref_impl/core.o] Error 1 
make[2]: Leaving directory `/home/petros/NetBeansProjects/ACM_test' 
make[1]: *** [.build-conf] Error 2 
make[1]: Leaving directory `/home/petros/NetBeansProjects/ACM_test' 
make: *** [.build-impl] Error 2 


BUILD FAILED (exit value 2, total time: 1s) 
+0

这应该工作:'明确unordered_set(SIZE_TYPE BUCKET_COUNT =/*实现定义*/ 常量哈希和哈希= HASH(), 常量KeyEqual与平等= KeyEqual(), const Allocator&alloc = Allocator());' – chris 2013-04-06 17:15:59

+1

我们可以看到那些“一堆错误”吗? – scones 2013-04-06 17:17:44

+0

@scones你不值得! – 2013-04-06 17:18:37

回答

1

这是一个结构里面。它应该是:

unordered_set<QueryID> query_id = unordered_set<QueryID>(109); 

谢谢

0

我怀疑斗数是一个红色的鲱鱼。它看起来像QueryID是不可见的。

+0

如果是这种情况,为什么它能正常工作,如果我删除(109)。它知道类型QueryID – 2013-04-06 17:39:21

+0

@PetrosDrakoulis:如果它在你删除'109'并且没有其他改变时起作用,我会撤回我的建议。 – NPE 2013-04-06 17:40:17

+0

@PetrosDrakoulis:如果您包含SSCCE(http://sscce.org/),它可以帮助其他人帮助您。否则有太多未知数。 – NPE 2013-04-06 17:41:22