void test9(void) { ElementNode_handle pE1=0,pE2=0,pRes; int i; printf("\n==== VECTOR ADDITION 2 =================\n"); for(i=0;i<5;++i) insert_element(&pE1,2000*i,i); for(i=0;i<10;++i) insert_element(&pE2,1000*i,i); pRes=add(pE1,pE2); printf("pE1 + pE2 = \n"); printf("raw:\n"); print_elements(pRes); printf("\n"); free_elements(pRes); pRes=add(pE2,pE1); printf("pE2 + pE1 = \n"); printf("raw:\n"); print_elements(pRes); printf("\n"); free_elements(pRes); pRes=add(pE1,pE1); printf("pE1 + pE1 = \n"); printf("raw:\n"); print_elements(pRes); printf("\n"); free_elements(pRes); free_elements(pE1); free_elements(pE2); }
void test6(void) { ElementNode_handle pE1=0,pE2=0,pE3=0; int i; printf("\n==== SCALAR MULTIPLICATION =================\n"); for(i=0;i<20;++i) insert_element(&pE1,i,i*i); printf("vector pE1 formatted:\n"); printf_elements(pE1,"%4d",20); printf("\n"); for(i=0;i<20;++i) insert_element(&pE2,40-2*i,i); printf("vector pE2 formatted:\n"); printf_elements(pE2,"%4d",40); printf("\n"); for(i=0;i<20;++i) { if (i%2) insert_element(&pE3,2*i,i); else insert_element(&pE3,41-2*i,-i); } printf("vector pE3 formatted:\n"); printf_elements(pE3,"%4d",40); printf("\n"); printf("scalar product pE1 and pE2 = %i\n",scalar_product(pE1,pE2)); printf("scalar product pE2 and pE3 = %i\n",scalar_product(pE2,pE3)); printf("scalar product pE3 and pE1 = %i\n",scalar_product(pE3,pE1)); printf("scalar product pE1 and pE1 = %i\n",scalar_product(pE1,pE1)); free_elements(pE1); free_elements(pE2); free_elements(pE3); }
static int move_to_env_suite(t_env *env, char *cat, char *pwd, char *oldpwd) { char *tmp; tmp = NULL; if (cat) { tmp = pwd; pwd = ft_strjoin(pwd, cat); ft_memdel((void**)&tmp); } if (pwd && chdir(pwd) == 0) { move_old_and_pwd(env, oldpwd, pwd); free_elements(pwd, cat, NULL, NULL); return (0); } else { cant_move_home(); free_elements(pwd, cat, NULL, NULL); return (1); } }
void test10( void ) { ElementNode * pE1=0, *pE2=0, *pRes; int i; printf( "\n==== VECTOR ADDITION (ZEROES) ========\n" ); for( i=0; i<20; ++i ) insert_element( &pE1,i,i*i ); printf( "vector pE1 formatted:\n" ); printf_elements( pE1,"%4d",20 ); printf( "\n" ); for( i=0; i<20; ++i ) insert_element( &pE2,i,-i*i ); printf( "vector pE2 formatted:\n" ); printf_elements( pE2,"%4d",20 ); printf( "\n" ); pRes=add( pE1,pE2 ); printf( "pE1 + pE2 = \n" ); printf_elements( pRes,"%4d",20 ); printf( "\n" ); printf( "raw:\n" ); print_elements( pRes ); printf( "\n" ); free_elements( pRes ); pRes=add( pE2,pE1 ); printf( "pE2 + pE1 = \n" ); printf_elements( pRes,"%4d",20 ); printf( "\n" ); printf( "raw:\n" ); print_elements( pRes ); printf( "\n" ); free_elements( pRes ); free_elements( pE1 ); free_elements( pE2 ); }
void test7( void ) { ElementNode * pE1=0, *pE2=0; int i; printf( "\n==== SCALAR MULTIPLICATION 2 =================\n" ); for( i=0; i<20; ++i ) insert_element( &pE1,1000*i,i*i ); for( i=0; i<20; ++i ) insert_element( &pE2,500*i,i ); printf( "scalar product pE1 and pE2 = %i\n",scalar_product( pE1,pE2 ) ); printf( "scalar product pE2 and pE1 = %i\n",scalar_product( pE2,pE1 ) ); printf( "scalar product pE1 and pE1 = %i\n",scalar_product( pE1,pE1 ) ); free_elements( pE1 ); free_elements( pE2 ); }
void free_rows( RowNode_handle p_r ) { /* pointer to the columns */ ElementNode_handle pColumn; /* pointer to traverse the rows */ RowNode_handle TempRow; /* validate matrix exists */ if(!p_r) return; /* while rows are valid */ while(p_r) { /* assign column pointer to start of column */ pColumn = p_r->elements; /* delete this row */ free_elements(pColumn); /* move to next row */ TempRow = p_r->next; /* free current row, after columns have been freed */ free(p_r); /* move to new current row */ p_r = TempRow; } }
static int move_to_env(t_env *environ, char *env, char *av) { char *oldpwd; char *pwd; char buffer[256]; char *cat; char *tmp; cat = NULL; tmp = NULL; pwd = NULL; if (!ft_strcmp(env, "OLDPWD") && ft_strlen(av) > 0) { tmp = ft_strsub(av, 1, ft_strlen(av)); cat = ft_strdup(tmp); av = ft_strdup(tmp); } oldpwd = getcwd(buffer, 256); pwd = return_env(environ->environ, env); if (!pwd) { cant_move_home(); move_old_and_pwd(environ, oldpwd, pwd); free_elements(pwd, cat, tmp, NULL); return (1); } ft_memdel((void**)&tmp); ft_memdel((void**)&av); return (move_to_env_suite(environ, cat, pwd, oldpwd)); }
void test12(void) { ElementNode_handle pE1=0; int pos=10000; printf("\n==== TESTING FIND 2 ========\n"); insert_element(&pE1,pos,5); print_elements(pE1); printf("\n"); printf ("value %i at position %i\n",get(pE1,pos),pos); free_elements(pE1); }
void test11(void) { ElementNode_handle pE1=0; int i; printf("\n==== TESTING FIND ========\n"); for(i=0;i<20;i+=2) insert_element(&pE1,i,i*i); printf_elements(pE1,"%4d",20); printf("\n"); printf("print vector using get - very inefficient!!!\n"); for(i=0;i<20;++i) printf("index %i, value %i\n",i,get(pE1,i)); free_elements(pE1); }
void test0(void) { ElementNode_handle pE1=0; int i; printf("\n====== INSERTS BACK =============================\n"); for(i=0;i<20;++i) insert_element(&pE1,3*i,i*i); printf("vector 1 formatted:\n"); printf_elements(pE1,"%4d",80); printf("\n"); printf("vector 1 raw:\n"); print_elements(pE1); printf("\n"); free_elements(pE1); }
void test1(void) { ElementNode_handle pE2=0; int i; printf("\n====== INSERTS BACK =============================\n"); for(i=0;i<20;++i) insert_element(&pE2,20-i,i); printf("vector 2 formatted:\n"); printf_elements(pE2,"%4d",20); printf("\n"); printf("vector 2 raw:\n"); print_elements(pE2); printf("\n"); free_elements(pE2); }
void test2(void) { ElementNode_handle pE3=0; int i; printf("\n====== INSERTS MIDDLE =============================\n"); for(i=0;i<20;++i) { if (i%2) insert_element(&pE3,i,i); else insert_element(&pE3,20-i,-i); } printf("vector 3 formatted:\n"); printf_elements(pE3,"%4d",20); printf("\n"); printf("vector 3 raw:\n"); print_elements(pE3); printf("\n"); free_elements(pE3); }
void test3(void) { ElementNode_handle pE2=0; int i; printf("\n====== DELETE FRONT ====================\n"); for(i=0;i<5;++i) insert_element(&pE2,i,i+1); /*no 0s in the list*/ printf("vector 2 formatted:\n"); printf_elements(pE2,"%4d",5); printf("\n"); printf("vector 2 raw:\n"); print_elements(pE2); printf("\n"); delete_element(&pE2,0); printf("vector 2 formatted:\n"); printf_elements(pE2,"%4d",5); printf("\n"); printf("vector 2 raw:\n"); print_elements(pE2); printf("\n"); free_elements(pE2); }
void replace_char(t_it *it, char cmd[2]) { int size; char *tmp2; char *tmp3; char *tmp; int j; j = 0; tmp = ft_memalloc(sizeof(char) * (it->i + 3)); ft_strncpy(tmp, it->line, it->i); tmp[it->i + 1] = '\0'; tmp = ft_strcat(tmp, cmd); tmp3 = copy_end_line(j, it->i, it->line); tmp2 = ft_strjoin(tmp, tmp3); ft_memdel((void**)&it->line); it->line = ft_strdup(tmp2); multi_line_text(it); size = ((it->len + 1) + it->offset) + 1; if (!(size % (it->ws_col))) tputs(tgetstr(RIGHT, NULL), 0, my_putchar); free_elements(tmp, tmp2, tmp3, NULL); }
void test8( void ) { ElementNode * pE1=0, *pE2=0, *pE3=0, *pRes; int i; printf("\n==== VECTOR ADDITION =================\n"); for(i=0;i<20;++i) insert_element(&pE1,i,i*i); printf("vector pE1 formatted:\n"); printf_elements(pE1,"%4d",20); printf("\n"); for(i=0;i<10;++i) insert_element(&pE2,20-2*i,i); printf("vector pE2 formatted:\n"); printf_elements(pE2,"%4d",20); printf("\n"); for(i=0;i<5;++i) { if (i%2) insert_element(&pE3,4*i,i); else insert_element(&pE3,21-4*i,-i); } printf("vector pE3 formatted:\n"); printf_elements(pE3,"%4d",20); printf("\n"); pRes=add(pE1,pE2); printf("pE1 + pE2 = \n"); printf_elements(pRes,"%4d",20); printf("\n"); /* printf("raw:\n"); print_elements(pRes); printf("\n"); */ free_elements(pRes); pRes=add(pE2,pE3); printf("pE2 + pE3 = \n"); printf_elements(pRes,"%4d",20); printf("\n"); /* printf("raw:\n"); print_elements(pRes); printf("\n"); */ free_elements(pRes); pRes=add(pE3,pE1); printf("pE3 + pE1 = \n"); printf_elements(pRes,"%4d",20); printf("\n"); /* printf("raw:\n"); print_elements(pRes); printf("\n"); */ free_elements(pRes); pRes=add(pE1,pE3); printf("pE1 + pE3 = \n"); printf_elements(pRes,"%4d",20); printf("\n"); /* printf("raw:\n"); print_elements(pRes); printf("\n"); */ free_elements(pRes); free_elements(pE1); free_elements(pE2); free_elements(pE3); }
matr_sums::~matr_sums() { delete weights; free_elements(matrices->begin(), matrices->end()); delete matrices; };
void test(const Cont &) { // Testing if all types are provided. typename Cont::value_type t0; typename Cont::reference t1 = t0; CGAL_USE(t1); typename Cont::const_reference t2 = t0; CGAL_USE(t2); typename Cont::pointer t3 = &t0; typename Cont::const_pointer t4 = &t0; CGAL_USE(t4); typename Cont::size_type t5 = 0; CGAL_USE(t5); typename Cont::difference_type t6 = t3-t3; CGAL_USE(t6); typename Cont::iterator t7; CGAL_USE(t7); typename Cont::const_iterator t8; CGAL_USE(t8); typename Cont::reverse_iterator t9; CGAL_USE(t9); typename Cont::const_reverse_iterator t10; CGAL_USE(t10); typename Cont::allocator_type t15; std::cout << "Testing empty containers." << std::endl; Cont c0, c1; Cont c2(t15); Cont c3(c2); Cont c4; c4 = c2; typedef std::vector<typename Cont::value_type> Vect; Vect v0; const Cont c5(v0.begin(), v0.end()); Cont c6(c5.begin(), c5.end()); typename Cont::allocator_type Al; Cont c7(c0.begin(), c0.end(), Al); Cont c8; c8.insert(c0.rbegin(), c0.rend()); // test conversion iterator-> const_iterator. typename Cont::const_iterator t16 = c5.begin(); CGAL_USE(t16); assert(t16 == c5.begin()); assert(c0 == c1); assert(! (c0 < c1)); assert(check_empty(c0)); assert(check_empty(c1)); assert(check_empty(c2)); assert(check_empty(c3)); assert(check_empty(c4)); assert(check_empty(c5)); assert(check_empty(c6)); assert(check_empty(c7)); assert(check_empty(c8)); c1.swap(c0); assert(check_empty(c0)); assert(check_empty(c1)); c1.merge(c0); assert(check_empty(c0)); assert(check_empty(c1)); typename Cont::allocator_type t20 = c0.get_allocator(); std::cout << "Now filling some containers" << std::endl; Vect v1(10000); Cont c9(v1.begin(), v1.end()); assert(c9.size() == v1.size()); assert(c9.max_size() >= v1.size()); assert(c9.capacity() >= c9.size()); Cont c10 = c9; assert(c10 == c9); assert(c10.size() == v1.size()); assert(c10.max_size() >= v1.size()); assert(c10.capacity() >= c10.size()); c9.clear(); assert(check_empty(c9)); assert(c9.capacity() >= c9.size()); assert(c0 == c9); c9.merge(c10); c10.swap(c9); assert(check_empty(c9)); assert(c9.capacity() >= c9.size()); assert(c10.size() == v1.size()); assert(c10.max_size() >= v1.size()); assert(c10.capacity() >= c10.size()); std::cout << "Testing insertion methods" << std::endl; c9.assign(c10.begin(), c10.end()); assert(c9 == c10); c10.assign(c9.begin(), c9.end()); assert(c9 == c10); c9.insert(c10.begin(), c10.end()); assert(c9.size() == 2*v1.size()); c9.clear(); assert(c9 != c10); c9.insert(c10.begin(), c10.end()); assert(c9.size() == v1.size()); assert(c9 == c10); typename Cont::iterator it = c9.iterator_to(*c9.begin()); assert(it == c9.begin()); typename Cont::const_iterator cit = c9.iterator_to(const_cast<typename Cont::const_reference>(*c9.begin())); assert(cit == c9.begin()); typename Cont::iterator s_it = Cont::s_iterator_to(*c9.begin()); assert(s_it == c9.begin()); typename Cont::const_iterator s_cit = Cont::s_iterator_to(const_cast<typename Cont::const_reference>(*c9.begin())); assert(s_cit == c9.begin()); c10 = Cont(); assert(check_empty(c10)); for(typename Vect::const_iterator it = v1.begin(); it != v1.end(); ++it) c10.insert(*it); assert(c10.size() == v1.size()); assert(c9 == c10); c9.erase(c9.begin()); c9.erase(c9.begin()); assert(c9.size() == v1.size() - 2); // test reserve /*Cont c11; c11.reserve(v1.size()); for(typename Vect::const_iterator it = v1.begin(); it != v1.end(); ++it) c11.insert(*it); assert(c11.size() == v1.size()); assert(c10 == c11);*/ // owns() and owns_dereferencable(). for(typename Cont::const_iterator it = c9.begin(), end = c9.end(); it != end; ++it) { assert(c9.owns(it)); assert(c9.owns_dereferencable(it)); assert(! c10.owns(it)); assert(! c10.owns_dereferencable(it)); } assert(c9.owns(c9.end())); assert(! c9.owns_dereferencable(c9.end())); c9.erase(c9.begin(), c9.end()); assert(check_empty(c9)); std::cout << "Testing parallel insertion" << std::endl; { Cont c11; Vect v11(1000000); std::vector<typename Cont::iterator> iterators(v11.size()); tbb::parallel_for( tbb::blocked_range<size_t>( 0, v11.size() ), Insert_in_CCC_functor<Vect, Cont>(v11, c11, iterators) ); assert(c11.size() == v11.size()); std::cout << "Testing parallel erasure" << std::endl; tbb::parallel_for( tbb::blocked_range<size_t>( 0, v11.size() ), Erase_in_CCC_functor<Cont>(c11, iterators) ); assert(c11.empty()); } std::cout << "Testing parallel insertion AND erasure" << std::endl; { Cont c12; Vect v12(1000000); std::vector<tbb::atomic<bool> > free_elements(v12.size()); for(typename std::vector<tbb::atomic<bool> >::iterator it = free_elements.begin(), end = free_elements.end(); it != end; ++it) { *it = true; } tbb::atomic<unsigned int> num_erasures; num_erasures = 0; std::vector<typename Cont::iterator> iterators(v12.size()); tbb::parallel_for( tbb::blocked_range<size_t>( 0, v12.size() ), Insert_and_erase_in_CCC_functor<Vect, Cont>( v12, c12, iterators, free_elements, num_erasures) ); assert(c12.size() == v12.size() - num_erasures); } }