Back to index

cell-binutils  2.17cvs20070401
Classes | Defines | Typedefs | Functions
partition.h File Reference
#include "ansidecl.h"
#include <stdio.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  partition_elem
struct  partition_def

Defines

#define partition_find(partition__, element__)   ((partition__)->elements[(element__)].class_element)

Typedefs

typedef struct partition_defpartition

Functions

partition partition_new (int)
void partition_delete (partition)
int partition_union (partition, int, int)
void partition_print (partition, FILE *)

Class Documentation

struct partition_elem

Definition at line 46 of file partition.h.

Collaboration diagram for partition_elem:
Class Members
unsigned class_count
int class_element
struct partition_elem * next
struct partition_def

Definition at line 59 of file partition.h.

Class Members
int num_elements

Define Documentation

#define partition_find (   partition__,
  element__ 
)    ((partition__)->elements[(element__)].class_element)

Definition at line 75 of file partition.h.


Typedef Documentation


Function Documentation

Definition at line 64 of file partition.c.

{
  free (part);
}

Here is the call graph for this function:

Definition at line 43 of file partition.c.

{
  int e;
  
  partition part = (partition) 
    xmalloc (sizeof (struct partition_def) + 
            (num_elements - 1) * sizeof (struct partition_elem));
  part->num_elements = num_elements;
  for (e = 0; e < num_elements; ++e) 
    {
      part->elements[e].class_element = e;
      part->elements[e].next = &(part->elements[e]);
      part->elements[e].class_count = 1;
    }

  return part;
}

Here is the call graph for this function:

void partition_print ( partition  ,
FILE *   
)

Definition at line 140 of file partition.c.

{
  char *done;
  int num_elements = part->num_elements;
  struct partition_elem *elements = part->elements;
  int *class_elements;
  int e;

  /* Flag the elements we've already printed.  */
  done = (char *) xmalloc (num_elements);
  memset (done, 0, num_elements);

  /* A buffer used to sort elements in a class.  */
  class_elements = (int *) xmalloc (num_elements * sizeof (int));

  fputc ('[', fp);
  for (e = 0; e < num_elements; ++e)
    /* If we haven't printed this element, print its entire class.  */
    if (! done[e]) 
      {
       int c = e;
       int count = elements[elements[e].class_element].class_count;
       int i;

      /* Collect the elements in this class.  */
       for (i = 0; i < count; ++i) {
         class_elements[i] = c;
         done[c] = 1;
         c = elements[c].next - elements;
       }
       /* Sort them.  */
       qsort ((void *) class_elements, count, sizeof (int), elem_compare);
       /* Print them.  */
       fputc ('(', fp);
       for (i = 0; i < count; ++i) 
         fprintf (fp, i == 0 ? "%d" : " %d", class_elements[i]);
       fputc (')', fp);
      }
  fputc (']', fp);

  free (class_elements);
  free (done);
}

Here is the call graph for this function:

int partition_union ( partition  ,
int  ,
int   
)

Definition at line 75 of file partition.c.

{
  struct partition_elem *elements = part->elements;
  struct partition_elem *e1;
  struct partition_elem *e2;
  struct partition_elem *p;
  struct partition_elem *old_next;
  /* The canonical element of the resulting union class.  */
  int class_element = elements[elem1].class_element;

  /* If they're already in the same class, do nothing.  */
  if (class_element == elements[elem2].class_element)
    return class_element;

  /* Make sure ELEM1 is in the larger class of the two.  If not, swap
     them.  This way we always scan the shorter list.  */
  if (elements[elem1].class_count < elements[elem2].class_count) 
    {
      int temp = elem1;
      elem1 = elem2;
      elem2 = temp;
      class_element = elements[elem1].class_element;
    }

  e1 = &(elements[elem1]);
  e2 = &(elements[elem2]);

  /* Keep a count of the number of elements in the list.  */
  elements[class_element].class_count 
    += elements[e2->class_element].class_count;

  /* Update the class fields in elem2's class list.  */
  e2->class_element = class_element;
  for (p = e2->next; p != e2; p = p->next)
    p->class_element = class_element;
  
  /* Splice ELEM2's class list into ELEM1's.  These are circular
     lists.  */
  old_next = e1->next;
  e1->next = e2->next;
  e2->next = old_next;

  return class_element;
}

Here is the call graph for this function: