void IndexBuilder::run() { Client::initThread(name().c_str()); LOG(2) << "IndexBuilder building index " << _index; OperationContextImpl txn; Lock::ParallelBatchWriterMode::iAmABatchParticipant(txn.lockState()); txn.getClient()->getAuthorizationSession()->grantInternalAuthorization(); txn.getCurOp()->reset(HostAndPort(), dbInsert); NamespaceString ns(_index["ns"].String()); ScopedTransaction transaction(&txn, MODE_IX); Lock::DBLock dlk(txn.lockState(), ns.db(), MODE_X); Client::Context ctx(&txn, ns.getSystemIndexesCollection()); Database* db = dbHolder().get(&txn, ns.db().toString()); Status status = _build(&txn, db, true, &dlk); if ( !status.isOK() ) { error() << "IndexBuilder could not build index: " << status.toString(); fassert(28555, ErrorCodes::isInterruption(status.code())); } txn.getClient()->shutdown(); }
void PreflateSeqChain::_reshift() { const unsigned short delta = 0x7e00; unsigned remaining = (1 << 16) - (delta + 8); // If the head of large sequence is shifted out, // but the tail remains in the cache, // we need to adapt the head and all pointers to it, // that is all members, the next non-member pointing to it // or heads if (prev[delta + 8].distToNext != 0xffff && prev[delta + 8].length < PreflateConstants::MIN_MATCH) { unsigned d = prev[delta + 8].distToNext; prev[delta + 8].distToNext = 0xffff; prev[delta + 8].length = prev[delta + 8 - d].length - d; for (unsigned i = 3; i < prev[delta + 8].length; ++i) { prev[delta + 8 + i - 2].distToNext -= d; } uint8_t c = *_input.curChars(-(int)remaining); if (heads[c] == delta + 8 - d) { heads[c] += d; } else { for (unsigned i = prev[delta + 8].length; i < remaining; ++i) { if (prev[delta + 8 + i].distToNext == i + d) { prev[delta + 8 + i].distToNext -= d; break; } } } } for (unsigned i = 0; i < 256; ++i) { heads[i] = std::max(heads[i], delta) - delta; } memmove(prev + 8, prev + (delta + 8), sizeof(SeqChainEntry) * remaining); totalShift += delta; _build(8 + remaining, std::min<uint32_t>(delta, _input.remaining())); }
// Process void Tree::Process() { switch (_step) { case 0: if (_initialize()) _step++; else return; case 1: if (_count()) _step++; else throw std::runtime_error("read error"); case 2: if (_sum()) _step++; else return; case 3: if (_build()) _step++; else throw std::runtime_error("build error"); case 4: if (_subtrees()) _step++; else throw std::runtime_error("subtree error"); default: _fptree.free(); FinishProcess(); } }
void BoundingBoxHierarchy::build(vector<RTShape*> shapes) { vector<RTShape*> flattened = flatten(shapes); _build(flattened.begin(), flattened.end(), 0); }
void SystemClass::loadTable(BaseGame *gameRef, BasePersistenceManager *persistMgr) { _savedID = persistMgr->getDWORD(); int numInstances = persistMgr->getDWORD(); for (int i = 0; i < numInstances; i++) { int instID = persistMgr->getDWORD(); if (_persistent) { if (i > 0) { gameRef->LOG(0, "Warning: attempting to load multiple instances of persistent class %s (%d)", _name.c_str(), numInstances); continue; } Instances::iterator it = _instances.begin(); if (it != _instances.end()) { (it->_value)->setSavedID(instID); SystemClassRegistry::getInstance()->addInstanceToTable((it->_value), (it->_value)->getInstance()); } else { gameRef->LOG(0, "Warning: instance %d of persistent class %s not found", i, _name.c_str()); } } // normal instances, create empty objects else { void *emptyObject = _build(); if (!emptyObject) { warning("HALT"); } addInstance(emptyObject, SystemClassRegistry::getInstance()->getNextID(), instID); } } }
PreflateSeqChain::PreflateSeqChain( const std::vector<unsigned char>& input_) : _input(input_) , totalShift(-8) , curPos(0) { prev = new SeqChainEntry[1 << 16]; memset(heads, 0x00, sizeof(heads)); _build(8, std::min<uint32_t>((1 << 16) - 8, _input.remaining())); }
const Font::Glyph * FontFreeType::build(c32 chr) { GlyphMap::iterator it = m_glyphMap.insert(std::make_pair(chr, (GlyphEx *)0)).first; if (it->second) { it->second->pass = m_currentPass; } else { _build(chr, it); } return it->second; }
void GraphOperation::build() { if(_source && !_built) { const_cast<Graph*>(_source)->build(); _build(); _built = true; connectGraphSignals(); } }
bool BasicShader::build() { bool ret; _build(); _bindAttribLocation(0, "vPosition"); _bindAttribLocation(1, "vColor"); _bindAttribLocation(2, "vNormal"); _bindAttribLocation(3, "vTexCoord"); ret = _linkProgram(); if (ret) _bindTextureUnit(0, "fTexture0"); return (ret); }
/** rebuild list */ void ui_setup_ledlist_refresh( NiftyconfChain * c) { if(!c) return; /* clear ledlist */ ui_setup_ledlist_clear(); _build(c); /* redraw */ renderer_all_queue_draw(); }
InventoryPanel::InventoryPanel(Inventory* inventory) { Node::init(); _inventory = inventory; _inventory->retain(); _build(); _update(); auto eventDispatcher = cocos2d::Director::getInstance()->getEventDispatcher(); _inventoryChangedListener = eventDispatcher->addCustomEventListener(Inventory::ITEM_COUNT_CHANGED, [this](cocos2d::EventCustom* e) { _update(); }); }
// discrete features // vs continuous features void buildTree(const vector < vector <T1> > & feature_set, const vector < T2 > & label_set) { // row: ds, col: fs size_t data_size, feature_size; vector < bool > selected; // has been selected as branch feature or not data_size = feature_set.size(); assert(data_size > 0); feature_size = feature_set[0].size(); selected.resize(feature_size, false); // build tree _root = _build(feature_set, label_set, selected); #ifdef DEBUG cerr << _root.getNodeType() << endl; cerr << _root.getNumInstances() << endl; #endif }
void RandomTree::buildTest(DataFrame & data, unsigned int numFactors) { unsigned int nodeSize = 1; _factPerNode = numFactors; std::vector<unsigned int> indices; indices.resize(data.getNumDataVectors()); for(unsigned int i = 0; i < indices.size(); i++) { indices[i] = i; } _root = new TreeNode(); _root->leftChild = NULL; _root->rightChild = NULL; _root->isPure = false; _build(data, indices, _root, nodeSize); }
const Font::Glyph * CellBasedFont::build(const str32 &code) { GlyphMap::iterator it = m_glyphMap.insert(std::make_pair(code, (GlyphEx *)0)).first; if (it->second) { it->second->pass = m_currentPass; } else { GlyphEx *glyph = m_glyphList.back(); if (glyph->pass == m_currentPass) { return 0; } if (glyph->mapIt != m_glyphMap.end()) { m_glyphMap.erase(glyph->mapIt); } glyph->pass = m_currentPass; m_glyphList.erase(glyph->lstIt); m_glyphList.push_front( glyph ); glyph->lstIt = m_glyphList.begin(); glyph->mapIt = it; it->second = glyph; _build(code, glyph); } return it->second; }
Manageable::MethodMap& Manageable::manageableMmethodMap() { _build(); return *manageable::methodMap; }
index(Indices... indices) { static_assert(sizeof...(Indices) == N, "Wrong number of arguments to construct the index."); _build(indices...); }
void MeshGroup::Build() { _build(0); _build(1); }
TreeNode < T1 > _build(const vector < vector <T1> > & feature_set, const vector < T2 > & label_set, vector < bool > & selected) { TreeNode < T1 > temp; #ifdef DEBUG for(auto d: feature_set) { for(auto f: d) { cerr << f << ", "; } cerr << endl; } #endif // label->size: data size // select->size: feature size // related instance number temp.setNumInstances(label_set.size()); // check input bool feature_the_same = true; for(size_t fdx = 0; fdx < selected.size(); fdx++) { if(selected[fdx] == false) { set < T1 > cur_values; for(size_t ddx = 0; ddx < label_set.size(); ddx++) { cur_values.insert(feature_set[ddx][fdx]); } if(cur_values.size() != 1) { feature_the_same = false; } } } // all features have the same value if(feature_the_same) { temp.setNodeType(AIS); return temp; } // check output set < T2 > output_set; for(size_t ddx = 0; ddx < label_set.size(); ddx++) { // maybe wrong output_set.insert(label_set[ddx]); } // labels are the same if(output_set.size() == 1) { temp.setNodeType(AOS); return temp; } // find maximum information gain temp.setNodeType(MIG); map < T1, int > count_label; for(auto l: label_set) { count_label[l]++; } // H(Y) = - sigma(p(y) * log(p(y)) double h_y = 0; for(auto c: count_label) { double p = c.second * 1. / label_set.size(); h_y += p * log(p); } h_y = - h_y; #ifdef DEBUG cerr << "H(Y): " << h_y << endl; #endif int best_feature = -1; double best_ig = -1.; for(size_t fdx = 0; fdx < selected.size(); fdx++) { if(selected[fdx] == false) { // TODO // IG(Xi) = H(Y) - H(Y|Xi) // H(Y) = - sigma(p(y) * log(p(y)) // H(Y|Xi) = sigma(p(xij) * H(Y|xij)) // = sigma(p(xij) * [- sigma(p(y|xij) * log(p(y|xij)))] // = -sigma"y, xij"(p(xij, y) * log(p(y|xij))) // = -sigma"y, xij"(p(xij, y) * log(p(xij, y)/p(xij))) map < T1, map < T2, int > > count_value_with_label; for(size_t ddx = 0; ddx < label_set.size(); ddx++) { count_value_with_label[feature_set[fdx][ddx]][label_set[ddx]]++; } double h_y_x = 0.; for(auto x: count_value_with_label) { double p_x_with_no_fraction = x.second.size() * 1.; for(auto x_y: x.second) { double p_x_y_w_n_f = x_y.second * 1. / label_set.size(); h_y_x += p_x_y_w_n_f * log(p_x_y_w_n_f / p_x_with_no_fraction); } } h_y_x = - h_y_x; double ig = h_y - h_y_x; #ifdef DEBUG cerr << "IG: " << h_y << endl; #endif if(best_ig < ig) { best_ig = ig; best_feature = fdx; } } } assert(best_feature != -1); // split temp.setFeatureId(best_feature); // choose branches (discrete) set < T1 > values_of_feature; for(size_t ddx = 0; ddx < label_set.size(); ddx++) { values_of_feature.insert(feature_set[ddx][best_feature]); } selected[best_feature] = true; for(auto v: values_of_feature) { vector < vector <T1> > children_feature_set; vector < T2 > children_label_set; for(size_t ddx = 0; ddx < label_set.size(); ddx++) { if(feature_set[ddx][best_feature] == v) { children_feature_set.push_back(feature_set[ddx]); children_label_set.push_back(label_set[ddx]); } } temp.addChild(_build(children_feature_set, children_label_set, selected), v); } return temp; }
BubblesScene::BubblesScene(int width, int height) : Scene(width, height), _rotationAngle(0.), _dof(true) { _build(); }
void LevelListScene::onEnter() { cocos2d::Scene::onEnter(); _build(); }
Status IndexBuilder::buildInForeground(OperationContext* txn, Database* db) const { return _build(txn, db, false, NULL); }
WaveScene::WaveScene(int width, int height) : Scene(width, height) { _build(); }
MetaObject& Manageable::manageableMetaObject() { _build(); return *manageable::metaObject; }
bool Url::build(String* protocol, String* auth, String* host, String* path, Hash* query, String* fragment){ return _build(protocol, auth, host, path, 0, query, fragment); }
bool Url::build(String* protocol, String* auth, String* host, String* path, String* query_string, String* fragment){ return _build(protocol, auth, host, path, query_string, 0, fragment); }
void RandomTree::_build(DataFrame & data, std::vector<unsigned int> & dataSet, TreeNode * node, unsigned int nodeSize) { static unsigned int idCtr = 0; node->leftChild = NULL; node->rightChild = NULL; if(data.isDataSetPure(dataSet) || dataSet.size() <= nodeSize) //Data is pure { //If data set is all of same class then it is pure and done //Give it a class label node->classLabel = data.getTrainingLabel(dataSet[0]); node->isPure = true; node->purityDelta = 0; node->rangeMin = node->rangeMax = 0; node->dataList = dataSet; idCtr++; node->nodeId = idCtr; } else //Data is not pure { std::vector<unsigned int> factors; unsigned int splitIdx = 0; unsigned int fIdx = 0; double splitVal = 0.0; double purityDelta = 0.0; data.selectRandomFactors(_factPerNode, factors); bool splitPossible = _igc.findDataSplit(data, factors, dataSet, splitIdx, fIdx, splitVal, purityDelta); if(splitPossible) //Data is not all same value { node->isPure = false; std::vector<unsigned int> leftSplit; std::vector<unsigned int> rightSplit; node->leftChild = new TreeNode(); node->rightChild = new TreeNode(); node->splitValue = splitVal; node->factorIndex = fIdx; node->purityDelta = purityDelta; node->nodeId = 0; double minVal, maxVal, mean, q1, q3; double bandwidth = data.computeBandwidthByFactor(fIdx, dataSet, minVal, maxVal, mean, q1, q3); bandwidth = bandwidth; // node->rangeMin = mean - (6 * bandwidth); // node->rangeMax = mean + (6 * bandwidth); // double midVal = (maxVal - minVal) / 2.0; // node->rangeMin = minVal - (0.5 *(maxVal - minVal)); // node->rangeMax = maxVal + (0.5 * (maxVal - minVal)); double iqr = q3 - q1; node->rangeMin = q1 - ( 3 * iqr); node->rangeMax = q3 + (3 * iqr); data.sortIndicesOnFactorValue(dataSet, fIdx); for(unsigned int i = 0; i < splitIdx; i++) { leftSplit.push_back(dataSet[i]); } _build(data, leftSplit, node->leftChild, nodeSize); for(unsigned int i = splitIdx; i < dataSet.size(); i++) { rightSplit.push_back(dataSet[i]); } _build(data, rightSplit, node->rightChild, nodeSize); } else //Data is all same value { //No split possible (all factors values same across all factors) //Vote on classes and make pure node. node->classLabel = data.getMajorityTrainingLabel(dataSet); node->isPure = true; node->purityDelta = 0; node->dataList = dataSet; idCtr++; node->nodeId = idCtr; } } }
Manageable::SignalMap& Manageable::manageableSignalMap() { _build(); return *manageable::signalMap; }
void init_building_data() { for (int i = 0; i < BUILD_MAX; i++) { Building_data[i] = new Building_datum; Building_data[i]->uid = i; } int cur_id; _build(BUILD_PARK); _name("park"); _cost(RES_GOLD, 300); _build_time(3); _destroy_cost(20); _upkeep(4); _base_morale(3); _description("\ A park is a well-groomed area of nature, with carefully designed paths and \ seating areas.\ "); _build(BUILD_PLAZA); _name("plaza"); _cost(RES_GOLD, 500); _cost(RES_STONE, 500); _build_time(5); _destroy_cost(150); _upkeep(4); _base_morale(1); _description("\ A plaza is an urban area that combines the pleasant environment and seating \ and strolling areas of a <link=park>park</link>, with the \ <link=building>business</link> space of a <link=marketplace>marketplace</link>.\ "); _build(BUILD_MARKETPLACE); _name("marketplace"); _cost(RES_GOLD, 800); _cost(RES_STONE, 1500); _build_time(7); _destroy_cost(350); _upkeep(2); _description("\ A marketplace is an area designed purely for business, with lots of space for \ <link=building>buildings</link> of various natures.\ "); _build(BUILD_HOVEL); _name("hovels"); _plural(); _cost(RES_GOLD, 300); _cost(RES_WOOD, 300); _build_time(3); _destroy_cost(250); _upkeep(5); _housing(CIT_PEASANT, 100); _description("\ Hovels are simple homes, sacrificing comfort and style to be a purely \ utilitarian living space for <link=peasants>peasants</link>.\ "); _build(BUILD_HOUSE); _name("houses"); _plural(); _cost(RES_GOLD, 800); _cost(RES_WOOD, 500); _build_time(10); _destroy_cost(600); _upkeep(10); _housing(CIT_MERCHANT, 100); _description("\ Houses are respectable homes with a moderate degree of comfort, suitable for \ the <link=merchants>middle classes</link>.\ "); _build(BUILD_MANOR); _name("manor"); _cost(RES_GOLD, 1200); _cost(RES_WOOD, 500); _cost(RES_STONE, 1000); _build_time(30); _destroy_cost(1250); _upkeep(20); _housing(CIT_BURGHER, 50); _description("\ A manor is a large, well-furnished home. Its high degree of comfort and low-\ density quarters are ideal for the <link=burghers>upper class</link>.\ "); _build(BUILD_KEEP); _name("keep"); _cost(RES_GOLD, 3000); _cost(RES_STONE, 4000); _build_time(90); _destroy_cost(2500); _upkeep(30); _housing(CIT_BURGHER, 5); _housing(CIT_MERCHANT, 50); _housing(CIT_PEASANT, 100); _description("\ A keep is the center of any city. It provides a home for the \ <link=nobles>nobility</link> as well as space for some <link=citizens>citizens\ </link>. It also has space to support several <link=building>businesses\ </link>.\ "); _build(BUILD_FARM); _name("farm"); _cost(RES_GOLD, 250); _build_time(1); _destroy_cost(50); _upkeep(1); _jobs(CIT_PEASANT, 15); _wages(1); _produces(RES_FARMING, 1); _description("\ A farm is a tilled piece of land designed for growing <link=crop>crops</link>.\ "); _build(BUILD_HUNTING_CAMP); _name("hunting camp"); _cost(RES_GOLD, 200); _build_time(1); _destroy_cost(100); _upkeep(3); _jobs(CIT_PEASANT, 10); _wages(1); _produces(RES_HUNTING, 1); _description("\ A hunting camp is a base of operations for <link=hunting>hunters</link>, \ allowing them to catch <link=animals>game</link> in the land upon which it is \ built.\ "); _build(BUILD_MINE); _name("mine"); _cost(RES_GOLD, 500); _cost(RES_WOOD, 400); _build_time(10); _destroy_cost(1500); _upkeep(8); _jobs(CIT_PEASANT, 8); _wages(2); _produces(RES_MINING, 5); _description("\ A mine is set of several shafts dug into the land, allowing <link=mining>miners\ </link> to pull <link=minerals>minerals</link> from the ground.\ "); _build(BUILD_SAWMILL); _name("sawmill"); _forbidden(RACE_ELF); _cost(RES_GOLD, 200); _cost(RES_STONE, 350); _build_time(5); _destroy_cost(350); _upkeep(3); _jobs(CIT_PEASANT, 6); _wages(1); _produces(RES_LOGGING, 5); _description("\ A sawmill is a site for the processing of <link=logging>logging</link> \ operations. It should be built on a <link=city map tile>map tile</link> that \ has <link=trees>trees</link> growing on it; it will remove the trees and turn \ them into <link=wood>wood</link> for use. Once the trees are cleared, the \ sawmill will automatically close.\ "); _build(BUILD_PASTURE); _name("pasture"); _cost(RES_GOLD, 100); _cost(RES_WOOD, 100); _build_time(1); _destroy_cost(20); _upkeep(1); _livestock(500); _description("\ A pasture is a fenced-in area used for keeping <link=livestock>livestock\ </link>. The terrain it is built upon does not matter.\ "); _build(BUILD_BARRACKS); _name("barracks"); _plural(); _cost(RES_GOLD, 800); _cost(RES_WOOD, 650); _build_time(14); _destroy_cost(800); _upkeep(15); _military(50); _description("\ Barracks are a space for the housing and training of <link=army>military units\ </link>.\ "); _build(BUILD_MASONRY); _category(BUILDCAT_MANUFACTURING); _name("masonry"); _cost(RES_GOLD, 250); _cost(RES_WOOD, 600); _build_time(5); _upkeep(3); _jobs(CIT_PEASANT, 3); _wages(1); _recipe(RES_STONE, 1); _units_per_day(3); _max_deficit(0); _uses_mineral(MINERAL_STONE, 1); _description("\ A masonry is a <link=building>building</link> where uncut <link=stone>stone\ </link> is cut into useful blocks.\ "); _build(BUILD_SMELTERY); _category(BUILDCAT_MANUFACTURING); _name("smeltery"); _cost(RES_GOLD, 500); _cost(RES_STONE, 1000); _build_time(6); _unlock(CITY_ACHIEVE_ORES, 0, 0); _jobs(CIT_PEASANT, 10); _wages(2); _recipe(RES_TIN, 1); _recipe_name("Smelt tin (burn wood)"); _units_per_day(1); _max_deficit(0); _uses_mineral(MINERAL_TIN, 1); _uses_resource(RES_WOOD, 3); _recipe(RES_TIN, 3); _recipe_name("Smelt tin (burn coal)"); _units_per_day(3); _max_deficit(0); _uses_mineral(MINERAL_TIN, 3); _uses_mineral(MINERAL_COAL, 1); _recipe(RES_COPPER, 1); _recipe_name("Smelt copper (burn wood)"); _units_per_day(1); _max_deficit(0); _uses_mineral(MINERAL_COPPER, 1); _uses_resource(RES_WOOD, 3); _recipe(RES_COPPER, 3); _recipe_name("Smelt copper (burn coal)"); _units_per_day(3); _max_deficit(0); _uses_mineral(MINERAL_COPPER, 3); _uses_mineral(MINERAL_COAL, 1); _recipe(RES_IRON, 1); _recipe_name("Smelt iron (burn wood)"); _days_per_unit(2); _max_deficit(0); _uses_mineral(MINERAL_IRON, 1); _uses_resource(RES_WOOD, 3); _recipe(RES_IRON, 3); _recipe_name("Smelt iron (burn coal)"); _units_per_day(2); _max_deficit(0); _uses_mineral(MINERAL_IRON, 3); _uses_mineral(MINERAL_COAL, 1); _description("\ A smeltery is a high-temperature furnace used to melt metals out of the \ <link=minerals>ores</link> they naturally appear in. These ores are virtually \ useless before smelting; thus a smeltery is a vital addition to any mining \ operation. It is possible to smelt ores using <link=wood>wood</link> as a \ fuel; however, it is much faster and more efficient to burn <link=coal>coal\ </link> if it is available.\ "); _build(BUILD_MINT); _category(BUILDCAT_MANUFACTURING); _name("mint"); _cost(RES_GOLD, 500); _cost(RES_STONE, 1000); _cost(RES_IRON, 200); _build_time(6); _unlock( CITY_ACHIEVE_POP, CIT_MERCHANT, 1 ); _upkeep(6); _jobs(CIT_MERCHANT, 3); _wages(4); _recipe(RES_GOLD, 1); _recipe_name("Gold (burn wood)"); _units_per_day(3); _max_deficit(0); _uses_mineral(MINERAL_GOLD, 1); _uses_resource(RES_WOOD, 3); _recipe(RES_GOLD, 3); _recipe_name("Gold (burn coal)"); _units_per_day(3); _max_deficit(0); _uses_mineral(MINERAL_GOLD, 3); _uses_mineral(MINERAL_COAL, 1); _description("\ A mint is a <link=building>building</link> where raw <link=gold>gold</link> \ ore can be forged into spendable coins and bars. Doing so requires a fuel \ source; <link=wood>wood</link> can be used, but <link=coal>coal</link> is more \