[BACK]Return to tsort.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tsort

Diff for /src/usr.bin/tsort/tsort.c between version 1.13 and 1.14

version 1.13, 2002/02/17 19:42:33 version 1.14, 2002/02/27 20:26:37
Line 179 
Line 179 
  ***/   ***/
   
 static void *  static void *
 emem(p)  emem(void *p)
         void            *p;  
 {  {
         if (p)          if (p)
                 return p;                  return p;
Line 189 
Line 188 
 }  }
   
 static void *  static void *
 hash_alloc(s, u)  hash_alloc(size_t s, void *u UNUSED)
         size_t s;  
         void *u         UNUSED;  
 {  {
         return emem(calloc(s, 1));          return emem(calloc(s, 1));
 }  }
   
 static void  static void
 hash_free(p, s, u)  hash_free(void *p, size_t s UNUSED, void *u UNUSED)
         void *p;  
         size_t s        UNUSED;  
         void *u         UNUSED;  
 {  {
         free(p);          free(p);
 }  }
   
 static void *  static void *
 entry_alloc(s, u)  entry_alloc(size_t s, void *u UNUSED)
         size_t s;  
         void *u         UNUSED;  
 {  {
         return emalloc(s);          return emalloc(s);
 }  }
   
 static void *  static void *
 emalloc(s)  emalloc(size_t s)
         size_t s;  
 {  {
         return emem(malloc(s));          return emem(malloc(s));
 }  }
