void db_add_directory_entry(CH_DBFile* db, const char* name, uint64_t offset, uint64_t length) { uint32_t name_len = strlen(name) + 1; uint32_t name_offset = db->name_buf_count; uint32_t entry_num = db->dir_buf_count; CH_DBDirEntry* entry; ensure_buffer_size(&db->name_buf, db->name_buf_count + name_len); memcpy(db->name_buf.data + db->name_buf_count, name, name_len); db->name_buf_count += name_len; db->dir_buf_count = entry_num + 1; ensure_buffer_size(&db->dir_buf, sizeof(CH_DBDirEntry)*db->dir_buf_count); entry = &((CH_DBDirEntry*)db->dir_buf.data)[entry_num]; entry->offset = offset; entry->length = length; entry->name_offset = name_offset; }
static int write_word_to_string(const char* word, void* data){ TextBuffer* buffer = (TextBuffer*) data; int word_len = (int)strlen(word); if (ensure_buffer_size(buffer, word_len)) return 1; strcpy(buffer->text + buffer->used, word); buffer->used += word_len; buffer->text[buffer->used++] = ' '; //replaces \0 with space return 0; }
void solver_type:: calc_next_ortho_interleave ( method_type method , bool is_parallel_method , rate_type x_rate , rate_type y_rate , sheet_type const & src_sheet , sheet_type & trg_sheet ) // // Solve the 2D sheet as two perpendicular 1D solves. // // This is used with forward, backward, and central diff, both serial and parellel. // We only use this to solve the heat equation, not the wave equation. { // Get the appropriate 1d functor. solve_1d_functor_type const & calc_1d_functor = get_1d_functor( method, is_parallel_method); ensure_buffer_size( calc_1d_functor, src_sheet.get_x_count( ), src_sheet.get_y_count( )); // Damping is never used because this only solves heat, not wave. // We pass in a special damping value to ensure damping is ignored, and we always use // set (=) (as opposed to sum or +=) when setting values in the trg. rate_type const damping = finite_difference::get_no_init_damping_set_value< rate_type >( ); if ( x_rate ) { calc_1d_functor( damping, x_rate, src_sheet.get_range_yx( ), trg_sheet.get_range_yx( )); if ( not_early_exit( ) && y_rate ) { // The 2nd calc above must be trg->trg because trg holds the results of the first calculation. calc_1d_functor( damping, y_rate, trg_sheet.get_range_xy( ), trg_sheet.get_range_xy( )); } } else if ( y_rate ) { calc_1d_functor( damping, y_rate, src_sheet.get_range_xy( ), trg_sheet.get_range_xy( )); } else if ( (& src_sheet) != (& trg_sheet) ) { // Both x- and y-rate are zero. // Simple copy from src to trg, unless they are the same sheet. trg_sheet = src_sheet; } }
CH_DbgCompletionResult dbg_auto_complete_global_name(QueryThread* q, CH_DbgCompletionKind kinds, const char* prefix, uint8_t case_sensitive, int32_t from, int32_t desired_count) { CH_DbgCompletionResult result; uint32_t first_match; CH_GrowBuf matches; uint32_t total_match_count; uint32_t prefix_len = strlen(prefix); uint32_t match_index; uint32_t total_chars; uint32_t match; dbg_wait_for_global_symbols(q); init_buf(&matches); /* XXX report progress? */ first_match = find_first_match(prefix, strcasecmp); /* Collect a list of all matches to be returned. Skip global symbols that don't match the search criteria and suppress duplicate name+kind pairs; symbols that have the same name and kind but are multiply defined should just have one autocomplete result. Gather more matches than we really need to get an estimate of the total number. */ match = first_match; total_match_count = 0; while (match < global_symbol_count && total_match_count < (from + desired_count)*4) { GlobalSymbol* m = &global_symbols[match]; ++match; if (strncasecmp(m->name, prefix, prefix_len)) break; if (!(m->kind & kinds)) continue; if (case_sensitive && strncmp(m->name, prefix, prefix_len)) continue; if (total_match_count > 0) { GlobalSymbol* prev_match = &global_symbols[((uint32_t*)matches.data)[total_match_count - 1]]; if (strcmp(m->name, prev_match->name) == 0 && m->kind == prev_match->kind) continue; } ensure_buffer_size(&matches, sizeof(uint32_t)*(total_match_count + 1)); ((uint32_t*)matches.data)[total_match_count] = match - 1; total_match_count++; } result.total_matches = total_match_count; result.match_count = total_match_count - from; if (result.match_count <= 0) { safe_free(matches.data); result.match_count = 0; result.match_names = NULL; result.match_kinds = NULL; return result; } if (result.match_count > desired_count) { result.match_count = desired_count; } total_chars = 0; for (match_index = 0; match_index < result.match_count; ++match_index) { uint32_t i = ((uint32_t*)matches.data)[match_index + from]; total_chars += strlen(global_symbols[i].name) + 1; } result.match_kinds = safe_malloc(sizeof(CH_DbgCompletionKind)*result.match_count); result.match_names = safe_malloc(total_chars); total_chars = 0; for (match_index = 0; match_index < result.match_count; ++match_index) { uint32_t i = ((uint32_t*)matches.data)[match_index + from]; uint32_t len = strlen(global_symbols[i].name) + 1; result.match_kinds[match_index] = global_symbols[i].kind; memcpy(result.match_names + total_chars, global_symbols[i].name, len); total_chars += len; } safe_free(matches.data); return result; }
void solver_type:: calc_next_wave_with_damping ( method_type method , bool is_parallel_method , rate_type damping , rate_type x_rate , rate_type y_rate , sheet_type const & src_sheet , sheet_type & trg_sheet ) { // Damping cannot be one of the special values. Those are only used to make the // mixing algorithms work. d_assert( damping != finite_difference::get_no_init_damping_set_value< rate_type >( )); d_assert( damping != finite_difference::get_no_init_damping_sum_value< rate_type >( )); // We solve forward-diff with 2-d functions instead the 1-d functors for all the others. if ( method == e_forward_diff ) { clear_buffers( ); // forward-diff doesn't need buffers -- free their alloc'd memory if ( is_parallel_method ) { // We don't use a functor for 2d forward diff. Instead we have two functions: // one for serial and one for parallel. // We have to pass in all the state since we don't have a functor to wrap it up for us. calc_next_2d_forward_diff_parallel ( output_params_.ref_early_exit( ) , damping, x_rate, y_rate , src_sheet.get_range_yx( ) , trg_sheet.get_range_yx( ) ); } else { // The serial (not parallel) 2d forward-diff function. calc_next_2d_forward_diff_serial ( output_params_.ref_early_exit( ) , damping, x_rate, y_rate , src_sheet.get_range_yx( ) , trg_sheet.get_range_yx( ) ); } } else /* central or backward diff */ { // We use the 1d functors. The damping params tell them how we're using them. d_assert( (method == e_backward_diff) || (method == e_central_diff)); // Get the appropriate 1d functor. solve_1d_functor_type const & calc_1d_functor = get_1d_functor( method, is_parallel_method); ensure_buffer_size( calc_1d_functor, src_sheet.get_x_count( ), src_sheet.get_y_count( )); // This is a 2-pass algorithm that uses different damping values for each pass. rate_type const damping_1st_pass = damping; rate_type const damping_2nd_pass = finite_difference::get_no_init_damping_sum_value< rate_type >( ); // Two pass algorithms: // The 1st pass calculates values from src_sheet and writes them to trg_sheet. // The 2nd pass calculates other values from the original src_sheet and sums them into trg_sheet. // Improve? Since the first pass does slightly more work, perhaps we should do the narrow // dimension first? Although it probably doesn't matter at all. // We could just copy if (damping==1) and (x_rate==0) and (y_rate==0). calc_1d_functor( damping_1st_pass, x_rate, src_sheet.get_range_yx( ), trg_sheet.get_range_yx( )); if ( not_early_exit( ) ) { // 2nd-pass damping says use +=. calc_1d_functor( damping_2nd_pass, y_rate, src_sheet.get_range_xy( ), trg_sheet.get_range_xy( )); } } }