Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals  

hash.c

00001 
00011 static void hsh_var_free(hashindex_t hi, ns_key_t ns, plint_var_t var)
00012 {
00013   plint_var_fre(var);
00014 }
00015 
00020 plint_hsh_t plint_hsh_new()
00021 {
00022   plint_hsh_t hsh;
00023   hash_init(&hsh, (hash_freefunc_t)hsh_var_free);
00024   return hsh;
00025 }
00026 
00027 static int hsh_cpy(hashindex_t hi, ns_key_t ns, plint_ref_t ref, plint_hsh_t dst)
00028 {
00029   plint_str_t str;
00030   plint_hash_str(ns_hash(ns), hi, str);
00031   hash_putstr(NS_GLOBAL(dst), plint_str_sn(str), plint_var_cpy(plint_ref_var(ref)));
00032   plint_str_fre(str);
00033 
00034   return !0;
00035 }
00036 
00044 plint_hsh_t plint_hsh_cpy(plint_hsh_t src)
00045 {
00046   plint_hsh_t dst = plint_hsh_new();
00047   hash_iterdata_all(src, (hash_iterfunc_t)hsh_cpy, dst);
00048   return dst;
00049 }
00050 
00051 static int hsh_dup(hashindex_t hi, ns_key_t ns, plint_ref_t ref, plint_hsh_t dst)
00052 {
00053   plint_str_t str;
00054   plint_hash_str(ns_hash(ns), hi, str);
00055   hash_putstr(NS_GLOBAL(dst), plint_str_sn(str), plint_var_dup(plint_ref_var(ref)));
00056   plint_str_fre(str);
00057 
00058   return !0;
00059 }
00060 
00068 plint_hsh_t plint_hsh_dup(plint_hsh_t src)
00069 {
00070   plint_hsh_t dst = plint_hsh_new();
00071   hash_iterdata_all(src, (hash_iterfunc_t)hsh_dup, dst);
00072   return dst;
00073 }
00074 
00080 void plint_hsh_fre(plint_hsh_t hsh)
00081 {
00082   hash_finish(hsh);
00083 }
00084 
00093 hashindex_t plint_hsh_put(plint_hsh_t hsh, plint_str_t str, plint_var_t var)
00094 {
00095   return hash_putstr(NS_GLOBAL(hsh), plint_str_sn(str), var);
00096 }
00097 
00106 hashindex_t plint_hsh_get(plint_hsh_t hsh, plint_str_t str, plint_ref_t * pref)
00107 {
00108   hashindex_t hi = hash_getindex(hsh, plint_str_sn(str));
00109   *pref = (plint_ref_t)hash_getdata(hi);
00110   return hi;
00111 }
00112 
00113 static int hsh_cat(hashindex_t hi, ns_key_t ns, plint_ref_t ref, plint_hsh_t hsh)
00114 {
00115   plint_var_t var = plint_var_dup(plint_ref_var(ref));
00116   plint_str_t str;
00117   plint_hash_str(ns_hash(ns), hi, str);
00118   hi = plint_hsh_get(hsh, str, &ref);
00119   if (HASH_INDEX_ISBAD(hi))
00120     hash_putstr(NS_GLOBAL(hsh), plint_str_sn(str), var);
00121   else
00122     {
00123       plint_var_fre(plint_ref_var(ref));
00124       plint_ref_var(ref) = var;
00125     }
00126   plint_str_fre(str);
00127 
00128   return !0;
00129 }
00130 
00137 void plint_hsh_cat(plint_hsh_t l, plint_hsh_t r)
00138 {
00139   hash_iterdata_all(r, (hash_iterfunc_t)hsh_cat, l);
00140 }
00141 
00142 PLINT_PTR_TYP_XCHG(hsh)
00143 

Generated on Thu Jan 9 19:02:38 2003 for plint by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002