本文整理汇总了C++中Hash::end方法的典型用法代码示例。如果您正苦于以下问题:C++ Hash::end方法的具体用法?C++ Hash::end怎么用?C++ Hash::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hash
的用法示例。
在下文中一共展示了Hash::end方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testAdd
void testAdd() {
Hash<int, int> h;
h.put(42, 11);
if (h.get(42) == h.end()) {
cout << "testAdd failed\n";
}
}
示例2: mode
IntPair mode(const int *values, unsigned int size) {
Hash::iterator it;
Hash hash;
for (int i = 0; i < size; i++) {
it = hash.find(values[i]);
if(it == hash.end()) {
hash.insert( std::make_pair(values[i], 1));
} else {
it->second += 1;
}
}
unsigned int counts = 0;
Hash::iterator found;
for (it = hash.begin(); it != hash.end(); ++it) {
if(it->second > counts) {
counts = it->second;
found = it;
}
}
return *found;
}
示例3: extract_hash
void extract_hash(Hash const& hash){
Class hash_class(Hash().class_of());
Class array_class(Array().class_of());
Class string_class(String().class_of());
for(Hash::const_iterator i=hash.begin(), iend=hash.end(); i!=iend; ++i){
std::cout << i->key << ":\n";
Object obj(i->value);
if(obj.is_instance_of(hash_class))
extract_hash(obj);
else if(obj.is_instance_of(array_class))
extract_array(obj);
else if(obj.is_instance_of(string_class))
std::cout << i->value << "\n";
else
std::cout << i->value << "\n";
}
}
示例4: data
/* Brief: TODO description
* Parameter: index, TODO description
* Parameter: role, TODO description
*
* Note: This function is called
*/
QVariant CDailyWeatherModel::data( const QModelIndex & index, int role ) const
{
int column = index.column();
int row = index.row();
//qDebug("from inside Data(), row:%i, col:%i, role=%i, counter=%i", row, column, role, counter);
if (role == Qt::DisplayRole || role == Qt::EditRole)
{
if (mStation == NULL)
return QVariant("n/a");
if (column == CDailyWeatherModel::YEAR)
return QVariant(mYear);
else if (column == CDailyWeatherModel::DOY)
return QVariant(row+1);
else {
// Note: Be sure to use pointer here! Else, the map will be returned by value. This means
// that a copy of this huge map will be made whenever this function is called (whenever
// the model needs to be updated or the table needs to be redraen - potentially many times.
// This will lag the interface.
Hash* hash = mStation->getWeather();
QString yr = QString::number(mYear);
QString doy = QString::number(row+1);
Pair pair(yr, doy);
// Find item in weather map with key
Hash::const_iterator iter = hash->find(pair);
// (Year, Day of Year) not found in weather data map for the current station
if(iter == hash->end())
return QVariant("n/a");
return QVariant(iter.value()->at(column-2));
}
}
else if (role == Qt::TextAlignmentRole)
return QVariant(Qt::AlignCenter);
else
return QVariant();
}
示例5: findSmallestSubString
void findSmallestSubString (string word, unsigned int indexInString)
{
Hash::iterator nptr;
bool checkForNewSmallest = false;
/* its not their in words to check */
if( (nptr=words.find(word)) == words.end() ) return ;
if( nptr->second->index == -1 )
noOfWords--;
nptr->second->index = indexInString;
if( start == NULL ) start = nptr->second;
else if( start == nptr->second)
{
start = start->next;
checkForNewSmallest = true;
}
if( end == NULL ) end = nptr->second;
else if( end != nptr->second)
{
Node *n = nptr->second;
if( n->prev ) n->prev->next = n->next;
if( n->next ) n->next->prev = n->prev;
n->prev = end;
end->next = n;
end = n;
}
if( noOfWords == 0 && checkForNewSmallest )
{
if( smallestCount > end->index - start->index + 1 )
{
smallestIndex = start->index;
smallestCount = end->index - start->index + 1;
}
}
}
示例6: while
int
da_build_dump(da_build_t* builder, char* tmpfile, FILE* lexfile)
{
Hash::iterator i, last;
Hash* entries = builder->entries;
char** keys = new char*[entries->size()];
size_t* lens = new size_t[entries->size()];
long* vals = new long[entries->size()];
int size = 0;
std::vector<long> lex_indices;
std::cerr << entries->size() << " entries" << std::endl;
i = entries->begin();
while (i != entries->end()) {
const std::string& key = i->first;
last = entries->upper_bound(key);
lex_indices.clear();
for (; i != last; i++) {
lex_indices.push_back(i->second);
}
lens[size] = key.size();
keys[size] = (char*) key.data();
vals[size] = redump_lex(lens[size], lex_indices, tmpfile, lexfile);
if (vals[size] < 0) {
std::cerr << "Unexpected error at " << key << std::endl;
cha_exit_perror((char*)"build darts file");
}
size++;
}
std::cerr << size << " keys" << std::endl;
DoubleArrayL da;
da.build(size, (const char**) keys, lens, vals);
da.save(builder->path->c_str(), "wb");
return builder->entries->size();
}
示例7: execute
int StatusJob::execute()
{
bool matched = false;
const char *alternatives = "fileids|watchedpaths|dependencies|symbols|symbolnames|sources|jobs|info|compilers";
if (!strcasecmp(query.constData(), "fileids")) {
matched = true;
if (!write(delimiter) || !write("fileids") || !write(delimiter))
return 1;
const Hash<uint32_t, Path> paths = Location::idsToPaths();
for (Hash<uint32_t, Path>::const_iterator it = paths.begin(); it != paths.end(); ++it) {
if (!write<256>(" %u: %s", it->first, it->second.constData()))
return 1;
}
if (isAborted())
return 1;
}
std::shared_ptr<Project> proj = project();
if (!proj) {
if (!matched)
write(alternatives);
return matched ? 0 : 1;
}
if (query.isEmpty() || !strcasecmp(query.constData(), "watchedpaths")) {
matched = true;
if (!write(delimiter) || !write("watchedpaths") || !write(delimiter))
return 1;
Set<Path> watched = proj->watchedPaths();
if (!write("Indexer"))
return 1;
for (Set<Path>::const_iterator it = watched.begin(); it != watched.end(); ++it) {
if (!write<256>(" %s", it->constData()))
return 1;
}
if (proj->fileManager) {
if (!write("FileManager"))
return 1;
watched = proj->fileManager->watchedPaths();
for (Set<Path>::const_iterator it = watched.begin(); it != watched.end(); ++it) {
if (!write<256>(" %s", it->constData()))
return 1;
}
}
if (isAborted())
return 1;
}
if (query.isEmpty() || !strcasecmp(query.constData(), "dependencies")) {
matched = true;
const DependencyMap map = proj->dependencies();
if (!write(delimiter) || !write("dependencies") || !write(delimiter))
return 1;
DependencyMap depsReversed;
for (DependencyMap::const_iterator it = map.begin(); it != map.end(); ++it) {
if (!write<256>(" %s (%d) is depended on by", Location::path(it->first).constData(), it->first))
return 1;
const Set<uint32_t> &deps = it->second;
for (Set<uint32_t>::const_iterator dit = deps.begin(); dit != deps.end(); ++dit) {
if (!write<256>(" %s (%d)", Location::path(*dit).constData(), *dit))
return 1;
depsReversed[*dit].insert(it->first);
}
if (isAborted())
return 1;
}
for (DependencyMap::const_iterator it = depsReversed.begin(); it != depsReversed.end(); ++it) {
write<256>(" %s (%d) depends on", Location::path(it->first).constData(), it->first);
const Set<uint32_t> &deps = it->second;
for (Set<uint32_t>::const_iterator dit = deps.begin(); dit != deps.end(); ++dit) {
if (!write<256>(" %s (%d)", Location::path(*dit).constData(), *dit))
return 1;
}
if (isAborted())
return 1;
}
}
if (query.isEmpty() || !strcasecmp(query.constData(), "symbols")) {
matched = true;
const SymbolMap &map = proj->symbols();
write(delimiter);
write("symbols");
write(delimiter);
for (SymbolMap::const_iterator it = map.begin(); it != map.end(); ++it) {
const Location loc = it->first;
const std::shared_ptr<CursorInfo> ci = it->second;
write(loc);
write(ci);
write("------------------------");
if (isAborted())
return 1;
}
}
if (query.isEmpty() || !strcasecmp(query.constData(), "symbolnames")) {
matched = true;
const SymbolNameMap &map = proj->symbolNames();
//.........这里部分代码省略.........
示例8: main
int main() {
Value a;
assert(!a.isInteger());
assert(!a.isString());
assert(!a.isList());
assert(!a.isHash());
assert(a.type() == Value::UNDEFINED);
assert(!a);
a = Value(11);
assert(a.isInteger());
assert(!a.isString());
assert(!a.isList());
assert(!a.isHash());
assert(a);
assert(a.asInteger() == 11);
a = Value("123");
assert(!a.isInteger());
assert(a.isString());
assert(!a.isList());
assert(!a.isHash());
assert(a);
assert(a.asString() == "123");
List b;
b.push_back(Value(11));
b.push_back(Value("111"));
a = Value(b);
b.push_back(Value(34));
assert(b.size() == 3);
assert(a.isList());
assert(a.asList().size() == 2);
Hash m;
m["aa"] = Value(12);
m["bb"] = Value(11);
a = Value(m);
m.erase("bb");
assert(m.size() == 1);
assert(m["aa"].asInteger() == 12);
assert(m.find("bb") == m.end());
assert(a.isHash());
assert(a.asHash().size() == 2);
a = Value(Vector(1,-1,2));
assert(a.type() == Value::VECTOR);
assert(a.isVector());
assert(a.asVector().y == -1);
assert(a);
a = Value(Position(1,-1,2));
assert(a.type() == Value::POSITION);
assert(a.isPosition());
assert(a.asPosition().x == 1);
assert(a);
std::cout << "Success!" << std::endl;
return 0;
}
示例9: execute
int StatusJob::execute()
{
auto match = [this](const char *name) {
return !strncasecmp(query.constData(), name, query.size());
};
bool matched = false;
const char *alternatives = "fileids|watchedpaths|dependencies|cursors|symbols|targets|symbolnames|sources|jobs|info|compilers|headererrors|memory";
if (match("fileids")) {
matched = true;
if (!write(delimiter) || !write("fileids") || !write(delimiter))
return 1;
const Hash<uint32_t, Path> paths = Location::idsToPaths();
for (Hash<uint32_t, Path>::const_iterator it = paths.begin(); it != paths.end(); ++it) {
if (!write<256>(" %u: %s", it->first, it->second.constData()))
return 1;
}
if (isAborted())
return 1;
}
if (match("headererrors")) {
matched = true;
if (!write(delimiter) || !write("headererrors") || !write(delimiter))
return 1;
for (auto err : Server::instance()->jobScheduler()->headerErrors()) {
if (!write(Location::path(err)))
return 1;
}
if (isAborted())
return 1;
}
if (query.isEmpty() || match("info")) {
matched = true;
if (!write(delimiter) || !write("info") || !write(delimiter))
return 1;
String out;
Log log(&out);
#ifdef NDEBUG
out << "Running a release build\n";
#else
out << "Running a debug build\n";
#endif
const Server::Options &opt = Server::instance()->options();
out << "socketFile" << opt.socketFile << '\n'
<< "dataDir" << opt.dataDir << '\n'
<< "options" << opt.options
<< "jobCount" << opt.jobCount << '\n'
<< "rpVisitFileTimeout" << opt.rpVisitFileTimeout << '\n'
<< "rpIndexDataMessageTimeout" << opt.rpIndexDataMessageTimeout << '\n'
<< "rpConnectTimeout" << opt.rpConnectTimeout << '\n'
<< "rpConnectTimeout" << opt.rpConnectTimeout << '\n'
<< "threadStackSize" << opt.threadStackSize << '\n'
<< "defaultArguments" << opt.defaultArguments << '\n'
<< "includePaths" << opt.includePaths << '\n'
<< "defines" << opt.defines << '\n'
<< "ignoredCompilers" << opt.ignoredCompilers;
write(out);
}
std::shared_ptr<Project> proj = project();
if (!proj) {
if (!matched)
write(alternatives);
return matched ? 0 : 1;
}
if (query.isEmpty() || match("watchedpaths")) {
matched = true;
if (!write(delimiter) || !write("watchedpaths") || !write(delimiter))
return 1;
Hash<Path, Flags<Project::WatchMode> > watched = proj->watchedPaths();
auto watchModeToString = [](Flags<Project::WatchMode> mode) {
List<String> ret;
if (mode & Project::Watch_FileManager)
ret << "filemanager";
if (mode & Project::Watch_SourceFile)
ret << "source";
if (mode & Project::Watch_Dependency)
ret << "dependency";
if (mode & Project::Watch_CompilationDatabase)
ret << "compilationdatabase";
return String::join(ret, '|');
};
for (const auto &it : watched) {
if (!write<256>(" %s (%s)", it.first.constData(), watchModeToString(it.second).constData())) {
return 1;
}
}
}
const Dependencies &deps = proj->dependencies();
if (query.isEmpty() || match("dependencies")) {
matched = true;
if (!write(delimiter) || !write("dependencies") || !write(delimiter))
return 1;
for (auto it : deps) {
//.........这里部分代码省略.........
示例10: QVERIFY
void tst_QHash::insert1()
{
const char *hello = "hello";
const char *world = "world";
const char *allo = "allo";
const char *monde = "monde";
{
typedef QHash<QString, QString> Hash;
Hash hash;
QString key;
for (int i = 0; i < 10; ++i) {
key[0] = i + '0';
for (int j = 0; j < 10; ++j) {
key[1] = j + '0';
hash.insert(key, "V" + key);
}
}
for (int i = 0; i < 10; ++i) {
key[0] = i + '0';
for (int j = 0; j < 10; ++j) {
key[1] = j + '0';
hash.remove(key);
}
}
}
{
typedef QHash<int, const char *> Hash;
Hash hash;
hash.insert(1, hello);
hash.insert(2, world);
QVERIFY(hash.size() == 2);
QVERIFY(!hash.isEmpty());
{
Hash hash2 = hash;
hash2 = hash;
hash = hash2;
hash2 = hash2;
hash = hash;
hash2.clear();
hash2 = hash2;
QVERIFY(hash2.size() == 0);
QVERIFY(hash2.isEmpty());
}
QVERIFY(hash.size() == 2);
{
Hash hash2 = hash;
hash2[1] = allo;
hash2[2] = monde;
QVERIFY(hash2[1] == allo);
QVERIFY(hash2[2] == monde);
QVERIFY(hash[1] == hello);
QVERIFY(hash[2] == world);
hash2[1] = hash[1];
hash2[2] = hash[2];
QVERIFY(hash2[1] == hello);
QVERIFY(hash2[2] == world);
hash[1] = hash[1];
QVERIFY(hash[1] == hello);
}
{
Hash hash2 = hash;
hash2.detach();
hash2.remove(1);
QVERIFY(hash2.size() == 1);
hash2.remove(1);
QVERIFY(hash2.size() == 1);
hash2.remove(0);
QVERIFY(hash2.size() == 1);
hash2.remove(2);
QVERIFY(hash2.size() == 0);
QVERIFY(hash.size() == 2);
}
hash.detach();
{
Hash::iterator it1 = hash.find(1);
QVERIFY(it1 != hash.end());
Hash::iterator it2 = hash.find(0);
QVERIFY(it2 != hash.begin());
QVERIFY(it2 == hash.end());
*it1 = monde;
QVERIFY(*it1 == monde);
QVERIFY(hash[1] == monde);
*it1 = hello;
QVERIFY(*it1 == hello);
QVERIFY(hash[1] == hello);
//.........这里部分代码省略.........