Example #1
0
ring_elem RingZZ::remainderAndQuotient(const ring_elem f, const ring_elem g,
                                  ring_elem &quot) const
{
  mpz_ptr q = new_elem();
  mpz_ptr r = new_elem();
  int gsign = mpz_sgn(g.get_mpz());
  mpz_t gg, ghalf;
  mpz_init(gg);
  mpz_init(ghalf);
  mpz_abs(gg,g.get_mpz());
  mpz_fdiv_qr(q, r, f.get_mpz(), gg);
  mpz_tdiv_q_2exp(ghalf, gg, 1);
  if (mpz_cmp(r,ghalf) > 0)  // r > ghalf
    {
      mpz_sub(r,r,gg);
      mpz_add_ui(q,q,1);
    }
  if (gsign < 0)
    mpz_neg(q,q);

  mpz_clear(gg);
  mpz_clear(ghalf);
  quot = ring_elem(q);
  return ring_elem(r);
}
Example #2
0
void					ft_ls(t_node *dir, int flags)
{
	DIR					*directory;
	struct dirent		*file;
	t_node				*dirs;
	t_node				*files;

	dirs = new_elem(FORBIDDEN_FILE, FORBIDDEN_FILE, 0);
	files = new_elem(FORBIDDEN_FILE, FORBIDDEN_FILE, 0);
	if ((!is_dir(dir->path, flags)))
	{
		render_file(dir, flags, NULL);
		return ;
	}
	if ((directory = opendir(dir->path)) == NULL)
	{
		perror("Error");
		return ;
	}
	while ((file = readdir(directory)) > 0 && (PUSH(files, file)) != NULL)
		if (ISADIR(file) && !IS(file->d_name, ".") &&
				!IS(file->d_name, "..") && RR_ON)
			PUSH(dirs, file);
	files = files->next;
	dirs = dirs->next;
	if ((ISHIDDEN(dir) && A_ON) || !ISHIDDEN(dir) || dir->first == TRUE)
		render_list(files, flags);
	free(files);
	closedir(directory);
	if (RR_ON)
		ft_ls_relaunch(dirs, flags);
	free(dirs);
}
Example #3
0
ring_elem RingZZ::gcd_extended(const ring_elem f, const ring_elem g,
                            ring_elem &u, ring_elem &v) const
{
  mpz_ptr result = new_elem();
  mpz_ptr u1 = new_elem();
  mpz_ptr v1 = new_elem();
  mpz_gcdext(result, u1, v1, f.get_mpz(), g.get_mpz());
  u = ring_elem(u1);
  v = ring_elem(v1);
  return ring_elem(result);
}
Example #4
0
static inline fb_include_t *fb_add_include(fb_parser_t *P)
{
    fb_include_t *p;
    p = new_elem(P, sizeof(*p));
    p->link = P->schema.includes;
    return P->schema.includes = p;
}
Example #5
0
    }END_TEST

START_TEST (test_add_more)
    {
        p_minheap m = minheap_init( 5 );

        ck_assert_int_eq( 0, m->count );
        ck_assert_int_eq( 5, m->alloc );

        for( int i = 0; i < 20; i++ ) {
            elem_t e = new_elem( i, i, i );
            minheap_add( m, &e );
        }

        minheap_sort( m );

        ck_assert_int_eq( 5, m->count );
        ck_assert_int_eq( 5, m->alloc );

        ck_assert_int_eq( 19, m->array[0].score );
        ck_assert_int_eq( 19, m->array[0].query_id );
        ck_assert_int_eq( 19, m->array[0].db_id );

        ck_assert_int_eq( 18, m->array[1].score );
        ck_assert_int_eq( 17, m->array[2].score );
        ck_assert_int_eq( 16, m->array[3].score );
        ck_assert_int_eq( 15, m->array[4].score );

        minheap_exit( m );
    }END_TEST
