void solve(double theta, std::ofstream& fout){ double v0 = 700.0; double x, y, vx, vy, t; // initial condition x = 0; y = 0; vx = v0 * cos(theta); vy = v0 * sin(theta); t = 0; int steps = 0; std::cout<<"begin solving problem"<<std::endl; while (y >= 0.0) { fout<<t<<' '<<x<<' '<<y<<std::endl; iter_func(x, y, vx, vy); t += DT; steps += 1; } fout<<t<<' '<<x<<' '<<y<<std::endl; std::cout<<"problem solved after "<<steps<<" steps"<<std::endl; std::cout<<"t: "<<t<<" s"<<std::endl <<"xf: "<<x<<" m"<<std::endl <<"v: "<<sqrt(vx*vx+vy*vy)<<" m/s"<<std::endl <<"vx: "<<vx<<" m/s"<<std::endl<<"vy: "<<vy<<" m/s"<<std::endl<<std::endl; }
int dm_target_iterate(void (*iter_func)(struct target_type *tt, void *param), void *param) { struct target_type *tt; down_read(&_lock); list_for_each_entry(tt, &_targets, list) iter_func(tt, param); up_read(&_lock); return 0; }
/** * Helper function to apply operation on each item. * * @param q A pointer to the queue data structure. * @param iter_func Function pointer to operation to be applied. * @param arg Pass through variable to iter_func. * @return void */ void queue_iterate(queue_t *q, void (*iter_func)(void *, void *), void *arg) { struct queue_node *node; if(queue_size(q) == 0) { return; } node = q->head; while(node != NULL) { iter_func(node->item, arg); node = node->next; } }
// Recursively iterates static int recursive_iter(radix_node *n, void *data, int(*iter_func)(void *data, char *key, void *value)) { int ret = 0; if (n->edges[0]) { radix_leaf *leaf = n->edges[0]; ret = iter_func(data, leaf->key, leaf->value); } radix_node *child; for (int i=1; !ret && i < 256; i++) { child = (radix_node*)n->edges[i]; if (!child) continue; ret = recursive_iter(child, data, iter_func); } return ret; }
int cfpkt_iterate(struct cfpkt *pkt, u16 (*iter_func)(u16, void *, u16), u16 data) { /* * Don't care about the performance hit of linearizing, * Checksum should not be used on high-speed interfaces anyway. */ if (unlikely(is_erronous(pkt))) return -EPROTO; if (unlikely(skb_linearize(&pkt->skb) != 0)) { PKT_ERROR(pkt, "linearize failed\n"); return -EPROTO; } return iter_func(data, pkt->skb.data, cfpkt_getlen(pkt)); }