int imxctl_set_param(void *handle, act_isp_imx_param_t *param) { imxctl_inter_t *ctl_handle = (imxctl_inter_t *)handle; pthread_mutex_lock(&ctl_handle->cmd_mutex); if(ctl_handle->res_num) { int idx = find_idx(ctl_handle, param->width, param->height); if(-1 != idx) { memcpy(&ctl_handle->param[idx], param, sizeof(act_isp_imx_param_t)); } else { ctl_handle->res_num++; memcpy(&ctl_handle->param[ctl_handle->res_num - 1], param, sizeof(act_isp_imx_param_t)); } } else { ctl_handle->res_num = 1; memcpy(&ctl_handle->param[0], param, sizeof(act_isp_imx_param_t)); ctl_handle->param_inited = 1; } pthread_mutex_unlock(&ctl_handle->cmd_mutex); return 0; }
static const struct user* get_user_by_fd(struct user_list_ctx* ctx, int fd) { struct user* result = 0; size_t i = find_idx(ctx, fd); if (i <= ctx->current_idx) result = ctx->users[i]; return result; }
int find_idx( int start_idx, int end_idx, int val ) { int mid_idx = (start_idx + end_idx) / 2; int idx = 0; if (array[start_idx] < array[end_idx]) { /* ** normal binary search */ idx = bin_search(start_idx, end_idx, val); } else if ((idx = find_idx(start_idx, mid_idx, val)) == -1) { idx = find_idx(mid_idx + 1, end_idx, val); } return idx; }
static uint table_dist(const struct freq_s *est, int est_len, const struct model_s *m, int best_d) { int i; int d = 0; for (i = 0; i < est_len && i < TOPN; i++){ int m_rank; if ((m_rank = find_idx(m->ranked, est[i].idx)) == -1){ d += MISSING_PENALTY; }else d += abs(m_rank - i); if (d >= best_d) break; } return d; }
// zastępowanie usuniętego elemntu ostatnim elementem static void rm_user_by_fd(struct user_list_ctx* ctx, int fd) { size_t i = find_idx(ctx, fd); if (i > ctx->current_idx) return; free(ctx->users[i]); if (i < ctx->current_idx) ctx->users[i] = ctx->users[ctx->current_idx]; ctx->users[ctx->current_idx] = 0; if (ctx->current_idx > 0) { --(ctx->current_idx); } }
int main( int argc, char **argv ) { int idx = 0; idx = find_idx(0, sizeof(array) / sizeof(int) - 1, atoi(argv[1])); if (idx == -1) { printf("Index not found\n"); } else { printf("Index is: %u\n", idx); } return 0; }
int imxctl_get_param(void *handle, act_isp_imx_param_t *param) { imxctl_inter_t *ctl_handle = (imxctl_inter_t *)handle; int idx; int ret = 0; pthread_mutex_lock(&ctl_handle->cmd_mutex); idx = find_idx(ctl_handle, param->width, param->height); if(-1 != idx) { memcpy(param, &ctl_handle->param[idx], sizeof(act_isp_imx_param_t)); } else { OMXDBUG(OMXDBUG_ERR, "%s, no param for this resolution!\n", __func__); ret = -1; } pthread_mutex_unlock(&ctl_handle->cmd_mutex); return ret; }