Exemple #1
0
    void variable_intersection::populate_self(const app * a)
    {
        SASSERT(is_uninterp(a));

        //TODO: optimize quadratic complexity
        //TODO: optimize number of checks when variable occurs multiple times
        unsigned arity = a->get_num_args();
        for(unsigned i1=0; i1<arity; i1++) {
            expr * e1=a->get_arg(i1);
            if(is_var(e1)) {
                var* v1=to_var(e1);
                for(unsigned i2=i1+1; i2<arity; i2++) {
                    expr * e2=a->get_arg(i2);
                    if(!is_var(e2)) {
                        continue;
                    }
                    var* v2=to_var(e2);
                    if(v1->get_idx()==v2->get_idx()) {
                        add_pair(i1, i2);
                    }
                }
            }
            else {
                SASSERT(is_app(e1));
                app * c1 = to_app(e1);
                SASSERT(c1->get_num_args()==0); //c1 must be a constant

                m_const_indexes.push_back(i1);
                m_consts.push_back(c1);

                SASSERT(m_const_indexes.size()==m_consts.size());
            }
        }
    }
Exemple #2
0
void StandardEstimator::correlate(ChainingMesh& mesh1, ChainingMesh& mesh2, array& paircount, double vmax) {
    /* Iterate over cells in mesh 1... */
    for(vector<Cell>::iterator c1 = mesh1.cells.begin(); c1 != mesh1.cells.end(); c1++) {
        Particle* p1begin = &mesh1.particles[c1->start];
        Particle* p1end = p1begin + c1->count;
        if(p1begin == p1end)
            continue;

        /* ... and cells in mesh 2 */
        for(vector<Cell>::iterator c2 = mesh2.cells.begin(); c2 != mesh2.cells.end(); c2++) {
            Particle* p2begin = &mesh2.particles[c2->start];
            Particle* p2end = p2begin + c2->count;
            if(p2begin == p2end)
                continue;

            /* Check distance between cells, and compare it to the maximum
             * separation that we actually care about */
            if(cell_separation(*c1, *c2, L, L, inf) > smax + 2*vmax)
                continue;

            /* Correlate particles within these cells */
            for(Particle* p1 = p1begin; p1 < p1end; p1++)
                for(Particle* p2 = p2begin; p2 < p2end; p2++)
                    add_pair(*p1, *p2, paircount);
        }
    }
}
Exemple #3
0
static void
fix_diff_singleton(struct saucy *s, int cf)
{
	int r = s->right.lab[cf];
	int l = s->left.lab[cf];
	int rcfl;

	if (!s->right.clen[cf] && r != l) {

		/* Make sure diff is marked */
		add_diff(s, r);

		/* It is now undiffed since it is singleton */
		++s->nundiffs;
		remove_diffnon(s, r);

		/* Mark the other if not singleton already */
		rcfl = s->right.cfront[l];
		if (s->right.clen[rcfl]) {
			add_diff(s, l);

			/* Check for pairs */
			if (in_cell_range(&s->right, s->left.unlab[r], rcfl)) {
				add_pair(s, l);
			}
		}
		/* Otherwise we might be eating a pair */
		else if (is_a_pair(s, r)) {
			eat_pair(s, r);
		}
	}
}
int main(int argc, char * argv[]){

  pair_t ** pairs = new_pairs(); //create a new pair array

  add_pair(pairs, 2, 10); //assign a new pair
  add_pair(pairs, 0, 3); //assign a new pair
  add_pair(pairs, 13, 7);

  print_pairs(pairs); //print pairs

  rm_pair(pairs, 1); //remove pair at index 1

  printf("------------\n");
  print_pairs(pairs); //print pairs (again)

  delete_pairs(pairs); //delete all pairs, no memleaks!

  return 0;
}
Exemple #5
0
static void tst18() {
    std::cout << "--------------------------------\n";    
    imdd_manager m;
    imdd_ref d1(m), d2(m), d3(m);
    d1 = m.mk_empty(2);
    add_pair(m, d1, 1112, 1290, 1302, 1302);
    std::cout << mk_ll_pp(d1, m) << "\n";
    m.mk_swap(d1, d2, 0);
    std::cout << "mk_swap 0:\n";
    std::cout << mk_ll_pp(d2, m) << "\n";
}
Exemple #6
0
void StandardEstimator::self_correlate(ChainingMesh& mesh, array& paircount, double vmax) {
    /* Iterate over pairs of distinct cells within the ChainingMesh */
    for(vector<Cell>::iterator c1 = mesh.cells.begin(); c1 != mesh.cells.end(); c1++) {
        Particle* p1begin = &mesh.particles[c1->start];
        Particle* p1end = p1begin + c1->count;
        if(p1begin == p1end)
            continue;

        for(vector<Cell>::iterator c2 = c1+1; c2 != mesh.cells.end(); c2++) {
            Particle* p2begin = &mesh.particles[c2->start];
            Particle* p2end = p2begin + c2->count;
            if(p2begin == p2end)
                continue;

            /* Check distance between cells, and compare it to the maximum
             * r that we actually care about */
            if(cell_separation(*c1, *c2, L, L, inf) > smax + 2*vmax)
                continue;

            /* Correlate particles within these cells */
            for(Particle* p1 = p1begin; p1 < p1end; p1++)
                for(Particle* p2 = p2begin; p2 < p2end; p2++)
                    add_pair(*p1, *p2, paircount);
        }
    }

    /* Now count pairs of distinct particles from within the same cell */
    for(vector<Cell>::iterator c = mesh.cells.begin(); c != mesh.cells.end(); c++) {
        Particle* pbegin = &mesh.particles[c->start];
        Particle* pend = pbegin + c->count;
        if(pbegin == pend)
            continue;

        for(Particle* p1 = pbegin; p1 != pend; p1++)
            for(Particle* p2 = p1+1; p2 != pend; p2++)
                add_pair(*p1, *p2, paircount);
    }
}
Exemple #7
0
/**
 * Set name => address hint.
 *
 * Input:  { name, address }
 * Output: { result: bool }
 *
 */