static t_splitlist		*load_list(char *str, char c)
{
	t_splitlist		*list[2];
	int				nb[3];

	list[1] = NULL;
	nb[0] = 0;
	while (str && str[nb[0]])
	{
		if (str[nb[0]] == c)
			nb[0]++;
		else
		{
			list[0] = list[1];
			nb[1] = nb[0];
			nb[2] = 0;
			while (str[nb[0]] && str[nb[0]] != c)
			{
				nb[0]++;
				nb[2]++;
			}
			list[1] = new_elem(list[0], nb[1], nb[2]);
			if (list[0] != NULL)
				list[0]->next = list[1];
		}
	}
	return (list[1]);
}
Example #7
0
File: ZZ.cpp Project: DanGrayson/M2
ring_elem RingZZ::from_long(long n) const
{
  mpz_ptr result = new_elem();
  mpz_set_si(result, n);

  return ring_elem(result);
}
Example #8
0
char			append_buffer(struct s_buffers **head, char *buffer)
{
  struct s_buffers	*tmp;

  if (*head == 0)
    {
      *head = new_elem(buffer);
      return (1);
    }
  tmp = *head;
  while (tmp->next != 0)
    tmp = tmp->next;
  tmp->next = new_elem(buffer);
  (*head)->nbr_elems++;
  return (1);
}
Example #9
0
static inline fb_metadata_t *fb_add_metadata(fb_parser_t *P, fb_metadata_t **metadata)
{
    fb_metadata_t *p;
    p = new_elem(P, sizeof(*p));
    p->link = *metadata;
    return *metadata = p;
}
Example #10
0
ring_elem RingZZ::from_int(mpz_ptr n) const
{
  mpz_ptr result = new_elem();
  mpz_set(result, n);

  return ring_elem(result);
}
Example #11
0
static inline fb_ref_t *fb_add_ref(fb_parser_t *P, fb_token_t *t)
{
    fb_ref_t *p;

    p = new_elem(P, sizeof(*p));
    p->ident = t;
    return p;
}
struct elem * ins(struct elem *const e, const KEY_T key) {
	int b;
	if (!e) return new_elem(key);
	if (e->key == key) return e;
	if (key < e->key) e->left = ins(e->left, key); else e->right = ins(e->right, key);
	update(e), b = balance_factor(e);
	return b > 1 && key < e->left->key ? zig(e) : b > 1 && key > e->left->key ? (e->left = zag(e->left), zig(e)) : b < -1 && key > e->right->key ? zag(e) : b < -1 && key < e->right->key ? (e->right = zig(e->right), zag(e)) : e;
}
Example #13
0
ring_elem RingZZ::copy(const ring_elem f) const
{
  mpz_ptr a = f.get_mpz();

  mpz_ptr result = new_elem();
  mpz_set(result, a);
  return ring_elem(result);
}
Example #14
0
File: gram.c Project: PDelak/intent
Elem *
new_elem_nterm(Production *p, Rule *r) {
  Elem *e = new_elem();
  e->kind = ELEM_NTERM;
  e->e.nterm = p;
  e->rule = r;
  return e;
}
Example #15
0
static inline fb_attribute_t *fb_add_attribute(fb_parser_t *P)
{
    fb_attribute_t *p;

    p = new_elem(P, sizeof(*p));
    p->name.link = P->schema.attributes;
    P->schema.attributes = &p->name;
    return p;
}
Example #16
0
File: gram.c Project: PDelak/intent
static Elem *
new_elem_term(Term *t, Rule *r) {
  Elem *e = new_elem();
  e->kind = ELEM_TERM;
  e->e.term = t;
  e->rule = r;
  vec_add(&r->elems, e);
  return e;
}
Example #17
0
ring_elem RingZZ::power(const ring_elem f, mpz_t n) const
{
  mpz_ptr result = new_elem();
  int n1;
  if (!get_si(n1, n))
    { ERROR("exponent too large"); }
  else
    mpz_pow_ui(result, f.get_mpz(), n1);
  return ring_elem(result);
}
Example #18
0
static inline fb_doc_t *fb_add_doc(fb_parser_t *P, fb_token_t *t)
{
    fb_doc_t *p;

    p = new_elem(P, sizeof(*p));
    p->ident = t;
    p->link = P->doc;
    P->doc = p;
    return p;
}
Example #19
0
static inline fb_member_t *fb_add_member(fb_parser_t *P, fb_symbol_t **members)
{
    fb_member_t *p;
    p = new_elem(P, sizeof(*p));
    p->symbol.link = *members;
    p->symbol.kind = fb_is_member;
    *members = (fb_symbol_t *)p;
    fb_assign_doc(P, p);
    return p;
}
Example #20
0
File: gram.c Project: PDelak/intent
Rule *
new_rule(Grammar *g, Production *p) {
  Rule *r = reinterpret_cast<Rule*>(MALLOC(sizeof(Rule)));
  memset(r, 0, sizeof(Rule));
  r->prod = p;
  r->end = new_elem();
  r->end->kind = ELEM_END;
  r->end->rule = r;
  r->action_index = g->action_index;
  return r;
}
Example #21
0
static inline fb_compound_type_t *fb_add_union(fb_parser_t *P)
{
    fb_compound_type_t *p;

    p = new_elem(P, sizeof(*p));
    p->symbol.link = P->schema.symbols;
    p->symbol.kind = fb_is_union;
    P->schema.symbols = &p->symbol;
    p->scope = P->current_scope;
    fb_assign_doc(P, p);
    return p;
}
    std::size_t SoundManager::createBuffer(const std::string &filename) {
        sf::SoundBuffer buffer;
        if (buffer.loadFromFile(filename)) {
            std::pair<std::size_t, sf::SoundBuffer> new_elem(id_gen_base, buffer);

            sound_buffers.insert(new_elem);
            return id_gen_base++;
        }
        else {
            throw std::runtime_error("File missing or could not open: " + filename);
        }
    }
