Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

hashinfo improvement



-----BEGIN PGP SIGNED MESSAGE-----

This patch changes the means by which hashinfo lists all the hash tables.
Previously it had to know about each table individually, requiring
them all to have global scope.  This patch causes newhashtable() to
put the created hash tables into a linked list, which hashinfo can then
walk along.

This allows hash tables to be private to a single source file or function,
and yet still appear in the debugging output.  I have a couple of patches
planned that would benefit from this.  (Zoltan, are you planning a 3.1.0
release sometime soon?)

There are no changes if ZSH_HASH_DEBUG is undefined.

 -zefram

      Index: Src/builtin.c
      ===================================================================
      RCS file: /home/zefram/usr/cvsroot/zsh/Src/builtin.c,v
      retrieving revision 1.38
      diff -c -r1.38 builtin.c
      *** Src/builtin.c	1996/11/30 23:34:47	1.38
      --- Src/builtin.c	1996/11/30 23:48:56
      ***************
      *** 5697,5736 ****
            return 0;
        }
        
      - /*** debugging functions ***/
      - 
      - #ifdef ZSH_HASH_DEBUG
      - /**/
      - int
      - bin_hashinfo(char *nam, char **args, char *ops, int func)
      - {
      -     printf("----------------------------------------------------\n");
      -     cmdnamtab->printinfo(cmdnamtab);
      -     printf("----------------------------------------------------\n");
      -     shfunctab->printinfo(shfunctab);
      -     printf("----------------------------------------------------\n");
      -     builtintab->printinfo(builtintab);
      -     printf("----------------------------------------------------\n");
      -     paramtab->printinfo(paramtab);
      -     printf("----------------------------------------------------\n");
      -     compctltab->printinfo(compctltab);
      -     printf("----------------------------------------------------\n");
      -     aliastab->printinfo(aliastab);
      -     printf("----------------------------------------------------\n");
      -     reswdtab->printinfo(reswdtab);
      -     printf("----------------------------------------------------\n");
      -     emkeybindtab->printinfo(emkeybindtab);
      -     printf("----------------------------------------------------\n");
      -     vikeybindtab->printinfo(vikeybindtab);
      -     printf("----------------------------------------------------\n");
      -     altkeybindtab->printinfo(altkeybindtab);
      -     printf("----------------------------------------------------\n");
      -     nameddirtab->printinfo(nameddirtab);
      -     printf("----------------------------------------------------\n");
      -     return 0;
      - }
      - #endif
      - 
        /**** utility functions -- should go in utils.c ****/
        
        /* Separate an argument into name=value parts, returning them in an     *
      --- 5697,5702 ----
      Index: Src/hashtable.c
      ===================================================================
      RCS file: /home/zefram/usr/cvsroot/zsh/Src/hashtable.c,v
      retrieving revision 1.11
      diff -c -r1.11 hashtable.c
      *** Src/hashtable.c	1996/11/08 01:23:07	1.11
      --- Src/hashtable.c	1996/12/01 00:03:36
      ***************
      *** 35,40 ****
      --- 35,44 ----
        /* Generic Hash Table functions */
        /********************************/
        
      + #ifdef ZSH_HASH_DEBUG
      + static HashTable firstht, lastht;
      + #endif
      + 
        /* Generic hash function */
        
        /**/
      ***************
      *** 58,63 ****
      --- 62,76 ----
            HashTable ht;
        
            ht = (HashTable) zcalloc(sizeof *ht);
      + #ifdef ZSH_HASH_DEBUG
      +     ht->next = NULL;
      +     if(!firstht)
      + 	firstht = ht;
      +     ht->last = lastht;
      +     if(lastht)
      + 	lastht->next = ht;
      +     lastht = ht;
      + #endif /* ZSH_HASH_DEBUG */
            ht->nodes = (HashNode *) zcalloc(size * sizeof(HashNode));
            ht->hsize = size;
            ht->ct = 0;
      ***************
      *** 450,459 ****
            ht->ct = 0;
        }
        
      - /* Print info about hash table */
      - 
        #ifdef ZSH_HASH_DEBUG
        
        #define MAXDEPTH 7
        
        /**/
      --- 463,472 ----
            ht->ct = 0;
        }
        
        #ifdef ZSH_HASH_DEBUG
        
      + /* Print info about hash table */
      + 
        #define MAXDEPTH 7
        
        /**/
      ***************
      *** 488,494 ****
            printf("number of hash values with chain of length %d+ : %4d\n", MAXDEPTH, chainlen[MAXDEPTH]);
            printf("total number of nodes                         : %4d\n", total);
        }
      ! #endif
        
        /********************************/
        /* Command Hash Table Functions */
      --- 501,521 ----
            printf("number of hash values with chain of length %d+ : %4d\n", MAXDEPTH, chainlen[MAXDEPTH]);
            printf("total number of nodes                         : %4d\n", total);
        }
      ! 
      ! /**/
      ! int
      ! bin_hashinfo(char *nam, char **args, char *ops, int func)
      ! {
      !     HashTable ht;
      !     printf("----------------------------------------------------\n");
      !     for(ht = firstht; ht; ht = ht->next) {
      ! 	ht->printinfo(ht);
      ! 	printf("----------------------------------------------------\n");
      !     }
      !     return 0;
      ! }
      ! 
      ! #endif /* ZSH_HASH_DEBUG */
        
        /********************************/
        /* Command Hash Table Functions */
      Index: Src/zsh.h
      ===================================================================
      RCS file: /home/zefram/usr/cvsroot/zsh/Src/zsh.h,v
      retrieving revision 1.28
      diff -c -r1.28 zsh.h
      *** Src/zsh.h	1996/11/22 22:59:33	1.28
      --- Src/zsh.h	1996/11/30 23:42:59
      ***************
      *** 637,650 ****
        /* hash table for standard open hashing */
        
        struct hashtable {
            /* HASHTABLE DATA */
            int hsize;			/* size of nodes[]  (number of hash values)   */
            int ct;			/* number of elements                         */
            HashNode *nodes;		/* array of size hsize                        */
      - 
      - #ifdef ZSH_HASH_DEBUG
      -     char *tablename;		/* string containing name of the hash table */
      - #endif
        
            /* HASHTABLE METHODS */
            HashFunc hash;		/* pointer to hash function for this table    */
      --- 637,651 ----
        /* hash table for standard open hashing */
        
        struct hashtable {
      + #ifdef ZSH_HASH_DEBUG
      +     HashTable next, last;	/* linked list of all hash tables */
      +     char *tablename;		/* string containing name of the hash table */
      + #endif
      + 
            /* HASHTABLE DATA */
            int hsize;			/* size of nodes[]  (number of hash values)   */
            int ct;			/* number of elements                         */
            HashNode *nodes;		/* array of size hsize                        */
        
            /* HASHTABLE METHODS */
            HashFunc hash;		/* pointer to hash function for this table    */

-----BEGIN PGP SIGNATURE-----
Version: 2.6.2

iQCVAwUBMqDR4nD/+HJTpU/hAQGs5gQAuldI3pg+HbKDBXwOVYuBy1Nd0rrMlI9h
47B6s2qOTB0VKkILeSXEHc2pKi822DwQM426pVAfE8cOKG7gQucv8+87Dsj3BSfB
6Ih4Nzz/HlNIJrAncHqOYj2KNRnJ8tJJaP06HTHKwWua62VXomG8FJGGxUYNlJKS
H38wbJWemWA=
=Y8fs
-----END PGP SIGNATURE-----



Messages sorted by: Reverse Date, Date, Thread, Author