// // Preparing drives for selected grunts. // void Manager::Prepare_Disks(int target) { int i, loop_start, loop_finish; if (target == ALL_WORKERS) { // Preparing all grunts at the same time. This requires a great // amount of coordination on the part of Iometer to ensure that the // grunts do not prepare the same drives. for (i = 0; i < grunt_count; i++) { if (!grunts[i]->Prepare_Disks()) { // Send failure message back to Iometer. msg.data = 0; if (IsBigEndian()) { (void)reorder(msg); } prt->Send(&msg); return; } } loop_start = 0; loop_finish = grunt_count; } else { // Preparing a single grunt. if (!grunts[target]->Prepare_Disks()) { // Send failure message back to Iometer. msg.data = 0; if (IsBigEndian()) { (void)reorder(msg); } prt->Send(&msg); return; } loop_start = target; loop_finish = loop_start + 1; } // Peek to see if the prepare was be canceled by the user. for (i = loop_start; i < loop_finish; i++) { while (grunts[i]->not_ready) { if (prt->Peek()) { prt->Receive(&msg); if (IsBigEndian()) { (void)reorder(msg); } Process_Message(); } else { Sleep(LONG_DELAY); } } grunts[i]->grunt_state = TestIdle; } // Send a message back to Iometer to indicate that we're done preparing. msg.data = 1; // indicates success if (IsBigEndian()) { (void)reorder(msg); } prt->Send(&msg); }
bool equals(const DB::ASTPtr & lhs, const DB::ASTPtr & rhs) { DB::ASTPtr lhs_reordered = lhs->clone(); reorder(&*lhs_reordered); DB::ASTPtr rhs_reordered = rhs->clone(); reorder(&*rhs_reordered); return lhs_reordered->getTreeID() == rhs_reordered->getTreeID(); }
/* Note: * change priority queue implementation */ Graph shortestPathPQ(Graph g, Vertex v) { Graph mst = newGraph(g->nV); int *dist = malloc(sizeof(int) * g->nV); // create the distance array int *pred = malloc(sizeof(int) * g->nV); // create the predecessor array, stores vertices passed through PQueue q = newPQueue(); // create a new priority queue Vertex currentVertex = 0, w = 0; int i = 0; int total = 0; assert(dist != NULL && pred != NULL); // clear all the memory blocks setArray(dist, INF, g->nV); setArray(pred, -1, g->nV); dist[v] = 0; for (i = 0; i < g->nV; i++){ joinPQueue(q, i, dist[i]); } reorder(q, NO_UPDATE, NO_UPDATE); while ( !isEmptyPQ(q) ){ // while priority queue is not empty currentVertex = leavePQueue(q); for (w = 0; w < getnV(g); w++){ if (g->wt[currentVertex][w] == NO_WEIGHT) continue; if (g->wt[currentVertex][w] + dist[currentVertex] < dist[w]){ dist[w] = g->wt[currentVertex][w] + dist[currentVertex]; pred[w] = currentVertex; reorder(q, w, dist[w]); // updates the priority of vertex w as well } } reorder(q, NO_UPDATE, NO_UPDATE); } // construct the mst graph for (i = 0; i < getnV(g); i++){ if (pred[i] != NOT_ASSIGNED){ addEdge(mst, pred[i], i); total += dist[i]; } } printf("Total = %d.\n", total); deletePQueue(q); free(dist); free(pred); return mst; }
bool prepare_query(const char* entry) { position = 0; auto parsed_entry = parseEntry(entry); std::vector<std::vector<bool>> queryset; queryset.push_back(parsed_entry); if (querypoint != nullptr) delete[] querypoint; if (numres != nullptr) { delete numres[0]; delete[] numres; } if (results != nullptr) { delete[] results[0]; delete[] results; } results = new UINT32*[1]; numres = new UINT32*[1]; numres[0] = new UINT32[B + 1]; querypoint = create_dataset(queryset); if (r > 0) { UINT8* new_query = new UINT8[B/8]; reorder(new_query, querypoint, 1, B, order); delete[] querypoint; querypoint = new_query; } return true; }
// // Manager runs assuming Iometer control. Returns TRUE if Dynamo should // continue to run, otherwise FALSE. // BOOL Manager::Run() { while (TRUE) // Receive loop. { #ifdef _DEBUG cout << "in while loop : Manager::Run() " << endl; #endif if ( prt->Receive( &msg ) == PORT_ERROR ) { // Error receiving data message, stop running. cout << "Error receiving message." << endl << flush; return FALSE; } else { #ifdef BIG_ENDIAN_ARCH (void) reorder(msg); #endif // Continue to process messages until manager indicates stopping. if ( !Process_Message() ) return FALSE; // On a reset, stop then restart running the manager. if ( msg.purpose == RESET ) return TRUE; } } }
// // Signalling to stop testing. // void Manager::Stop_Test(int target) { if (target == ALL_WORKERS) { for (int i = 0; i < grunt_count; i++) { grunts[i]->Stop_Test(); } } else { grunts[target]->Stop_Test(); } cout << "Stopping..." << endl << flush; if (target == ALL_WORKERS) { for (int i = 0; i < grunt_count; i++) { grunts[i]->Wait_For_Stop(); } } else { grunts[target]->Wait_For_Stop(); } cout << " Stopped." << endl << flush; // Reply that test has stopped. if (IsBigEndian()) { (void)reorder(msg); } prt->Send(&msg); #if defined(IOMTR_OS_LINUX) || defined(IOMTR_OS_SOLARIS) if (do_syslog) { syslog(LOG_INFO, "I/O Stopped"); } #endif }
// // Stopping recording of test results. // void Manager::Record_Off( int target ) { // Get performance data for end of test. Get_Performance( WHOLE_TEST_PERF, LAST_SNAPSHOT ); Get_Performance( LAST_UPDATE_PERF, LAST_SNAPSHOT ); if ( target == ALL_WORKERS ) { for ( int i = 0; i < grunt_count; i++ ) { grunts[i]->Record_Off(); } } else { grunts[target]->Record_Off(); } cout << " Stopped." << endl << flush; record = FALSE; // No workers are recording data. #if _DEBUG cout << "Recording stopped." << endl << flush; #endif #ifdef BIG_ENDIAN_ARCH (void) reorder(msg); #endif prt->Send( &msg ); }
vector<vector<int> > levelOrderBottom(TreeNode *root) { vector<vector<int>> retVec; if (root == NULL) return retVec; helper(root,retVec); reorder(retVec); return retVec; }
inline void reorder(CPU_Results & var, int send_recv) { int i, j; if (send_recv == RECV) reorder(var.count); for (i = 0; i < var.count; i++) for (j = 0; j < CPU_RESULTS; j++) reorder(var.CPU_utilization[i][j]); if (send_recv == SEND) reorder(var.count); return; }
// // px4_getopt // // returns: // the valid option character // '?' if any option is unknown // -1 if no remaining options // // If the option takes an arg, myoptarg will be updated accordingly. // After each call to px4_getopt, myoptind in incremented to the next // unparsed arg index. // Argv is changed to put all options and option args at the beginning, // followed by non-options. // __EXPORT int px4_getopt(int argc, char *argv[], const char *options, int *myoptind, const char **myoptarg) { char *p; char c; int takesarg; if (*myoptind == 1) if (reorder(argc, argv, options) != 0) return (int)'?'; p = argv[*myoptind]; if (*myoptarg == 0) *myoptarg = argv[*myoptind]; if (p && options && myoptind && p[0] == '-') { c = isvalidopt(p[1], options, &takesarg); if (c == '?') return (int)c; *myoptind += 1; if (takesarg) { *myoptarg = argv[*myoptind]; *myoptind += 1; } return (int)c; } return -1; }
// // Signalling all threads to begin performing I/O. // void Manager::Begin_IO(int target) { msg.data = TRUE; cout << "Beginning to perform I/O..." << endl << flush; #if defined(IOMTR_OS_LINUX) || defined(IOMTR_OS_SOLARIS) if (do_syslog) { syslog(LOG_INFO, "Beginning to perform I/O..."); } #endif if (target == ALL_WORKERS) { for (int i = 0; i < grunt_count; i++) { grunts[i]->Begin_IO(); if (grunts[i]->critical_error) msg.data = FALSE; } } else { grunts[target]->Begin_IO(); if (grunts[target]->critical_error) msg.data = FALSE; } #ifdef _DEBUG cout << " Performing I/O." << endl << flush; #endif // Reply that I/O has started. if (IsBigEndian()) { (void)reorder(msg); } prt->Send(&msg); }
uint64_t RoboTVChannels::checkUpdates() { cRwLock::Lock(false); Channels.Lock(false); cChannels* oldChannels = m_channels; uint64_t oldHash = m_hash; uint64_t newHash = getChannelsHash(&Channels); if(newHash == oldHash) { Channels.Unlock(); cRwLock::Unlock(); return oldHash; } cRwLock::Unlock(); cRwLock::Lock(true); if((m_hash == oldHash) && (m_channels == oldChannels)) { if(m_channels != &Channels) { delete m_channels; } m_channels = reorder(&Channels); m_hash = newHash; } else { // Seems another thread has already updated the hash. newHash = m_hash; } Channels.Unlock(); cRwLock::Unlock(); return newHash; }
int buffer_enque(void* added_item, struct buffer * q) { if(!q->initialized){ return -1; } if(q->q_size>=q->capacity){ // Overflow return -1; } if (q->q_tail >= q->capacity - 1){ reorder(q); } q->q_tail++; q->q_size++; //cprintf("addIndex=%d\n", q->q_tail); q->buf[q->q_tail] = added_item; //printf(1,"addAtAdd=%d\n", ((int*)q->buf[q->q_tail])); //printf(1,"addPointer=%d\n", *((int*)q->buf[q->q_tail])); return 0; }
dnn_mem_t(const dnn_mem_t &rhs, mkldnn_data_type_t dt, mkldnn_format_tag_t tag = mkldnn_format_tag_undef, mkldnn_engine_t engine = engine_ref) : dnn_mem_t(rhs.md_, dt, tag, engine) { if (active_) reorder(rhs); }
// // Signalling all threads to begin performing I/O. // void Manager::Begin_IO( int target ) { msg.data = TRUE; cout << "Beginning to perform I/O..." << endl << flush; if ( target == ALL_WORKERS ) { for ( int i = 0; i < grunt_count; i++ ) { grunts[i]->Begin_IO(); if ( grunts[i]->critical_error ) msg.data = FALSE; } } else { grunts[target]->Begin_IO(); if ( grunts[target]->critical_error ) msg.data = FALSE; } #if _DEBUG cout << " Performing I/O." << endl << flush; #endif // Reply that I/O has started. #ifdef BIG_ENDIAN_ARCH (void) reorder(msg); #endif prt->Send( &msg ); }
void PixelMappingCircle::startNewFunction(int newIdFunction, int perno) { reorder(newIdFunction, perno); idFunction = newIdFunction; active = true; rectPos.x = -1; }
/** Renumber the nodes to make lookups use CPU and disk caches more effectively. * * First group the nodes into blocks so that each block contains the * root of a subtrie and as many levels of its descendants as will fit. * This way, after the root is paged in, the next few lookup * steps need not page in anything else. Then, sort the nodes of each * block in depth-first order. That should give each lookup almost * 1/2 chance to find the next node immediately adjacent. * * With a block size of 1024 bytes, this renumbering reduces the time * required for random lookups by about 1.1%, compared to a plain * depth-first order. However, it's still 2.3% slower than the * database optimized by MaxMind. */ void binary_trie::reorder_in_blocks( std::size_t bytes_per_block) { const edge_type none = -1; std::vector<edge_type> old_to_new, new_to_old; size_t bytes_left = bytes_per_block; old_to_new.resize(nodes.size(), none); new_to_old.reserve(nodes.size()); for (edge_type subtrie = 0; subtrie < nodes.size(); ++subtrie) { // If subtrie has already been added to the output, ignore it. if (old_to_new[subtrie] != none) continue; // Walk breadth-first from subtrie until we have a // block full of nodes or the subtrie runs out. // Don't add these nodes immediately to the output, however. // Instead just list them in nodes_in_block. std::set<edge_type> nodes_in_block; std::queue<edge_type> breadth_first; breadth_first.push(subtrie); if (bytes_left <= 0) bytes_left += bytes_per_block; while (bytes_left > 0 && !breadth_first.empty()) { edge_type edge = breadth_first.front(); breadth_first.pop(); if (edge >= nodes.size()) continue; // Let the last node of the block straddle the // block boundary. That's better than making // the hotter first node do so. bytes_left -= 6; nodes_in_block.insert(edge); breadth_first.push(nodes[edge].edges[0]); breadth_first.push(nodes[edge].edges[1]); } // Add the nodes from nodes_in_block to the output in depth-first order. // This assumes they are all reachable from subtrie. std::stack<edge_type> depth_first; depth_first.push(subtrie); while (!depth_first.empty()) { edge_type edge = depth_first.top(); depth_first.pop(); if (nodes_in_block.find(edge) == nodes_in_block.end()) continue; old_to_new[edge] = new_to_old.size(); new_to_old.push_back(edge); depth_first.push(nodes[edge].edges[1]); depth_first.push(nodes[edge].edges[0]); } } reorder(old_to_new, new_to_old); }
void Line::del_driver( Driver& d ) { auto driver_iter = std::find(drivers_->begin(),drivers_->end(),d); if (driver_iter != drivers_->end()) { drivers_->erase(driver_iter); } reorder(); }
inline void reorder(Net_Results & var, int send_recv) { int i, j; if (send_recv == RECV) reorder(var.ni_count); for (i = 0; i < TCP_RESULTS; i++) reorder(var.tcp_stats[i]); for (i = 0; i < var.ni_count; i++) for (j = 0; j < NI_RESULTS; j++) reorder(var.ni_stats[i][j]); if (send_recv == SEND) reorder(var.ni_count); return; }
int main (int argc, char const * argv []) { static char const * optv [] = { "cdst", PUTOPTV_S_FUNNEL, "enumerate html/xhtml/xml document fragments", "c\tprint CSS stylesheet on stdout", "d\tprint document as text", "s\tprint document as stream", "t\tprint document as tree", (char const *)(0) }; struct node node; void (* xmldump) (struct node const *) = xmlindent; signed c; while (~ (c = getoptv (argc, argv, optv))) { switch (c) { case 'c': xmldump = csstree; break; case 'd': xmldump = xmlindent; break; case 's': xmldump = xmlstream; break; case 't': xmldump = xmltree; break; default: break; } } argc -= optind; argv += optind; if (!argc) { error (1, ENOTSUP, "No filenames given!"); } while ((argc) && (* argv)) { xmlread (& node, * argv); xmlscan (& node); reorder (& node); xmldump (& node); xmlfree (& node); argc--; argv++; } return (0); }
ListNode* reorder(ListNode *head, bool flag) { if (!head) return head; if (flag) { head->next = reorder(head->next, !flag); return head; } else { ListNode *p = head, *prev = NULL; while (p->next) { prev = p; p = p->next; } if (prev) { prev->next = NULL; p->next = reorder(head, !flag); return p; } else { return head; } } }
Encode_Status VaapiEncoderBase::encode(VideoEncRawBuffer *inBuffer) { FUNC_ENTER(); Encode_Status ret; SurfacePtr surface = createSurface(inBuffer); if (!surface) ret = ENCODE_NO_MEMORY; else ret = reorder(surface, inBuffer->timeStamp); return ret; }
/* * lookup a telephone number */ static struct ndbtuple *telcolookup(struct network *np, char *host, char *serv, int nolookup) { struct ndbtuple *t; struct ndbs s; werrstr("can't translate address"); free(ndbgetvalue(db, &s, "sys", host, "telco", &t)); if (t == 0) return ndbnew("telco", host); return reorder(t, s.t); }
void DynamicSuffixArray::deleteAt(size_t position, size_t length) { if(length <= 0) { return; //Nothing to do here } size_t end_position = position + length - 1; //The end of the deleted block size_t rank_of_deleted; uchar last_symbol; //Make sure we do not delete the '\0' or anything outside of the string if(end_position > this->size()) { length = this->size() - position + 1; } //Sample the ISA for the last character in the substring first_modification_position = this->getISA(length + position); old_sym = this->getBWTAt(first_modification_position); //Notify the object that we are deleting (for various off-by-one error resolving) operation = deleting; insertion_point = this->countSymbolsSmallerThan(old_sym) + rank(old_sym, first_modification_position); //Actually delete the substring for(size_t i = length + position - 1; i >= position; i--) { last_symbol = this->getBWTAt(insertion_point); rank_of_deleted = this->rank(last_symbol, insertion_point); this->del(insertion_point); this->sample->deleteBWT(i, insertion_point); if(i == position) { break; } insertion_point = this->countSymbolsSmallerThan(last_symbol) + rank_of_deleted; } previous_position = this->countSymbolsSmallerThan(last_symbol) + rank_of_deleted; insertion_point = first_modification_position; this->del(insertion_point); this->new_sym = last_symbol; insert(last_symbol, insertion_point); reorder(); //Perform a final sampler update this->sample->deleteBWT(position); }
void ProcessorRouter::connect(Processor* destination, const Output* source, int index) { if (isDownstream(destination, source->owner)) { // We are introducing a cycle so insert a Feedback node. Feedback* feedback = new Feedback(); feedback->plug(source); destination->plug(feedback, index); addFeedback(feedback); } else { // Not introducing a cycle so just make sure _destination_ is in order. reorder(destination); } }
void PixelMappingCircle::setup(int totPixel) { this->totPixel = totPixel; values.assign(totPixel, 0); for(int a = 0; a < totPixel; a++) order.push_back(a); reorder(1, 1); fbo.allocate(totPixel*30, 1); fbo.begin(); ofClear(0,0,0,255); fbo.end(); setupGUI(); active = true; }
//takes in 3 command structs and links them into a tree command_t create_command_tree(command_t cmd1, command_t operator, command_t cmd2) { command_t tmp; if (operator->type == PIPE_COMMAND && cmd1->type != SIMPLE_COMMAND) { tmp = reorder(cmd1->u.command[1], operator, cmd2); cmd1->u.command[1] = tmp; return cmd1; } else { operator->u.command[0]=cmd1; operator->u.command[1]=cmd2; return operator; } }
Vehicle* Line::pre_vehicle( Driver& d ) { reorder(); //没有车的时候返回NULL:没有前车 if (drivers_->empty()) { return NULL; } //查找d这辆车 auto driver_iter = find(drivers_->begin(),drivers_->end(),d); if (driver_iter != drivers_->end()) { //找到了d if (driver_iter != drivers_->begin()) { //d不是第一辆车,所以返回d的前一辆 return ((driver_iter-1)->my_vehicle()); } else { //d是第一辆车,返回NULL return NULL; } } else { //没有找到d,那就找刚好比他远的车的前一辆 auto first_further = find_if(drivers_->begin(),drivers_->end(),[&](Driver& lambda_d) { return d.my_vehicle()->m_to_cross() < lambda_d.my_vehicle()->m_to_cross(); }); if (first_further != drivers_->end()) { //找到了一辆刚好比d远的车 if (first_further != drivers_->begin()) {//并且这部车不是开头,则返回这部车的前一辆车 return (first_further-1)->my_vehicle(); } else {//找到处于开头的车,返回NULL return NULL; } } else {//所有的车都比d近,那么返回最远的那一辆车; return drivers_->rbegin()->my_vehicle(); } }// the driver is not found in this line; return NULL; }
ObjectSettings BicyclePlatform::get_settings() { auto result = GameObject::get_settings(); result.add_float(_("X"), &m_center.x, "x", 0.0f, OPTION_HIDDEN); result.add_float(_("Y"), &m_center.y, "y", 0.0f, OPTION_HIDDEN); result.add_int(_("Platforms"), &m_platforms, "platforms", 2); result.add_float(_("Radius"), &m_radius, "radius", 128); result.add_float(_("Momentum change rate"), &m_momentum_change_rate, "momentum-change-rate", 0.1f); result.reorder({"platforms", "x", "y"}); return result; }
void reorder(DB::IAST * ast) { if (ast == nullptr) return; auto & children = ast->children; if (children.empty()) return; for (auto & child : children) reorder(&*child); std::sort(children.begin(), children.end(), [](const DB::ASTPtr & lhs, const DB::ASTPtr & rhs) { return lhs->getTreeID() < rhs->getTreeID(); }); }