Example #23
0
void insert(hash_table_t table, app_pc addr, cbr_state_t state)
{
    elem_t *elem = new_elem(addr, state);

    uint index = hash_func(addr);
    list_t *list = table[index];
    if (list == NULL) {
        list = new_list();
        table[index] = list;
    }

    append_elem(list, elem);
}
Example #24
0
bool md_add_module(module_t * head, char * name, uint length_list_bbs){

	module_t * tail;

	if (md_lookup_module(head, name) == NULL){
		tail = get_tail(head);
		tail->next = new_elem(name, length_list_bbs);
		return true;
	}

	return false;


}
GroupPtr ServerConnection::addGroupAsyncIO2( const String& group_name )
{
	FRL_EXCEPT_GUARD();
	boost::mutex::scoped_lock guard( scope_guard );
	checkIsConnect();
	GroupList::iterator it = group_list.find( group_name );
	if( it != group_list.end() )
		FRL_THROW_S_CLASS( GroupAlreadyExist );
	AsyncIO2Group *new_gr = new AsyncIO2Group( group_name, server );
	new_gr->create();
	GroupPtr new_group( new_gr );
	GroupElemPair new_elem( group_name, new_group );
	group_list.insert( new_elem );
	return new_group; 
}
Example #26
0
bool QQ::initialize_QQ()
{
  initialize_ring(0);
  _elem_size = sizeof(mpq_t);
  _zero_elem = new_elem();// this sets the element to 0.
#if 0
//   trans_one = globalZZ->from_int(1);
#endif
  declare_field();
  zeroV = from_int(0);
  oneV = from_int(1);
  minus_oneV = from_int(-1);

  return true;
}
Example #27
0
bool RingZZ::initialize_ZZ(const PolynomialRing *deg_ring)
{
  initialize_ring(0);
  _elem_size = sizeof(mpz_t);
  _zero_elem = new_elem();
  mpz_init_set_si(_zero_elem, 0);

  zeroV = from_int(0);
  oneV = from_int(1);
  minus_oneV = from_int(-1);

  degree_ring = deg_ring;
  coeffR = new CoefficientRingZZ_NTL(this);
  return true;
}
Example #28
0
static inline fb_scope_t *fb_add_scope(fb_parser_t *P, fb_ref_t *name)
{
    fb_scope_t *p;

    p = fb_scope_table_find(&P->schema.root_schema->scope_index, name, 0);
    if (p) {
        return p;
    }
    p = new_elem(P, sizeof(*p));
    p->name = name;
    p->prefix = P->schema.prefix;

    fb_scope_table_insert_item(&P->schema.root_schema->scope_index, p, ht_keep);
    return p;
}
Example #29
0
/*
 * return valid elem_t pointer
 * return NULL : Failed to process or invalid input.
 * a pointer to array of sorted number in increasing order 
 * Range of number : range, must be greater than 0.
 */
elem_t *compress (int *a, int range) {
  int     begin  = 0;
  elem_t *elem_p = NULL;
  elem_t *prev   = NULL;
  elem_t *head;

  if (range <= 0){
    return NULL;
  }
 
  for (int i = 0; i < range; i++) {

    elem_p        = new_elem();
    elem_p->start = a[i];
    if(i+1 >= range) {
      elem_p->diff =0;
      elem_p->end = a[i];
      if(prev) {
	prev->next  = elem_p;
      } else {
	head = elem_p;
      }
      break;
    }
    elem_p->diff  = a[i+1] - a[i];

    //Find end of sequence with same difference
    while (i < (range-1) && elem_p->diff == (a[i+1] - a[i])) {
      printf("Debug: compressing  a[%d]= %d, a[%d]= %d, diff is %d\n", 
	     i, a[i], i+1, a[i+1], a[i+1]-a[i]);
      i++;
      if (i >= range) {
	printf("breaking i=%d, range =%d\n", i, range);
	break;
      }
    }
    elem_p->end = a[i];
    if (prev) {
      prev->next = elem_p;
    } else {
      head = elem_p;
    }
    prev   = elem_p;
    elem_p = NULL;
  }//End of Begin
  return head;
}
Example #30
0
/* important assumes that the head is not null - therefore, the user should initialize the head */
bbinfo_t * md_add_bb_to_module(module_t * head,
								char * name,
								unsigned int addr,
								unsigned int length_list_bbs,
								bool extra_info){

	module_t * module = md_lookup_module(head,name);
	module_t * new_module;
	if(module != NULL){
		return add_bb_to_list(module->bbs,addr,extra_info, module->size_bbs);
	}
	else{
		module = get_tail (head);
		new_module = new_elem(name,length_list_bbs);
		module->next = new_module;
		return add_bb_to_list(new_module->bbs,addr,extra_info,new_module->size_bbs);
	}
}