int Fleet::getMaxDurability() { auto keys = getKeys(ships); int num = 0; for (auto it = keys.begin(); it < keys.end(); it++) { num += ships[*it].getMaxDurability(); } return num; }
int Fleet::getNumSailors() { auto keys = getKeys(ships); int num = 0; for (auto it = keys.begin(); it < keys.end(); it++) { num += ships[*it].sailors; } return num; }
int Fleet::getRations() { auto keys = getKeys(ships); int num = 0; for (auto it = keys.begin(); it < keys.end(); it++) { num += ships[*it].rations; } return num; }
Status IndexAccessMethod::touch(OperationContext* txn, const BSONObj& obj) { BSONObjSet keys; getKeys(obj, &keys); boost::scoped_ptr<SortedDataInterface::Cursor> cursor(_newInterface->newCursor(txn, 1)); for (BSONObjSet::const_iterator i = keys.begin(); i != keys.end(); ++i) { cursor->locate(*i, RecordId()); } return Status::OK(); }
Status BtreeBasedAccessMethod::touch(const BSONObj& obj) { BSONObjSet keys; getKeys(obj, &keys); boost::scoped_ptr<BtreeInterface::Cursor> cursor(_newInterface->newCursor(1)); for (BSONObjSet::const_iterator i = keys.begin(); i != keys.end(); ++i) { cursor->locate(*i, DiskLoc()); } return Status::OK(); }
bool Fleet::isLoadedProperly() { auto keys = getKeys(ships); for (auto it = keys.begin(); it < keys.end(); it++) { Ship& ship = ships[*it]; if (ship.getMaxStorage() < ship.getTotalStorageUsed()) return false; } return true; }
Status IndexAccessMethod::touch(OperationContext* txn, const BSONObj& obj) { BSONObjSet keys; getKeys(obj, &keys); std::unique_ptr<SortedDataInterface::Cursor> cursor(_newInterface->newCursor(txn)); for (BSONObjSet::const_iterator i = keys.begin(); i != keys.end(); ++i) { cursor->seekExact(*i); } return Status::OK(); }
plKey plKeyCollector::findKey(plKey match) { plKey key; std::vector<plKey> kList = getKeys(match->getLocation(), match->getType()); for (unsigned int i=0; i < kList.size(); i++) { if (*kList[i] == *match) { key = kList[i]; break; } } return key; }
/* vector index 0 = lkeys * vector index 1 = lvars * vector index 2 = lops * vector index 3 = llits */ std::vector<std::map<std::string, size_t>> Tokenizer::findTokens(std::string line) { std::vector<std::map<std::string, size_t>> vec; std::map<std::string, size_t> lkeys; std::map<std::string, size_t> lvars; std::map<std::string, size_t> lops; std::map<std::string, size_t> llits; std::string words = seperateWords(line); auto keys = getKeys(words); auto vars = getVars(words); auto ops = getOps(line); // getOps needs non-seperated line auto lits = getLits(words); size_t pos = 0; //for (int i = 0; i < keys.size(); i++) for (auto x : keys) { //pos = line.find(keys[i], pos); pos = line.find(x, pos); //lkeys.insert(std::pair<size_t, std::string>(pos++, keys[i])); lkeys.insert(std::make_pair(x, pos++)); } pos = 0; //for (int i = 0; i < vars.size(); i++) for (auto x : vars) { //pos = line.find(vars[i], pos); pos = line.find(x, pos); //lvars.insert(std::pair<size_t, std::string>(pos++, vars[i])); lvars.insert(std::make_pair(x, pos++)); } pos = 0; //for (int i = 0; i < ops.size(); i++) for (auto x : ops) { //pos = line.find(ops[i], pos); pos = line.find(x, pos); //lops.insert(std::pair<size_t, std::string>(pos++, ops[i])); lops.insert(std::make_pair(x, pos++)); } pos = 0; //for (int i = 0; i < lits.size(); i++) for (auto x : lits) { //pos = line.find(lits[i], pos); pos = line.find(x, pos); //llits.insert(std::pair<size_t, std::string>(pos++, lits[i])); llits.insert(std::make_pair(x, pos++)); } vec.push_back(lkeys); vec.push_back(lvars); vec.push_back(lops); vec.push_back(llits); return vec; }
bool Fleet::hasEnoughSailors() { auto keys = getKeys(ships); for (auto it = keys.begin(); it < keys.end(); it++) { Ship& ship = ships[*it]; if (ship.sailors < ship.getMinSailors()) return false; } return true; }
ZExport (ZBoolean) ZProfile::keyExists (const ZString & aKeyName) { ZFUNCTRACE_DEVELOP ("ZProfile::keyExists(const ZString& aKeyName)"); ZStringlist list; ZBoolean found; if (aKeyName.size ()) { getKeys (list); found = list.find (aKeyName) >= 0; } else { #ifdef ZC_WIN found = zTrue; try { openPath (zFalse); } catch (const ZException & exc) { found = zFalse; } // catch #endif #ifdef ZC_OS2 ZString path (iPath); try { setPath (""); getKeys (list); found = list.find (path) >= 0; setPath (path); } // try catch (const ZException & exc) { setPath (path); throw; } // catch #endif } // if return found; } // keyExists
int main(void) { if (!openDisplay()) { return 1; } grab(getKeys(), getButtons()); while (1) { nextEvent(); processEvent(); } }
WP::err Contact::sign(const QString &keyId, const QByteArray &data, QByteArray &signature) { QString certificate; QString publicKey; QString privateKey; WP::err error = getKeys()->getKeySet(keyId, certificate, publicKey, privateKey); if (error != WP::kOk) return error; CryptoInterface *crypto = CryptoInterfaceSingleton::getCryptoInterface(); SecureArray password = ""; return crypto->sign(data, signature, privateKey, password); }
Status IndexAccessMethod::validateUpdate(OperationContext* txn, const BSONObj& from, const BSONObj& to, const RecordId& record, const InsertDeleteOptions& options, UpdateTicket* ticket, const MatchExpression* indexFilter) { if (indexFilter == NULL || indexFilter->matchesBSON(from)) getKeys(from, &ticket->oldKeys); if (indexFilter == NULL || indexFilter->matchesBSON(to)) getKeys(to, &ticket->newKeys); ticket->loc = record; ticket->dupsAllowed = options.dupsAllowed; setDifference(ticket->oldKeys, ticket->newKeys, &ticket->removed); setDifference(ticket->newKeys, ticket->oldKeys, &ticket->added); ticket->_isValid = true; return Status::OK(); }
void JObject::finalize(){ memoryMutex->lock(); if (fromObject->size()==0){ vector<JObject*>* keys=getKeys(toObject); for (vector<JObject*>::size_type i=0;i<keys->size();i++){ unlink(keys->at(i)); } delete keys; delete this; } memoryMutex->unlock(); }
State_equipParts::State_equipParts(Fleet& fleet) : refToFleet(fleet), selector(-1) { popMe = false; console = new TCODConsole(screenwidth, screenheight); pageit = 0; pages = getKeys(fleet.ships); page = pages[pageit]; doRedraw = true; waiting = false; updateLookup(); }
IndexNode * IndexNode::split(int key, TreeNode *left, TreeNode *right, int &middle){ assert(getCount() == getMax()); //merge keys and children together int order = getMax(); int *merged = new int[order + 1]; int index = indexOfKey(key); int * keys = getKeys(); TreeNode **mergedNodes = new TreeNode*[order + 2]; for (int i = 0 ; i < index; i ++){ merged[i] = keys[i]; mergedNodes[i] = m_children[i]; } merged[index] = key; mergedNodes[index] = left; mergedNodes[index+1] = right; for (int i = index + 1; i < order + 1; i ++){ merged[i] = keys[i-1]; mergedNodes[i+1] = m_children[i]; } int half = (order + 1) / 2; //half is returned to be pushed up middle = merged[half]; //split keys and children for left node for (int i = 0; i < half; i++){ keys[i] = merged[i]; m_children[i] = mergedNodes[i]; } m_children[half] = mergedNodes[half]; for (int i = half + 1; i < order+1; i++){ m_children[i] = nullptr; } setCount(half); //split keys and children for second node IndexNode * sibling = new IndexNode(getOrder()); int * s_keys = sibling->getKeys(); TreeNode **s_children = sibling->m_children; for (int i = half + 1; i < order + 1; i++){ s_keys[i - (half + 1)] = merged[i]; s_children[i - (half + 1)] = mergedNodes[i]; s_children[i - (half + 1)]->setParent(sibling); sibling->increment(); } s_children[order + 1 - (half + 1)] = mergedNodes[order+1]; s_children[order + 1 - (half + 1)]->setParent(sibling); delete[] merged; delete mergedNodes; return sibling; }
int Fleet::getWaveResistance() { auto keys = getKeys(ships); double lowest = std::numeric_limits<double>::max(); for (auto it = keys.begin(); it < keys.end(); it++) { int waveResistance = ships[*it].waveResistance; if (waveResistance < lowest) lowest = waveResistance; } return int(lowest); }
Status BtreeBasedAccessMethod::touch(const BSONObj& obj) { BSONObjSet keys; getKeys(obj, &keys); DiskLoc loc; int keyPos; for (BSONObjSet::const_iterator i = keys.begin(); i != keys.end(); ++i) { _newInterface->locate(*i, DiskLoc(), 1, &loc, &keyPos); } return Status::OK(); }
Status BtreeBasedAccessMethod::validateUpdate(OperationContext* txn, const BSONObj& from, const BSONObj& to, const RecordId& record, const InsertDeleteOptions& options, UpdateTicket* status) { BtreeBasedPrivateUpdateData* data = new BtreeBasedPrivateUpdateData(); status->_indexSpecificUpdateData.reset(data); getKeys(from, &data->oldKeys); getKeys(to, &data->newKeys); data->loc = record; data->dupsAllowed = options.dupsAllowed; setDifference(data->oldKeys, data->newKeys, &data->removed); setDifference(data->newKeys, data->oldKeys, &data->added); status->_isValid = true; return Status::OK(); }
double Fleet::getSpeed() { auto keys = getKeys(ships); double lowest = std::numeric_limits<double>::max(); for (auto it = keys.begin(); it < keys.end(); it++) { double speed = ships[*it].getSpeed(); if (speed < lowest) lowest = speed; } return lowest; }
Status IndexAccessMethod::touch(OperationContext* txn, const BSONObj& obj) { BSONObjSet keys = SimpleBSONObjComparator::kInstance.makeBSONObjSet(); // There's no need to compute the prefixes of the indexed fields that cause the index to be // multikey when paging a document's index entries into memory. MultikeyPaths* multikeyPaths = nullptr; getKeys(obj, &keys, multikeyPaths); std::unique_ptr<SortedDataInterface::Cursor> cursor(_newInterface->newCursor(txn)); for (BSONObjSet::const_iterator i = keys.begin(); i != keys.end(); ++i) { cursor->seekExact(*i); } return Status::OK(); }
Status BtreeBasedAccessMethod::validateUpdate( const BSONObj &from, const BSONObj &to, const DiskLoc &record, const InsertDeleteOptions &options, UpdateTicket* status) { BtreeBasedPrivateUpdateData *data = new BtreeBasedPrivateUpdateData(); status->_indexSpecificUpdateData.reset(data); getKeys(from, &data->oldKeys); getKeys(to, &data->newKeys); data->loc = record; data->dupsAllowed = options.dupsAllowed; setDifference(data->oldKeys, data->newKeys, &data->removed); setDifference(data->newKeys, data->oldKeys, &data->added); bool checkForDups = !data->added.empty() && (KeyPattern::isIdKeyPattern(_descriptor->keyPattern()) || _descriptor->unique()) && !options.dupsAllowed; if (checkForDups) { for (vector<BSONObj*>::iterator i = data->added.begin(); i != data->added.end(); i++) { if (_interface->wouldCreateDup(_btreeState, _btreeState->head(), **i, record)) { status->_isValid = false; return Status(ErrorCodes::DuplicateKey, _interface->dupKeyError(_btreeState, _btreeState->head(), **i)); } } } status->_isValid = true; return Status::OK(); }
int main(int argc, char* argv[]) { if(argc<=2) { printf("Usage: %s <fileToEncrypt> <key1> <key2> ... <key_n>\n",argv[0]); return 1; } // read in the keys int numKeys=argc-2; xorKey* keyList=(xorKey*)malloc(sizeof(xorKey)*numKeys); // allocate key list getKeys(keyList,&(argv[2]),numKeys); // read in the data to encrypt/decrypt off_t textLength=fsize(argv[1]); //length of our text FILE* rawFile=(FILE*)fopen(argv[1],"rb"); //The intel in plaintext char* rawData = (char*)malloc(sizeof(char)*textLength); fread(rawData,textLength,1,rawFile); fclose(rawFile); // Encrypt char* cypherText = (char*)malloc(sizeof(char)*textLength); encode(rawData,cypherText,keyList,textLength,numKeys); // Decrypt char* plainText = (char*)malloc(sizeof(char)*textLength); decode(cypherText,plainText,keyList,textLength,numKeys); // write out FILE* encryptedFile=(FILE*)fopen("encryptedOut","wb"); FILE* decryptedFile=(FILE*)fopen("decryptedOut","wb"); fwrite(cypherText,textLength,1,encryptedFile); fwrite(plainText,textLength,1,decryptedFile); fclose(encryptedFile); fclose(decryptedFile); // Check int i; for(i=0;i<textLength;i++) { if(rawData[i]!=plainText[i]) { printf("Encryption/Decryption is non-deterministic\n"); i=textLength; } } return 0; }
Status AbstractIndexAccessMethod::touch(OperationContext* opCtx, const BSONObj& obj) { BSONObjSet keys = SimpleBSONObjComparator::kInstance.makeBSONObjSet(); // There's no need to compute the prefixes of the indexed fields that cause the index to be // multikey when paging a document's index entries into memory. BSONObjSet* multikeyMetadataKeys = nullptr; MultikeyPaths* multikeyPaths = nullptr; getKeys(obj, GetKeysMode::kEnforceConstraints, &keys, multikeyMetadataKeys, multikeyPaths); std::unique_ptr<SortedDataInterface::Cursor> cursor(_newInterface->newCursor(opCtx)); for (const auto& key : keys) { cursor->seekExact(key); } return Status::OK(); }
Status BtreeBasedAccessMethod::validateUpdate(OperationContext* txn, const BSONObj &from, const BSONObj &to, const DiskLoc &record, const InsertDeleteOptions &options, UpdateTicket* status) { BtreeBasedPrivateUpdateData *data = new BtreeBasedPrivateUpdateData(); status->_indexSpecificUpdateData.reset(data); getKeys(from, &data->oldKeys); getKeys(to, &data->newKeys); data->loc = record; data->dupsAllowed = options.dupsAllowed; setDifference(data->oldKeys, data->newKeys, &data->removed); setDifference(data->newKeys, data->oldKeys, &data->added); bool checkForDups = !data->added.empty() && (KeyPattern::isIdKeyPattern(_descriptor->keyPattern()) || _descriptor->unique()) && !options.dupsAllowed; if (checkForDups) { for (vector<BSONObj*>::iterator i = data->added.begin(); i != data->added.end(); i++) { Status check = _newInterface->dupKeyCheck(txn, **i, record); if (!check.isOK()) { status->_isValid = false; return check; } } } status->_isValid = true; return Status::OK(); }
// Remove the provided doc from the index. Status IndexAccessMethod::remove(OperationContext* txn, const BSONObj& obj, const RecordId& loc, const InsertDeleteOptions& options, int64_t* numDeleted) { BSONObjSet keys; getKeys(obj, &keys); *numDeleted = 0; for (BSONObjSet::const_iterator i = keys.begin(); i != keys.end(); ++i) { removeOneKey(txn, *i, loc, options.dupsAllowed); ++*numDeleted; } return Status::OK(); }
int Fleet::getFatigue() { auto keys = getKeys(ships); int total = 0; // sum of weight int sum = 0; // sum of weight * fatigue for (auto it = keys.begin(); it < keys.end(); it++) { Ship& ship = ships[*it]; total += ship.sailors; sum += ship.sailors * ship.fatigue; } if (total == 0) return 1000; return sum / total; // Throw away remainders! }
/** * @brief Removes all Items out of a dict. */ void sidexDict::clear(){ int iSize = getNumberOfDictEntrys(); if (0 < iSize){ char ** keyArray = NULL; int iRet = getKeys(&keyArray); if (SIDEX_SUCCESS == iRet){ for (int i = iSize-1; i >= 0; --i){ removeEntry(keyArray[i]); } } if (NULL != keyArray){ delete []keyArray; } } }
/** * Get a list of descriptor objects used to order the algorithms in the stored map * where an algorithm has multiple categories it will be represented using multiple descriptors. * Hidden categories will not be included. * @returns A vector of descriptor objects */ std::vector<Algorithm_descriptor> AlgorithmFactoryImpl::getDescriptors() const { //algorithm names std::vector<std::string> sv; sv = getKeys(true); //hidden categories std::set<std::string> hiddenCategories; fillHiddenCategories(&hiddenCategories); //results vector std::vector<Algorithm_descriptor> res; for(std::vector<std::string>::const_iterator s=sv.begin();s!=sv.end();++s) { if (s->empty()) continue; Algorithm_descriptor desc; size_t i = s->find('|'); if (i == std::string::npos) { desc.name = *s; desc.version = 1; } else if (i > 0) { desc.name = s->substr(0,i); std::string vers = s->substr(i+1); desc.version = vers.empty()? 1 : atoi(vers.c_str()); } else continue; boost::shared_ptr<IAlgorithm> alg = create(desc.name,desc.version); std::vector<std::string> categories = alg->categories(); //for each category std::vector<std::string>::const_iterator itCategoriesEnd = categories.end(); for(std::vector<std::string>::const_iterator itCategories = categories.begin(); itCategories!=itCategoriesEnd; ++itCategories) { desc.category = *itCategories; //if the entry is not in the set of hidden categories if (hiddenCategories.find(desc.category) == hiddenCategories.end()) { res.push_back(desc); } } } return res; }