// Monotonic total order on universe level terms. bool is_lt(level const & a, level const & b, bool use_hash) { if (is_eqp(a, b)) return false; unsigned da = get_depth(a); unsigned db = get_depth(b); if (da < db) return true; if (da > db) return false; if (kind(a) != kind(b)) return kind(a) < kind(b); if (use_hash) { if (hash(a) < hash(b)) return true; if (hash(a) > hash(b)) return false; } if (a == b) return false; switch (kind(a)) { case level_kind::Zero: lean_unreachable(); // LCOV_EXCL_LINE case level_kind::Param: case level_kind::Global: case level_kind::Meta: return to_param_core(a).m_id < to_param_core(b).m_id; case level_kind::Max: case level_kind::IMax: if (to_max_core(a).m_lhs != to_max_core(b).m_lhs) return is_lt(to_max_core(a).m_lhs, to_max_core(b).m_lhs, use_hash); else return is_lt(to_max_core(a).m_rhs, to_max_core(b).m_rhs, use_hash); case level_kind::Succ: return is_lt(succ_of(a), succ_of(b), use_hash); } lean_unreachable(); // LCOV_EXCL_LINE }
format pp(level l, bool unicode, unsigned indent) { if (is_explicit(l)) { lean_assert(get_depth(l) > 0); return format(get_depth(l) - 1); } else { switch (kind(l)) { case level_kind::Zero: lean_unreachable(); // LCOV_EXCL_LINE case level_kind::Param: case level_kind::Global: return format(to_param_core(l).m_id); case level_kind::Meta: return format("?") + format(meta_id(l)); case level_kind::Succ: { auto p = to_offset(l); return pp_child(p.first, unicode, indent) + format("+") + format(p.second); } case level_kind::Max: case level_kind::IMax: { format r = format(is_max(l) ? "max" : "imax"); r += nest(indent, compose(line(), pp_child(to_max_core(l).m_lhs, unicode, indent))); // max and imax are right associative while (kind(to_max_core(l).m_rhs) == kind(l)) { l = to_max_core(l).m_rhs; r += nest(indent, compose(line(), pp_child(to_max_core(l).m_lhs, unicode, indent))); } r += nest(indent, compose(line(), pp_child(to_max_core(l).m_rhs, unicode, indent))); return group(r); }} lean_unreachable(); // LCOV_EXCL_LINE } }
static void print(std::ostream & out, level l) { if (is_explicit(l)) { lean_assert(get_depth(l) > 0); out << get_depth(l) - 1; } else { switch (kind(l)) { case level_kind::Zero: lean_unreachable(); // LCOV_EXCL_LINE case level_kind::Param: case level_kind::Global: out << to_param_core(l).m_id; break; case level_kind::Meta: out << "?" << meta_id(l); break; case level_kind::Succ: out << "succ "; print_child(out, succ_of(l)); break; case level_kind::Max: case level_kind::IMax: if (is_max(l)) out << "max "; else out << "imax "; print_child(out, to_max_core(l).m_lhs); // max and imax are right associative while (kind(to_max_core(l).m_rhs) == kind(l)) { l = to_max_core(l).m_rhs; out << " "; print_child(out, to_max_core(l).m_lhs); } out << " "; print_child(out, to_max_core(l).m_rhs); break; } } }
bool operator==(level const & l1, level const & l2) { if (kind(l1) != kind(l2)) return false; if (hash(l1) != hash(l2)) return false; if (is_eqp(l1, l2)) return true; switch (kind(l1)) { case level_kind::Zero: return true; case level_kind::Param: case level_kind::Global: case level_kind::Meta: return to_param_core(l1).m_id == to_param_core(l2).m_id; case level_kind::Max: case level_kind::IMax: case level_kind::Succ: if (to_composite(l1).m_depth != to_composite(l2).m_depth) return false; break; } switch (kind(l1)) { case level_kind::Zero: case level_kind::Param: case level_kind::Global: case level_kind::Meta: lean_unreachable(); // LCOV_EXCL_LINE case level_kind::Max: case level_kind::IMax: return to_max_core(l1).m_lhs == to_max_core(l2).m_lhs && to_max_core(l1).m_rhs == to_max_core(l2).m_rhs; case level_kind::Succ: if (is_explicit(l1) != is_explicit(l2)) { return false; } else if (is_explicit(l1)) { lean_assert(get_depth(l1) == get_depth(l2)); // the depths are equal, then l1 and l2 must be the same universe return true; } else { return succ_of(l1) == succ_of(l2); } } lean_unreachable(); // LCOV_EXCL_LINE }
level_max_core(bool imax, level const & l1, level const & l2): level_composite(imax ? level_kind::IMax : level_kind::Max, hash(hash(l1), hash(l2)), std::max(get_depth(l1), get_depth(l2)) + 1, has_param(l1) || has_param(l2), has_global(l1) || has_global(l2), has_meta(l1) || has_meta(l2)), m_lhs(l1), m_rhs(l2) { lean_assert(!is_explicit(l1) || !is_explicit(l2)); }
int get_depth(Tree* t) { int depth = 0; if (t) { int a = get_depth(t->left); int b = get_depth(t->right); depth = a>b?a:b; depth++; } return depth; }
int get_depth(struct node *p) { int l,r; if (p==NULL) return 0; else { l = 1 + get_depth(p->left); r = 1 + get_depth(p->right); return (l>r) ? l : r; } }
int get_maxdistance(Tree* t) { int maxd = 0; if (t) { maxd = get_depth(t->left) + get_depth(t->right); int maxdl = get_maxdistance(t->left); int maxdr = get_maxdistance(t->right); maxd = maxdl > maxd ? maxdl : maxd; maxd = maxdr > maxd ? maxdr : maxd; } return maxd; }
int main(int argc, const char * argv[]) { FILE *file = fopen(argv[1], "r"); char line[LINE_LEN]; while (fgets(line, LINE_LEN, file)) { int node1, node2; sscanf(line, "%d %d", &node1, &node2); printf("%d\n", depth_to_ancestor(min(get_depth(node1), get_depth(node2)) - 1)); } return 0; }
int get_depth (struct treenode* root) { int l_depth, r_depth; if (!root) { return(0); } l_depth = 1 + get_depth(root->left); r_depth = 1 + get_depth(root->right); return(l_depth > r_depth ? l_depth:r_depth); }
bool KeySpecHelper::has_wildcards(size_t start, size_t depth) { size_t depth_k = get_depth(); if (!depth || depth > depth_k) depth = depth_k; for (unsigned i = start; i < depth; i++) { auto path_entry = get_path_entry(i); RW_ASSERT(path_entry); size_t n_keys = rw_keyspec_entry_num_keys(path_entry); for (unsigned j = 0; j < n_keys; j++) { if (!protobuf_c_message_has_field(nullptr, &path_entry->base, RW_SCHEMA_TAG_ELEMENT_KEY_START+j)) { return true; } } } return false; }
int* get_number_of_nodes_at_levels (struct treenode* root, int* len) { int* num_nodes_in_level; int index, depth; if (!len) { return(NULL); } if (!root) { *len = 0; return(NULL); } depth = get_depth(root); if (depth == 0) { *len = 0; return(NULL); } num_nodes_in_level = (int*)malloc(sizeof(int) * depth); if (!num_nodes_in_level) { *len = 0; return(NULL); } memset(num_nodes_in_level, 0, sizeof(int) * depth); populate_num_nodes_at_levels(root, num_nodes_in_level, 0, depth); *len = depth; return(num_nodes_in_level); }
void print_tree(bintree* tree) { unsigned int height = get_depth(tree); node* root = tree->root; node *arr[100], *arr2[100]; unsigned int nodes; for (int i = 0; i < height * 2; i++) printf(" "); printf("%2d\n", root->data); arr2[0] = root; nodes = 1; int not_null_flag = 1; for(int depth = 2;not_null_flag; depth++) { not_null_flag = 0; for (int i = 0; i < nodes; i++) { arr[i*2] = arr2[i] ? arr2[i]->lchild : NULL; arr[i*2 + 1] = arr2[i] ? arr2[i]->rchild : NULL; if (arr[i*2] || arr[i*2 + 1]) not_null_flag = 1; } nodes *= 2; memcpy(arr2, arr, nodes * sizeof(node*)); if (not_null_flag) { print_slice(arr2, nodes, height, depth); } } }
string AstExpressionList::to_string(int d) { string res = get_depth(d) + "EXP LIST\n"; for(vector<Expression*>::iterator it = exps.begin(); it != exps.end(); it++) { res += (*it)->to_string(d+1); } return res; }
void update(void) { // Coordinate system has been corrected to reflect actual display orientation uint32_t raw_zeta = *(uint32_t*)get_depth(200, 120); uint32_t raw_depth = raw_zeta & 0xFFFFFF; float f_depth = raw_depth / (float)0xFFFFFF; uint8_t raw_stencil = raw_zeta >> 24; float f_stencil = raw_stencil / (float)0xFF; uint32_t raw_color = *(uint32_t*)get_color(200, 120); printf("Last frame stencil: 0x%02" PRIX8 " = %.2f\n", raw_stencil, f_stencil); printf("Last frame depth: 0x%06" PRIX32 " = %.2f\n", raw_depth, f_depth); float f_color = 0.0f; f_color += (raw_color & 0xFF) / 255.0f; f_color += ((raw_color >> 8) & 0xFF) / 255.0f; f_color += ((raw_color >> 16) & 0xFF) / 255.0f; f_color += (raw_color >> 24) / 255.0f; f_color /= 4.0f; printf("Last frame color: 0x%08" PRIX32 " = %.2f\n", raw_color, f_color); //FIXME: Configure clear for next frame uint32_t clear_value = 0x55555555; if (clear_high) { clear_value ^= 0xFFFFFFFF; } rb.clearColor = clear_value; rb.clearDepth = clear_value; }
// Once you're done, just type make and it should produce an executable // called <name of source file>.out int main() { // Initialize by connecting to the FPGA init_fpga(); // Power on the system power_on(); /* YOUR CODE GOES HERE */ sleep(2); // Pause for 2 seconds int x, y, z, d; // Get acceleration vector and depth get_accel(&x, &y, &z); d = get_depth(); printf("Acceleration is: (%d, %d, %d)\n", x, y, z); printf("Current depth is: %d\n", d); int p = get_power(); // Check if power is still on printf("Power system %s\n", p ? "is good": "has failed"); puts("Exiting..."); /* END */ // Power off and release resources exit_safe(); return 0; }
/** * Returns the number of array layers (zero for non * array textures). * @return The number of array layers. */ inline Uint32 get_layer_count() const { if (!get_array()) { return 0; } if (get_depth() == 0) { return std::max(static_cast<Uint32>(1), get_height()); } return std::max(static_cast<Uint32>(1), get_depth()); }
string AstIdentifierList::to_string(int d) { string res = get_depth(d) + "ID LIST\n"; for(vector<AstIdentifier*>::iterator it = ids.begin(); it != ids.end(); it++) { res += (*it)->to_string(d+1); } return res; }
void balance(int id){ auto count = flat_tree.count(id);; if (count > max_items_per_quad) { int target_depth = get_depth(id) + logn(count, 4); for (auto&a : query_quad(id)) { //flat_tree.insert({}) insert(id, positions[id], target_depth); } flat_tree.erase(id); // erase all by key, can also erase iterator } }
void GobAsteroid::death () { STACKTRACE; Animation *a = new Animation(this, pos, explosion, 0, explosion->frames(), time_ratio, get_depth()); a->match_velocity(this); game->add(a); game->add ( new GobAsteroid() ); return; }
// Update depth reading by tracking the sum // of the last NUM_DEPTH_VALUES readings void update_depth_reading() { static unsigned idx = 0; depth_sum -= depth_values[idx]; int depth_reading = get_depth(); depth_values[idx] = depth_reading; depth_sum += depth_reading; // Rotate idx idx++; idx %= NUM_DEPTH_VALUES; }
level mk_max(level const & l1, level const & l2) { if (is_explicit(l1) && is_explicit(l2)) { return get_depth(l1) >= get_depth(l2) ? l1 : l2; } else if (l1 == l2) { return l1; } else if (is_zero(l1)) { return l2; } else if (is_zero(l2)) { return l1; } else if (is_max(l2) && (max_lhs(l2) == l1 || max_rhs(l2) == l1)) { return l2; // if l2 == (max l1 l'), then max l1 l2 == l2 } else if (is_max(l1) && (max_lhs(l1) == l2 || max_rhs(l1) == l2)) { return l1; // if l1 == (max l2 l'), then max l1 l2 == l1 } else { auto p1 = to_offset(l1); auto p2 = to_offset(l2); if (p1.first == p2.first) { lean_assert(p1.second != p2.second); return p1.second > p2.second ? l1 : l2; } else { return cache(level(new level_max_core(false, l1, l2))); } } }
void handle_trace(PyFrameObject *frame, Record__RecordType record_type, int n_arguments) { static int count = 0; count++; record->type = record_type; record->n_arguments = n_arguments; record->time = floattime(); record->tid = (long) pthread_self(); record->depth = get_depth(); set_string(&(record->module), PYSTR_TO_CHAR(frame->f_code->co_filename)); set_string(&(record->function), PYSTR_TO_CHAR(frame->f_code->co_name)); record->lineno = frame->f_code->co_firstlineno; record__pack(record, record_buf); ring_write(global_ring, record_buf, (unsigned long) record__get_packed_size(record)); CLEAR_REFS(); }
/* FIXME! We should do the array thing here too. */ static void parse_sample_keyvalue(void *_sample, const char *key, const char *value) { struct sample *sample = _sample; if (!strcmp(key, "sensor")) { sample->sensor = atoi(value); return; } if (!strcmp(key, "ndl")) { sample->ndl = get_duration(value); return; } if (!strcmp(key, "tts")) { sample->tts = get_duration(value); return; } if (!strcmp(key, "in_deco")) { sample->in_deco = atoi(value); return; } if (!strcmp(key, "stoptime")) { sample->stoptime = get_duration(value); return; } if (!strcmp(key, "stopdepth")) { sample->stopdepth = get_depth(value); return; } if (!strcmp(key, "cns")) { sample->cns = atoi(value); return; } if (!strcmp(key, "po2")) { pressure_t p = get_pressure(value); sample->setpoint.mbar = p.mbar; return; } if (!strcmp(key, "heartbeat")) { sample->heartbeat = atoi(value); return; } if (!strcmp(key, "bearing")) { sample->bearing.degrees = atoi(value); return; } report_error("Unexpected sample key/value pair (%s/%s)", key, value); }
short get_depth(short i) { auto& cached = depth[i]; if (cached != 0) return cached; for (short j = 0; children[i][j] != 0; ++j) { short depth_candidate = get_depth(children[i][j]); if (depth_candidate > cached) { cached = depth_candidate; deepest_child[i] = children[i][j]; } } return ++cached; }
const ProtobufCFieldDescriptor* KeySpecHelper::get_leaf_pb_desc() { if (is_generic()){ return NULL; } if (!is_leafy()) { return NULL; } size_t depth = get_depth(); if (depth < 2) { return NULL; } auto leaf_entry = get_path_entry(depth-1); RW_ASSERT(leaf_entry); auto element_id = ((RwSchemaPathEntry*)leaf_entry)->element_id; RW_ASSERT(element_id); RW_ASSERT(element_id->element_tag); auto leaf_tag = element_id->element_tag; auto parent_entry = get_path_entry(depth-2); RW_ASSERT(parent_entry); if (!(parent_entry->base.descriptor->ypbc_mdesc && parent_entry->base.descriptor->ypbc_mdesc->u)) { return NULL; } auto mdesc = parent_entry->base.descriptor->ypbc_mdesc->u->msg_msgdesc; RW_ASSERT(mdesc.num_fields); auto parent_tag = mdesc.pb_element_tag; if ((parent_tag > leaf_tag) || ((parent_tag+mdesc.num_fields) < leaf_tag)) { return NULL; } auto index = leaf_tag - parent_tag -1; const ProtobufCFieldDescriptor *fd = mdesc.ypbc_flddescs[index].pbc_fdesc; RW_ASSERT(fd); return fd; }
void occRasterizer::propagade () { // Clip-and-propagade zero level occTri** pFrame = get_frame (); float* pDepth = get_depth (); for (int y=0; y<occ_dim_0; y++) { for (int x=0; x<occ_dim_0; x++) { int ox=x+2, oy=y+2; // Y2-connect int pos = oy*occ_dim+ox; int pos_up = pos-occ_dim; int pos_down = pos+occ_dim; int pos_down2 = pos_down+occ_dim; occTri* Tu1 = pFrame [pos_up]; if (Tu1) { // We has pixel 1scan up if (shared(Tu1,pFrame[pos_down])) { // We has pixel 1scan down float ZR = (pDepth[pos_up]+pDepth[pos_down])/2; if (ZR<pDepth[pos]) { pFrame[pos] = Tu1; pDepth[pos] = ZR; } } else if (shared(Tu1,pFrame[pos_down2])) { // We has pixel 2scan down float ZR = (pDepth[pos_up]+pDepth[pos_down2])/2; if (ZR<pDepth[pos]) { pFrame[pos] = Tu1; pDepth[pos] = ZR; } } } // float d = pDepth[pos]; clamp (d,-1.99f,1.99f); bufDepth_0[y][x] = df_2_s32 (d); } } // Propagate other levels propagade_depth (bufDepth_1,bufDepth_0,occ_dim_1); propagade_depth (bufDepth_2,bufDepth_1,occ_dim_2); propagade_depth (bufDepth_3,bufDepth_2,occ_dim_3); }
bool KeySpecHelper::is_leafy() { size_t depth = get_depth(); if (!depth) { return false; } auto path_entry = get_path_entry(depth-1); RW_ASSERT(path_entry); auto element = rw_keyspec_entry_get_element_id(path_entry); RW_ASSERT(element); bool ret_val = (element->element_type == RW_SCHEMA_ELEMENT_TYPE_LEAF); return ret_val; }
uint32_t ktx_texture::get_total_images() const { if (!is_valid() || !get_num_mips()) return 0; // bogus: //return get_num_mips() * (get_depth() * get_num_faces() * get_array_size()); // Naive algorithm, could just compute based off the # of mips uint32_t max_index = 0; for (uint32_t mip_level = 0; mip_level < get_num_mips(); mip_level++) { uint32_t total_zslices = math::maximum<uint32_t>(get_depth() >> mip_level, 1U); uint32_t index = get_image_index(mip_level, get_array_size() - 1, get_num_faces() - 1, total_zslices - 1); max_index = math::maximum<uint32_t>(max_index, index); } return max_index + 1; }
void ActuatorOutputSubmarine::special_cmd(SPECIAL_COMMAND cmd) { switch(cmd) { case (SUB_POWER_ON): power_on(); break; case (SUB_STARTUP_SEQUENCE): SubmarineSingleton::get_instance().set_target_yaw(get_yaw()); SubmarineSingleton::get_instance().set_target_depth(get_depth()); startup_sequence(); break; case (SUB_MISSION_STARTUP_SEQUENCE): mission_startup_sequence(); break; case (SUB_POWER_OFF): power_off(); break; default: break; } }