[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

gEDA-cvs: CVS update: g_netlist.c



  User: pbernaud
  Date: 05/02/13 16:55:42

  Modified:    .        g_netlist.c
  Log:
  Rewritten g_get_packages() to use a hash table instead of the s_scratch of libgeda. Also cleaned up g_get_non_unique_packages().
  
  
  
  
  Revision  Changes    Path
  1.38      +34 -30    eda/geda/devel/gnetlist/src/g_netlist.c
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: g_netlist.c
  ===================================================================
  RCS file: /home/cvspsrv/cvsroot/eda/geda/devel/gnetlist/src/g_netlist.c,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -b -r1.37 -r1.38
  --- g_netlist.c	8 Feb 2005 19:48:22 -0000	1.37
  +++ g_netlist.c	13 Feb 2005 21:55:42 -0000	1.38
  @@ -43,32 +43,43 @@
       project_current = pr_current;
   }
   
  +
  +static void
  +hash_table_2_list (gpointer key,
  +                   gpointer value,
  +                   gpointer user_data)
  +{
  +  SCM* plist = (SCM*)user_data;
  +
  +  *plist = scm_cons (scm_makfrom0str ((char*)value),
  +                     *plist);
  +}
  +
   /* this function will only return a unique list of packages */
   SCM g_get_packages(SCM level)
   {
       SCM list = SCM_EOL;
  +    GHashTable *ht;
   
       NETLIST *nl_current = NULL;
   
       SCM_ASSERT( (SCM_NIMP (level) && SCM_STRINGP (level) ),
   		level, SCM_ARG1, "gnetlist:get-pins");
   
  -    nl_current = netlist_head;
  -    s_scratch_string_init();
  -
  -    while (nl_current != NULL) {
  -
  -	if (nl_current->component_uref) {
  -	    if (s_scratch_string_fill(nl_current->component_uref)) {
  -          list = scm_cons (scm_makfrom0str (nl_current->component_uref),
  -                           list);
  +    /* build a hash table */
  +    ht = g_hash_table_new (g_str_hash, g_str_equal);
  +    for (nl_current = netlist_head; nl_current != NULL;
  +         nl_current = nl_current->next) {
  +      if (nl_current->component_uref != NULL) {
  +        /* add component_uref in the hash table */
  +        /* uniqueness of component_uref is guaranteed by the hashtable */
  +        g_hash_table_insert (ht,
  +                             nl_current->component_uref,
  +                             nl_current->component_uref);
   	    }
   	}
  -	nl_current = nl_current->next;
  -    }
   
  -    s_scratch_string_free();
  -    return (list);
  +    return list;
   }
   
   /* this function will only return a non unique list of packages */
  @@ -81,22 +92,15 @@
       SCM_ASSERT( (SCM_NIMP (level) && SCM_STRINGP (level) ),
   		level, SCM_ARG1, "gnetlist:get-pins");
   
  -    nl_current = netlist_head;
  -    s_scratch_string_init();
  -
  -    while (nl_current != NULL) {
  -
  -	if (nl_current->component_uref) {
  -	    if (s_scratch_non_unique_string_fill(nl_current->component_uref)) {
  +    for (nl_current = netlist_head; nl_current != NULL;
  +         nl_current = nl_current->next) {
  +      if (nl_current->component_uref != NULL) {
             list = scm_cons (scm_makfrom0str (nl_current->component_uref),
                              list);
   	    }
   	}
  -	nl_current = nl_current->next;
  -    }
   
  -    s_scratch_string_free();
  -    return (list);
  +    return list;
   }