void traverse_list(LinkList L){ int length = list_length(L); for(int i=0;i<length;i++){ Elemtype e=0; get_elem(L, i, &e); printf("L[%d]=%d\n", i, e); } }
static int log_error(t_list *lst, void (*f)(t_list *elem)) { int i; ERROR_LOG i = 0; printf("file %s.\n", __FILE__); printf("function : %s\n", f == NULL ? "NULL" : "Not NULL"); while (get_elem(lst, i) != NULL) { printf("elem %i : %s\n", i, get_elem(lst, i) == NULL ? "NULL\t" : "Not NULL"); printf("content_size = %d\n", (int)(get_elem(lst, i)->content_size)); printf("content_size == sizeof(0)?%s\n", (get_elem(lst, i))->content_size == sizeof(0) ? "Yes" : "No"); printf("content : %s\n", (get_elem(lst, i))->content == NULL ? "NULL" : (*((int *)get_elem(lst, i)->content) == 0 ? "0" : "Not 0")); i++; } printf("elem %i : %s\n", i, get_elem(lst, i) == NULL ? "NULL" : "Not NULL"); return (0); }
int is_Solution_eq(bip inst, int* test){ if (!is_initialized(inst)) { return 0; } for (int i=0; i<inst.rows; ++i){ if (scalar_product(get_elem(inst, i, 0),test, inst.columns)!=inst.vector[i]) return 0; } return 1; }
int main() { int n = 0,j = 0,k = 0,temp = 0; //no od inputs int a[1000] = {0,}; //storage int i,ii = 0; //itrator int iter; int min; scanf("%d",&n); int count = 0; //counter while(n--){ scanf("%d",&a[i]); if(a[i] == 0){ continue; //overwrite if zero } i++; } iter = get_elem(a); for(i=0;i<=iter;i++){ /* get minimun elem and store it a[i] */ for(j= 1;j<iter;j++){ if(a[0]>a[j]){ temp = a[0]; a[0] = a[j]; a[j] = temp; } } min = a[0]; /*cut the stick */ for(k=0;k<iter;k++){ a[k] = a[k]-min; count++; } /*printf it here*/ printf("%d\n",count); fill_hole(a,iter); iter = get_elem(a); count = 0; i=0; } return 0; }
void set_commands(char *command_line, char *paths, char ***env) { int i; t_command *list; char **split; if (syntax_error(command_line) == 0) return ; while (ft_strchr(command_line, '~') && get_elem(*env, "HOME=") != NULL) command_line = strchange(command_line, '~', get_elem(*env, "HOME=")); split = ft_strsplit(command_line, ';'); i = 0; while (split[i]) { list = init_list(paths, split[i]); run_commands(list, env); i++; } }
int Stack::pop(int& elem) { if (top > 0) { get_elem(elem,--top); return 0; } else return -1; }
void Stack::print() { int elem; for (int i = top-1; i >= 0; --i) { // Print in LIFO order get_elem(elem,i); cout << elem << "\n"; } }
colvarvalue const colvarvalue::get_elem(int const icv) const { if (elem_types.size() > 0) { return get_elem(elem_indices[icv], elem_indices[icv] + elem_sizes[icv], elem_types[icv]); } else { cvm::error("Error: trying to get a colvarvalue element from a vector colvarvalue that was initialized as a plain array.\n"); return colvarvalue(type_notset); } }
SEXP R_soundex_dist(SEXP a, SEXP b) { int na = length(a); int nb = length(b); int nt = MAX(na,nb); int bytes = IS_CHARACTER(a); // when a and b are character vectors; create unsigned int vectors in which // the elements of and b will be copied unsigned int *s = NULL, *t = NULL; if (bytes) { int ml_a = max_length(a); int ml_b = max_length(b); s = (unsigned int *) malloc((ml_a + ml_b) * sizeof(unsigned int)); t = s + ml_a; if (s == NULL) { free(s); error("Unable to allocate enough memory"); } } // create output variable SEXP yy = allocVector(REALSXP, nt); PROTECT(yy); double *y = REAL(yy); // compute distances, skipping NA's unsigned int nfail = 0; int len_s, len_t, isna_s, isna_t; for (int k=0; k < nt; ++k, ++y) { s = get_elem(a, k % na, bytes, &len_s, &isna_s, s); t = get_elem(b, k % nb, bytes, &len_t, &isna_t, t); if (isna_s || isna_t) { (*y) = NA_REAL; } else { (*y) = soundex_dist(s, t, len_s, len_t, &nfail); } } // cleanup and return check_fail(nfail); if (bytes) free(s); UNPROTECT(1); return yy; }
int list_size(const Node* n) { if (n == NULL) { return 0; } else if (get_elem(n)) { return list_size(get_next(n)) + 1; } else { return list_size(get_next(n)); } }
static inline int bitmap_ipmac_gc_test(u16 id, const struct bitmap_ipmac *map, size_t dsize) { const struct bitmap_ipmac_elem *elem; if (!test_bit(id, map->members)) return 0; elem = get_elem(map->extensions, id, dsize); /* Timer not started for the incomplete elements */ return elem->filled == MAC_FILLED; }
bool check_overflow(bip inst){ #ifdef DOUBLE return true; #else long long check=0; int check2=0; for (int i=0; i<inst.rows; ++i) { for (int j=0; j<inst.columns; ++j) { check+=abs(*get_elem(inst, i, j)); check2+=abs(*get_elem(inst, i, j)); if( check!=check2)return false; } if (abs(inst.vector[i])>MAX_COEFF) { return false; } } return true; #endif }
template <typename T, typename X> void dense_matrix<T, X>::apply_from_right(vector <T> & w) { vector<T> t(m_m, numeric_traits<T>::zero()); for (unsigned i = 0; i < m_m; i ++) { auto & v = t[i]; for (unsigned j = 0; j < m_m; j++) v += w[j]* get_elem(j, i); } for (unsigned i = 0; i < m_m; i++) w[i] = t[i]; }
// norm_l calculation static float norm_l(Matrix* matrix, int rows, int cols ) { float norm = 0.; float tmp_norm = 0.; for ( size_t j = 0; j < cols; ++j ) { tmp_norm = 0.; for ( size_t i = 0; i < rows; ++i ) tmp_norm += fabs(get_elem(matrix,i,j)); if (tmp_norm > norm) norm = tmp_norm; } return norm; }
static inline int bitmap_ipmac_do_list(struct sk_buff *skb, const struct bitmap_ipmac *map, u32 id, size_t dsize) { const struct bitmap_ipmac_elem *elem = get_elem(map->extensions, id, dsize); return nla_put_ipaddr4(skb, IPSET_ATTR_IP, htonl(map->first_ip + id)) || (elem->filled == MAC_FILLED && nla_put(skb, IPSET_ATTR_ETHER, ETH_ALEN, elem->ether)); }
template <typename T, typename X> T* dense_matrix<T, X>:: apply_from_left_with_different_dims(vector<T> & w) { T * t = new T[m_m]; for (int i = 0; i < m_m; i ++) { T v = numeric_traits<T>::zero(); for (int j = 0; j < m_n; j++) { v += w[j]* get_elem(i, j); } t[i] = v; } return t; }
int main(void) { t_elem *lst_elem; lst_elem = NULL; lst_init(lst_elem); get_elem(lst_elem); print_list(lst_elem); // while(!getnextlineisblank) return (0); }
/* Print the bip as A<=b or A>=b or A=b to the console */ void print_bip(bip p){ if (!is_initialized(p)) { return; } printf("The input BIP is: \n"); char * ord; switch (p.ordin) { case non_def: ord="<="; printf("Warning: No ordinance sign put in. By default use <=. \n"); break; case smallereq: ord="<="; break; case greatereq: ord=">="; break; case eq: ord="="; break; } #ifdef DOUBLE for (int i=0; i<p.rows; ++i) { for (int j=0; j<p.columns; ++j) { printf("%.3f ",*get_elem(p,i, j)); } printf("%s %.3f \n", ord, p.vector[i]); } #else for (int i=0; i<p.rows; ++i) { for (int j=0; j<p.columns; ++j) { printf("%d ",*get_elem(p,i, j)); } printf("%s %d \n", ord, p.vector[i]); } #endif }
/* Multiplies the two matrices m1 and m2, storing the results into the result * matrix. */ void multiply_matrices(const matrix_t *m1, const matrix_t *m2, matrix_t *result) { int r, c, i, val; assert(m1 != NULL); assert(m2 != NULL); assert(result != NULL); assert(m1->cols == m2->rows); assert(m1->rows == result->rows); assert(m2->cols == result->cols); for (r = 0; r < result->rows; r++) { for (c = 0; c < result->cols; c++) { val = 0; for (i = 0; i < m1->cols; i++) val += get_elem(m1, r, i) * get_elem(m2, i, c); set_elem(result, r, c, val); } } }
template <typename T, typename X> void dense_matrix<T, X>::apply_from_left_to_X(vector<X> & w, lp_settings & ) { vector<X> t(m_m); for (int i = 0; i < m_m; i ++) { X v = zero_of_type<X>(); for (int j = 0; j < m_m; j++) { v += w[j]* get_elem(i, j); } t[i] = v; } for (int i = 0; i < m_m; i ++) { w[i] = t[i]; } }
void add_elem(struct item **head, int n, int num, int power) { if (*head == NULL) *head = get_elem(num, power); else { if (n != 0) { if (n == 1) { struct item *p = *head; *head = get_elem(num, power); (*head)->next = p; } else { struct item *prev = *head; int count = 1; while (count < n - 1 && prev->next != NULL) { prev = prev->next; count++; } struct item *p = prev->next; prev->next = get_elem(num, power); prev->next->next = p; } } else { struct item *elem = *head; while (elem->next != NULL) elem = elem->next; elem->next = get_elem(num, power); } } }
void test_vector_of_integers() { int ints[] = {0, 1, 2, 3, 4, 5, 6, 7}; int ints_count = sizeof(ints)/sizeof(int); Vector vector; init(&vector); int i; for(i = 0; i < ints_count; i++) { push_back(&vector, &ints[i]); } for(i = 0; i < size(&vector); i++) { int element = *(int *)get_elem(&vector, i); assert(ints[i] == element); } destroy(&vector); }
static inline int bitmap_ipmac_do_test(const struct bitmap_ipmac_adt_elem *e, const struct bitmap_ipmac *map, size_t dsize) { const struct bitmap_ipmac_elem *elem; if (!test_bit(e->id, map->members)) return 0; elem = get_elem(map->extensions, e->id, dsize); if (elem->filled == MAC_FILLED) return e->ether == NULL || ether_addr_equal(e->ether, elem->ether); /* Trigger kernel to fill out the ethernet address */ return -EAGAIN; }
template <typename T, typename X> void dense_matrix<T, X>::apply_from_left(vector<T> & w) { T * t = new T[m_m]; for (unsigned i = 0; i < m_m; i ++) { T v = numeric_traits<T>::zero(); for (unsigned j = 0; j < m_m; j++) { v += w[j]* get_elem(i, j); } t[i] = v; } for (unsigned i = 0; i < m_m; i ++) { w[i] = t[i]; } delete [] t; }
template <typename T, typename X> void dense_matrix<T, X>::apply_from_left(X * w, lp_settings & ) { T * t = new T[m_m]; for (int i = 0; i < m_m; i ++) { T v = numeric_traits<T>::zero(); for (int j = 0; j < m_m; j++) { v += w[j]* get_elem(i, j); } t[i] = v; } for (int i = 0; i < m_m; i ++) { w[i] = t[i]; } delete [] t; }
template <typename T, typename X> void dense_matrix<T, X>::apply_from_right(T * w) { T * t = new T[m_m]; for (int i = 0; i < m_m; i ++) { T v = numeric_traits<T>::zero(); for (int j = 0; j < m_m; j++) { v += w[j]* get_elem(j, i); } t[i] = v; } for (int i = 0; i < m_m; i++) { w[i] = t[i]; } delete [] t; }
void lvlup(char ***myenv) { char *newlvl; char *lvl; lvl = get_elem(*myenv, "SHLVL="); if (lvl == NULL) { ft_setenv(myenv, "SHLVL", "1", NULL); return ; } newlvl = ft_itoa(ft_atoi(lvl) + 1); ft_setenv(myenv, "SHLVL", newlvl, NULL); free(lvl); free(newlvl); }
Node* list_insert(Node* n, Node* pos, Cell* c) { if (n == NULL) { std::cerr << "ERROR" << std::endl; exit(1); } else if (n == pos) { n->next_m = make_node(get_elem(n), get_next(n)); n->elem_m = c; return n; } else if (get_next(n) == pos) { n->next_m = make_node(c, pos); return n->next_m; } else { return list_insert(get_next(n), pos, c); } }
int main(int ac, char **av, char **env) { char **myenv; char *home; size_t len_prompt; myenv = tab_dup(env); lvlup(&myenv); if (ac == 1 && av) { home = get_elem(env, "PWD="); prompt(home); len_prompt = ft_strlen(home) + 2; ft_test(myenv, len_prompt); } else ft_putendl("No arguments needed."); return (0); }
/* WARNING: this is just a minimal implementation to get win32gui.cpp/LoadSaveDlgProc working!*/ HTREEITEM TreeView_GetSelection(HWND elem, int item) { LONG i; DebOut("elem: %lx, item: %d\n", elem, item); i=get_index(elem, item); if(i<0) { elem=get_elem(item); i=get_index(elem, item); } if(i<0) { DebOut("ERROR: nIDDlgItem %d found nowhere!?\n", item); return NULL; } DebOut("WARNING: This is just a fake function, only working for win32gui.cpp/LoadSaveDlgProc!\n"); return (HTREEITEM) 666; }