Line 228 
Line 219 
 /* Inserting and finding nodes in the hash structure.  /* Inserting and finding nodes in the hash structure.
  * We handle interval strings for efficiency wrt fgetln.  */   * We handle interval strings for efficiency wrt fgetln.  */
 static struct node *  static struct node *
 new_node(start, end)  new_node(const char *start, const char *end)
         const char      *start;  
         const char      *end;  
 {  {
         struct node     *n;          struct node     *n;
   
Line 246 
Line 235 
   
   
 static void  static void
 nodes_init(h)  nodes_init(struct ohash *h)
         struct ohash    *h;  
 {  {
         ohash_init(h, HASH_START, &node_info);          ohash_init(h, HASH_START, &node_info);
 }  }
   
 static struct node *  static struct node *
 node_lookup(h, start, end)  node_lookup(struct ohash *h, const char *start, const char *end)
         struct ohash    *h;  
         const char      *start;  
         const char      *end;  
 {  {
         unsigned int    i;          unsigned int    i;
         struct node *   n;          struct node *   n;
Line 271 
Line 256 
   
 #ifdef DEBUG  #ifdef DEBUG
 static void  static void
 dump_node(n)  dump_node(struct node *n)
     struct node         *n;  
 {  {
         struct link     *l;          struct link     *l;
   
Line 286 
Line 270 
 }  }
   
 static void  static void
 dump_array(a)  dump_array(struct array *a)
         struct array    *a;  
 {  {
         unsigned int    i;          unsigned int    i;
   
Line 296 
Line 279 
 }  }
   
 static void  static void
 dump_hash(h)  dump_hash(struct ohash *h)
         struct ohash    *h;  
 {  {
         unsigned int    i;          unsigned int    i;
         struct node     *n;          struct node     *n;
Line 313 
Line 295 
  ***/   ***/
   
 static void  static void
 insert_arc(a, b)  insert_arc(struct node *a, struct node *b)
         struct node     *a, *b;  
 {  {
         struct link     *l;          struct link     *l;
   
Line 331 
Line 312 
 }  }
   
 static unsigned int  static unsigned int
 read_pairs(f, h, reverse, name, order, hint)  read_pairs(FILE *f, struct ohash *h, int reverse, const char *name,
         FILE            *f;      unsigned int order, int hint)
         struct ohash    *h;  
         int             reverse;  
         const char      *name;  
         unsigned int    order;  
         int             hint;  
 {  {
         int             toggle;          int             toggle;
         struct node     *a;          struct node     *a;
Line 388 
Line 364 
 }  }
   
 static unsigned int  static unsigned int
 read_hints(f, h, quiet, name, order)  read_hints(FILE *f, struct ohash *h, int quiet, const char *name,
         FILE            *f;      unsigned int order)
         struct ohash    *h;  
         int             quiet;  
         const char      *name;  
         unsigned int    order;  
 {  {
         char            *str;          char            *str;
         size_t          size;          size_t          size;
Line 432 
Line 404 
  ***/   ***/
   
 static void  static void
 heap_down(h, i)  heap_down(struct array *h, unsigned int i)
         struct array    *h;  
         unsigned int    i;  
 {  {
         unsigned int    j;          unsigned int    j;
         struct node     *swap;          struct node     *swap;
Line 451 
Line 421 
 }  }
   
 static void  static void
 heapify(h, verbose)  heapify(struct array *h, int verbose)
         struct array    *h;  
         int             verbose;  
 {  {
         unsigned int    i;          unsigned int    i;
   
Line 467 
Line 435 
 #define DEQUEUE(h) ( hints_flag ? dequeue(h) : (h)->t[--(h)->entries] )  #define DEQUEUE(h) ( hints_flag ? dequeue(h) : (h)->t[--(h)->entries] )
   
 static struct node *  static struct node *
 dequeue(h)  dequeue(struct array *h)
         struct array    *h;  
 {  {
         struct node     *n;          struct node     *n;
   
Line 492 
Line 459 
         } while(0);          } while(0);
   
 static void  static void
 enqueue(h, n)  enqueue(struct array *h, struct node *n)
         struct array    *h;  
         struct node     *n;  
 {  {
         unsigned int    i, j;          unsigned int    i, j;
         struct node     *swap;          struct node     *swap;
Line 514 
Line 479 
  * Iterate until no nodes are left.   * Iterate until no nodes are left.
  */   */
 static void  static void
 make_transparent(hash)  make_transparent(struct ohash *hash)
         struct ohash    *hash;  
 {  {
         struct node     *n;          struct node     *n;
         unsigned int    i;          unsigned int    i;
Line 571 
Line 535 
   
 /* Split nodes into unrefed nodes/live nodes.  */  /* Split nodes into unrefed nodes/live nodes.  */
 static void  static void
 split_nodes(hash, heap, remaining)  split_nodes(struct ohash *hash, struct array *heap, struct array *remaining)
         struct ohash    *hash;  
         struct array    *heap;  
         struct array    *remaining;  
 {  {
   
         struct node *n;          struct node *n;
Line 595 
Line 556 
   
 /* Good point to break a cycle: live node with as few refs as possible. */  /* Good point to break a cycle: live node with as few refs as possible. */
 static struct node *  static struct node *
 find_good_cycle_break(h)  find_good_cycle_break(struct array *h)
         struct array    *h;  
 {  {
         unsigned int    i;          unsigned int    i;
         unsigned int    best;          unsigned int    best;
Line 622 
Line 582 
   
 /*  Retrieve the node with the smallest order.  */  /*  Retrieve the node with the smallest order.  */
 static struct node *  static struct node *
 find_smallest_node(h)  find_smallest_node(struct array *h)
         struct array    *h;  
 {  {
         unsigned int    i;          unsigned int    i;
         unsigned int    best;          unsigned int    best;
Line 652 
Line 611 
 /* Explore the nodes reachable from i to find a cycle, store it in c.  /* Explore the nodes reachable from i to find a cycle, store it in c.
  * This may fail.  */   * This may fail.  */
 static struct node *  static struct node *
 find_cycle_from(i, c)  find_cycle_from(struct node *i, struct array *c)
         struct node     *i;  
         struct array    *c;  
 {  {
         struct node     *n;          struct node     *n;
   
Line 702 
Line 659 
  * to go through the whole array, but it is not needed often.   * to go through the whole array, but it is not needed often.
  */   */
 static struct node *  static struct node *
 find_predecessor(a, n)  find_predecessor(struct array *a, struct node *n)
         struct array *a;  
         struct node *n;  
 {  {
         unsigned int i;          unsigned int i;
   
Line 729 
Line 684 
    Update the largest cycle found so far.     Update the largest cycle found so far.
  */   */
 static unsigned int  static unsigned int
 traverse_node(n, o, c)  traverse_node(struct node *n, unsigned int o, struct array *c)
         struct node     *n;  
         unsigned int    o;  
         struct array    *c;  
 {  {
         unsigned int    min, max;          unsigned int    min, max;
   
Line 797 
Line 749 
 }  }
   
 static void  static void
 print_cycle(c)  print_cycle(struct array *c)
         struct array    *c;  
 {  {
         unsigned int    i;          unsigned int    i;
   
Line 811 
Line 762 
 }  }
   
 static struct node *  static struct node *
 find_longest_cycle(h, c)  find_longest_cycle(struct array *h, struct array *c)
         struct array    *h;  
         struct array    *c;  
 {  {
         unsigned int    i;          unsigned int    i;
         unsigned int    o;          unsigned int    o;
Line 863 
Line 812 
 #define plural(n) ((n) > 1 ? "s" : "")  #define plural(n) ((n) > 1 ? "s" : "")
   
 int  int
 main(argc, argv)  main(int argc, char *argv[])
     int                 argc;  
     char                *argv[];  
 {  {
         struct ohash    pairs;          struct ohash    pairs;
         int             reverse_flag, quiet_flag, long_flag,          int             reverse_flag, quiet_flag, long_flag,

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.14