static char* hint_set(void *env, struct kr_module *module, const char *args)
{
	struct kr_zonecut *hints = module->data;
	auto_free char *args_copy = strdup(args);

	int ret = -1;
	char *addr = strchr(args_copy, ' ');
	if (addr) {
		*addr = '\0';
		ret = add_pair(hints, args_copy, addr + 1);
	}

	char *result = NULL;
	asprintf(&result, "{ \"result\": %s", ret == 0 ? "true" : "false");
	return result;
}
Exemple #8
0
/**
 * Get/set root hints set.
 *
 * Input:  { name: [addr_list], ... }
 * Output: current list
 *
 */
static char* hint_root(void *env, struct kr_module *module, const char *args)
{
	struct engine *engine = env;
	struct kr_context *ctx = &engine->resolver;
	/* Replace root hints if parameter is set */
	if (args && strlen(args) > 0) {
		JsonNode *node = NULL;
		JsonNode *root_node = json_decode(args);
		kr_zonecut_set(&ctx->root_hints, (const uint8_t *)"");
		json_foreach(node, root_node) {
			switch(node->tag) {
			case JSON_STRING: add_pair(&ctx->root_hints, node->key, node->string_); break;
			default: continue;
			}
		}
		json_delete(root_node);
	}
Exemple #9
0
int ColInfo::add_joint_pair(Joint* j1, Joint* j2, SceneGraph* sg)
{
    if(Pair(j1, j2)) return 0;
    ColModel* m1, *m2;
    m1 = Model(j1);
    if(!m1)
    {
        m1 = new ColModel(j1, sg);
        add_model(m1);
    }
    m2 = Model(j2);
    if(!m2)
    {
        m2 = new ColModel(j2, sg);
        add_model(m2);
    }
    if(m1->n_triangle == 0 || m2->n_triangle == 0) return -1;
    if( (j1->parent == j2 && j1->n_dof == 0) || (j2->parent == j1 && j2->n_dof == 0) )
        return 0;
    cerr << "add joint pair: " << j1->name << ", " << j2->name << endl;
    ColPair* p = new ColPair(m1, m2);
    add_pair(p);
    return 0;
}
Exemple #10
0
static int load_map(struct kr_zonecut *hints, FILE *fp)
{
	size_t line_len = 0;
	size_t count = 0;
	auto_free char *line = NULL;

	while(getline(&line, &line_len, fp) > 0) {
		char *saveptr = NULL;
		char *tok = strtok_r(line, " \t\r", &saveptr);
		if (tok == NULL || strchr(tok, '#') || strlen(tok) == 0) {
			continue;
		}
		char *name_tok = strtok_r(NULL, " \t\n", &saveptr);
		while (name_tok != NULL) {
			if (add_pair(hints, name_tok, tok) == 0) {
				count += 1;
			}
			name_tok = strtok_r(NULL, " \t\n", &saveptr);
		}
	}

	DEBUG_MSG(NULL, "loaded %zu hints\n", count);
	return kr_ok();
}
Exemple #11
0
void build_verlet_lists()
{
  int c, np1, n, np2, i ,j, j_start;
  Cell *cell;
  IA_Neighbor *neighbor;
  Particle *p1, *p2;
  PairList *pl;
  double dist2;
#ifdef VERLET_DEBUG 
  double max_range_nonbonded2 = SQR(max_cut_nonbonded + skin);

  int estimate, sum=0;
  fprintf(stderr,"%d: build_verlet_list_and_force_calc:\n",this_node);
  /* estimate number of interactions: (0.5*n_part*ia_volume*density)/n_nodes */
  estimate = 0.5*n_part*(4.0/3.0*PI*pow(max_range_nonbonded2,1.5))*(n_part/(box_l[0]*box_l[1]*box_l[2]))/n_nodes;

  if (!dd.use_vList) { fprintf(stderr, "%d: build_verlet_lists, but use_vList == 0\n", this_node); errexit(); }
#endif
  
  /* Loop local cells */
  for (c = 0; c < local_cells.n; c++) {
    VERLET_TRACE(fprintf(stderr,"%d: cell %d with %d neighbors\n",this_node,c, dd.cell_inter[c].n_neighbors));

    cell = local_cells.cell[c];
    p1   = cell->part;
    np1  = cell->n;
    /* Loop cell neighbors */
    for (n = 0; n < dd.cell_inter[c].n_neighbors; n++) {
      neighbor = &dd.cell_inter[c].nList[n];
      p2  = neighbor->pList->part;
      np2 = neighbor->pList->n;
      /* init pair list */
      pl  = &neighbor->vList;
      pl->n = 0;

      /* no interaction set, Verlet list stays empty */
      if (max_cut_nonbonded == 0.0)
        continue;

      /* Loop cell particles */
      for(i=0; i < np1; i++) {
        j_start = 0;
        /* Tasks within cell: store old position, avoid double counting */
        if(n == 0) {
           memcpy(p1[i].l.p_old, p1[i].r.p, 3*sizeof(double));
           j_start = i+1;
        }
        /* Loop neighbor cell particles */
        for(j = j_start; j < np2; j++) {
#ifdef EXCLUSIONS
          if(do_nonbonded(&p1[i], &p2[j]))
#endif
          {
            dist2 = distance2(p1[i].r.p, p2[j].r.p);
            if(dist2 <= SQR(get_ia_param(p1[i].p.type, p2[j].p.type)->max_cut + skin))
              add_pair(pl, &p1[i], &p2[j]);
          }
        }
      }
      resize_verlet_list(pl);
      VERLET_TRACE(fprintf(stderr,"%d: neighbor %d has %d particles\n",this_node,n,pl->n));
      VERLET_TRACE(sum += pl->n);
    }
  }

  rebuild_verletlist = 0;

  VERLET_TRACE(fprintf(stderr,"%d: total number of interaction pairs: %d (should be around %d)\n",this_node,sum,estimate));
}
Exemple #12
0
void build_verlet_lists_and_calc_verlet_ia()
{
  int c, np1, n, np2, i ,j, j_start;
  Cell *cell;
  IA_Neighbor *neighbor;
  Particle *p1, *p2;
  PairList *pl;
  double dist2, vec21[3];
 
#ifdef VERLET_DEBUG 
  int estimate, sum=0;
  double max_range_nonbonded2 = SQR(max_cut_nonbonded + skin);

  fprintf(stderr,"%d: build_verlet_list_and_calc_verlet_ia:\n",this_node);
  /* estimate number of interactions: (0.5*n_part*ia_volume*density)/n_nodes */
  estimate = 0.5*n_part*(4.0/3.0*PI*pow(max_range_nonbonded2,1.5))*(n_part/(box_l[0]*box_l[1]*box_l[2]))/n_nodes;

  if (!dd.use_vList) { fprintf(stderr, "%d: build_verlet_lists, but use_vList == 0\n", this_node); errexit(); }
#endif
 
  /* Loop local cells */
  for (c = 0; c < local_cells.n; c++) {
    VERLET_TRACE(fprintf(stderr,"%d: cell %d with %d neighbors\n",this_node,c, dd.cell_inter[c].n_neighbors));

    cell = local_cells.cell[c];
    p1   = cell->part;
    np1  = cell->n;
    
    /* Loop cell neighbors */
    for (n = 0; n < dd.cell_inter[c].n_neighbors; n++) {
      neighbor = &dd.cell_inter[c].nList[n];
      p2  = neighbor->pList->part;
      np2 = neighbor->pList->n;
      VERLET_TRACE(fprintf(stderr,"%d: neighbor %d contains %d parts\n",this_node,n,np2));
      /* init pair list */
      pl  = &neighbor->vList;
      pl->n = 0;
      /* Loop cell particles */
      for(i=0; i < np1; i++) {
        j_start = 0;
        /* Tasks within cell: bonded forces, store old position, avoid double counting */
        if(n == 0) {
#ifdef MULTI_TIMESTEP
          if (p1[i].p.smaller_timestep==current_time_step_is_small || smaller_time_step < 0.)
#endif
          {
            add_bonded_force(&p1[i]);
#ifdef CONSTRAINTS
            add_constraints_forces(&p1[i]);
#endif
            add_external_potential_forces(&p1[i]);
            memcpy(p1[i].l.p_old, p1[i].r.p, 3*sizeof(double));
            j_start = i+1;
          }
        }
        
        /* no interaction set, no need for particle pairs */
        if (max_cut_nonbonded == 0.0)
          continue;

        /* Loop neighbor cell particles */
        for(j = j_start; j < np2; j++) {
#ifdef EXCLUSIONS
          if(do_nonbonded(&p1[i], &p2[j]))
#endif
          {
          dist2 = distance2vec(p1[i].r.p, p2[j].r.p, vec21);

          VERLET_TRACE(fprintf(stderr,"%d: pair %d %d has distance %f\n",this_node,p1[i].p.identity,p2[j].p.identity,sqrt(dist2)));

          if(dist2 <= SQR(get_ia_param(p1[i].p.type, p2[j].p.type)->max_cut + skin)) {
            ONEPART_TRACE(if(p1[i].p.identity==check_id) fprintf(stderr,"%d: OPT: Verlet Pair %d %d (Cells %d,%d %d,%d dist %f)\n",this_node,p1[i].p.identity,p2[j].p.identity,c,i,n,j,sqrt(dist2)));
            ONEPART_TRACE(if(p2[j].p.identity==check_id) fprintf(stderr,"%d: OPT: Verlet Pair %d %d (Cells %d %d dist %f)\n",this_node,p1[i].p.identity,p2[j].p.identity,c,n,sqrt(dist2)));
            add_pair(pl, &p1[i], &p2[j]);
#ifdef MULTI_TIMESTEP
      if (smaller_time_step < 0.
        || (p1[i].p.smaller_timestep==0 && p2[j].p.smaller_timestep==0 && current_time_step_is_small==0)
        || (!(p1[i].p.smaller_timestep==0 && p2[j].p.smaller_timestep==0) && current_time_step_is_small==1))
#endif      
      {
              /* calc non bonded interactions */
              add_non_bonded_pair_force(&(p1[i]), &(p2[j]), vec21, sqrt(dist2), dist2);
      }
          }
         }
        }
      }
      resize_verlet_list(pl);
      VERLET_TRACE(fprintf(stderr,"%d: neighbor %d has %d pairs\n",this_node,n,pl->n));
      VERLET_TRACE(sum += pl->n);
    }
Exemple #13
0
struct ini_file *ini_parse(const char *text, int *err, int *line) {
	jmp_buf on_error;
	int e_code;
	
	struct ini_file *ini = NULL;
	ini_section *cur_sec = NULL;
	
	const char *tstart, *tend;
	
	int t;
	
	if(err) *err = SUCCESS;
	if(line) *line = 1;
	
	ini = make_ini();
	
	if((e_code = setjmp(on_error)) != 0) {
		if(err) *err = e_code;
		ini_free(ini);
		return NULL;
	}
	
	while((t = get_token(&text, &tstart, &tend, line, on_error)) != T_END) {
		if(t == '[') {
			char *section_name;
			if(get_token(&text, &tstart, &tend, line, on_error) != T_VALUE) {
				longjmp(on_error, EMPTY_SECTION);				
			}
			
			section_name = get_string(tstart, tend, on_error);
			
			cur_sec = add_section(&ini->sections, section_name);
			if(!cur_sec)
				longjmp(on_error, OUT_OF_MEMORY);
			
			if(get_token(&text, &tstart, &tend, line, on_error) != ']') {
				longjmp(on_error, MISSING_END_BRACE);				
			}
			
		} else if (t == T_VALUE ) {
			char *par, *val;
			par = get_string(tstart, tend, on_error);
			t = get_token(&text, &tstart, &tend, line, on_error);
			if(t != '=' && t != ':') {
				longjmp(on_error, EXPECTED_EQUALS);				
			}
			if(get_token(&text, &tstart, &tend, line, on_error) != T_VALUE) {
				longjmp(on_error, EXPECTED_VALUE);
			}
			val = get_string(tstart, tend, on_error);
			
			if(cur_sec)
				add_pair(cur_sec, par, val);
			else {
				/* Add the parameter and value to the INI file's globals */
				ini_pair *pair;
				if(!(pair = malloc(sizeof *pair)))
					longjmp(on_error, OUT_OF_MEMORY);
				
				pair->param = par;
				pair->value = val;
				
				pair->left = pair->right = NULL;
					
				if(!ini->globals)
					ini->globals = pair;
				else
					insert_pair(ini->globals, pair);
			}
			
			
		} else 
			longjmp(on_error, EXPECTED_PARAMETER);
	}
	
	return ini;
}
Exemple #14
0
/* ----------------------------------------------------------------------------
FUNCTION

Name:   Open

Prototype:  struct confread_file* confread_open(char* path)

Developer:	Andrew Burian

Created On:	2015-03-07

Parameters:
  char* path
    file path to the conf file to read

Return Values:
  struct confread_file*
    the newly creaded confread file
    null on failure

Description:
  Parses the given config file and loads it into the data structure for
  processing

Revisions:
  (none)

---------------------------------------------------------------------------- */
struct confread_file* confread_open(char* path){

  // the actual configuration file
  FILE* confDataFile = 0;

  // temp pointers
  struct confread_file* confFile = 0;
  struct confread_section* thisSection = 0;

  // the line from the conf file
  char* line = 0;
  size_t lineLen = 0;

  // other char pointers for manipulation of the line
  char* lineStart = 0;
  char* lineEnd = 0;
  char* keyStart = 0;
  char* keyEnd = 0;

  // open the data file
  if(!(confDataFile = fopen(path, "r"))){
    return 0;
  }

  // create the conf file
  confFile = malloc(sizeof(struct confread_file));
  confFile->count = 0;
  confFile->name = malloc(strlen(path) + 1);
  confFile->sections = 0;
  memcpy(confFile->name, path, strlen(path) + 1);

  // add the 'root section'
  thisSection = add_section(confFile, "root");

  // Read the file line by line until EOF
  while(getline(&line, &lineLen, confDataFile) != -1){

    // seek forward to the first non-space character
    for(lineStart = line; *lineStart != 0; ++lineStart){
      if(!isspace(*lineStart)){
        break;
      }
    }

    // omit if empty
    if(*lineStart == 0){
      continue;
    }

    // omit if comment '#'
    if(*lineStart == '#'){
      continue;
    }

    // see if this is a section header
    if(*lineStart == '['){

      // move lineStart off the header start
      ++lineStart;


      // seek forward to the end of the header ']'
      for(lineEnd = lineStart; *lineEnd != 0; ++lineEnd){
        if(*lineEnd == ']'){
          break;
        }
      }

      // if it's anything other than the end of header, invalid line
      if(*lineEnd != ']'){
        continue;
      }

      // seek linestart forward to trim whitespace
      for(lineStart = lineStart; lineStart != lineEnd; ++lineStart){
        if(!isspace(*lineStart)){
          break;
        }
      }

      // omit zero size headers
      if(lineStart == lineEnd){
        continue;
      }

      // seek line end back to trim whitespace
      for(lineEnd = lineEnd - 1; lineEnd != lineStart; --lineEnd){
        if(!isspace(*lineEnd)){
          break;
        }
      }

      // set next char as null
      lineEnd[1] = 0;

      // create the new section
      thisSection = add_section(confFile, lineStart);

      continue;
    }

    // otherwise, key-value
    else{

      // seek line end forward to the separator '='
      for(lineEnd = lineStart; *lineEnd != 0; ++lineEnd){
        if(*lineEnd == '='){
          break;
        }
      }

      // discard if invalid
      if(*lineEnd != '='){
        continue;
      }

      // if key is zero length, discard
      if(lineEnd == lineStart){
        continue;
      }

      // set the key start
      keyStart = lineEnd + 1;

      // seek the line end backwards to trim whitespace
      for(lineEnd = lineEnd - 1; lineEnd != lineStart; --lineEnd){
        if(!isspace(*lineEnd)){
          break;
        }
      }

      // set the following char to null
      lineEnd[1] = 0;

      // seek the key end forward to the end of the line
      for(keyEnd = keyStart; *keyEnd != 0; ++keyEnd){
        if(*keyEnd == '\n'){
          break;
        }
      }

      // if the key is zero length, discard
      if(keyEnd == keyStart){
        continue;
      }

      // seek key end backwards to trim trailing whitespace
      for(keyEnd = keyEnd; keyEnd != keyStart; --keyEnd){
        if(!isspace(*keyEnd)){
          break;
        }
      }

      // seek the key start forward to trim leading whitespace
      for(keyStart = keyStart; keyStart != keyEnd; ++keyStart){
        if(!isspace(*keyStart)){
          break;
        }
      }

      // set the new line char to null
      keyEnd[1] = 0;

      // add the key-value pair
      add_pair(thisSection, lineStart, keyStart);

    }
  }

  free(line);
  fclose(confDataFile);

  return confFile;

}
Exemple #15
0
sink_line_res sink_line(config *cfg, data_set *ds, char *line, size_t len, size_t row_count) {
    size_t col = 0;

    if (len == 0) { return SINK_LINE_EMPTY; }
    if (line[len - 1] == '\n') { line[len - 1] = '\0'; len--; }
    if (*line == '\0') { return SINK_LINE_EMPTY; }
    LOG(3, "sink_line: %s\n", line);
    
    float cur_x = row_count;
    bool has_x = false;

    // ignore comments
    if (is_comment_marker(line[0])) { return SINK_LINE_COMMENT; }

    size_t offset = 0;
    while (offset < len && line[offset]) {
        double v = 0;
        if (offset >= len) { break; }

        // ignore comment to EOL
        if (is_comment_marker(line[offset])) { return SINK_LINE_OK; }

        if (!number_head_char(line[offset])) {
            if (offset == 0) {
                v = EMPTY_VALUE;
            } else {
                offset++;
                if (!number_head_char(line[offset])) {
                    v = EMPTY_VALUE;
                }
            }
        }

        char *cur_line = &line[offset];
        char *out_line = NULL;
        if (isnan(v)) {
            offset++;   // already got the value
        } else {
            v = strtod(cur_line, &out_line);
            if (isinf(v)) { v = EMPTY_VALUE; }
        }
        if (out_line == cur_line) {
            break;
        } else {
            // could do this in terms of *line == '\0' or line[offset] == len.
            // strtod shifts &line.
            while(&line[offset] < out_line) {
                offset++;
            }
        }

        if (cfg->x_column && !has_x) {
            cur_x = v;
            has_x = true;
        } else {
            point p = { .x = cur_x, .y = v };
            add_pair(cfg, ds, row_count, col, &p);
            col++;
            if (col == MAX_COLUMNS) { break; }
        }
    }

    // Fill remaining columns with EMPTY_VALUE
    for (size_t c = col; c < ds->columns; c++) {
        point p = { .x = cur_x, .y = EMPTY_VALUE };
        add_pair(cfg, ds, row_count, c, &p);
    }

    return SINK_LINE_OK;
}
Exemple #16
0
void IOUniformer::redirect(const char *orig_path, const char *new_path) {
    LOGI("Start redirect : from %s to %s", orig_path, new_path);
    add_pair(orig_path, new_path);
}
Exemple #17
0
void PixmanBitmap::initialize_formats() {
	if (formats_initialized)
		return;

	add_pair(PIXMAN_a8r8g8b8, DynamicFormat(32,8,16,8,8,8,0,8,24,PF::Alpha));
	add_pair(PIXMAN_x8r8g8b8, DynamicFormat(32,8,16,8,8,8,0,0,0,PF::NoAlpha));
	add_pair(PIXMAN_a8b8g8r8, DynamicFormat(32,8,0,8,8,8,16,8,24,PF::Alpha));
	add_pair(PIXMAN_x8b8g8r8, DynamicFormat(32,8,0,8,8,8,16,0,0,PF::NoAlpha));
	add_pair(PIXMAN_b8g8r8a8, DynamicFormat(32,8,8,8,16,8,24,8,0,PF::Alpha));
	add_pair(PIXMAN_b8g8r8x8, DynamicFormat(32,8,8,8,16,8,24,0,0,PF::NoAlpha));

	add_pair(PIXMAN_x14r6g6b6, DynamicFormat(32,6,12,6,6,6,0,0,0,PF::NoAlpha));
	add_pair(PIXMAN_x2r10g10b10, DynamicFormat(32,10,20,10,10,10,0,0,0,PF::NoAlpha));
	add_pair(PIXMAN_a2r10g10b10, DynamicFormat(32,10,20,10,10,10,0,2,30,PF::Alpha));
	add_pair(PIXMAN_x2b10g10r10, DynamicFormat(32,10,0,10,10,10,20,0,0,PF::NoAlpha));
	add_pair(PIXMAN_a2b10g10r10, DynamicFormat(32,10,0,10,10,10,20,2,30,PF::Alpha));

	add_pair(PIXMAN_r8g8b8, DynamicFormat(24,8,16,8,8,8,0,0,0,PF::NoAlpha));
	add_pair(PIXMAN_b8g8r8, DynamicFormat(24,8,0,8,8,8,16,0,0,PF::NoAlpha));

	add_pair(PIXMAN_r5g6b5, DynamicFormat(16,5,11,6,5,5,0,0,0,PF::NoAlpha));
	add_pair(PIXMAN_b5g6r5, DynamicFormat(16,5,0,6,5,5,11,0,0,PF::NoAlpha));
	add_pair(PIXMAN_a1r5g5b5, DynamicFormat(16,5,10,5,5,5,0,1,15,PF::Alpha));
	add_pair(PIXMAN_x1r5g5b5, DynamicFormat(16,5,10,5,5,5,0,0,0,PF::NoAlpha));
	add_pair(PIXMAN_a1b5g5r5, DynamicFormat(16,5,0,5,5,5,10,1,15,PF::Alpha));
	add_pair(PIXMAN_x1b5g5r5, DynamicFormat(16,5,0,5,5,5,10,0,0,PF::NoAlpha));
	add_pair(PIXMAN_a4r4g4b4, DynamicFormat(16,4,8,4,4,4,0,4,12,PF::Alpha));
	add_pair(PIXMAN_x4r4g4b4, DynamicFormat(16,4,8,4,4,4,0,0,0,PF::NoAlpha));
	add_pair(PIXMAN_a4b4g4r4, DynamicFormat(16,4,0,4,4,4,8,4,12,PF::Alpha));
	add_pair(PIXMAN_x4b4g4r4, DynamicFormat(16,4,0,4,4,4,8,0,0,PF::NoAlpha));
	add_pair(PIXMAN_g8, DynamicFormat(8,8,0,8,0,8,0,8,0,PF::Alpha));
	add_pair(PIXMAN_g8, DynamicFormat(8,8,0,8,0,8,0,0,0,PF::NoAlpha));

	formats_initialized = true;
}