/[guile]/guile/guile-core/libguile/weaks.c
ViewVC logotype

Diff of /guile/guile-core/libguile/weaks.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.53 by mdj, Thu Feb 13 10:42:59 2003 UTC revision 1.54 by mdj, Wed Feb 19 15:04:51 2003 UTC
# Line 52  Line 52 
52    
53    
54    
55    /* 1. The current hash table implementation in hashtab.c uses weak alist
56     *    vectors (formerly called weak hash tables) internally.
57     *
58     * 2. All hash table operations still work on alist vectors.
59     *
60     * 3. The weak vector and alist vector Scheme API is accessed through
61     *    the module (ice-9 weak-vector).
62     */
63    
64    
65  /* {Weak Vectors}  /* {Weak Vectors}
66   */   */
67    
# Line 61  Line 71 
71   * elements which are initialized with the 'fill' object, or, if 'fill' is   * elements which are initialized with the 'fill' object, or, if 'fill' is
72   * undefined, with an unspecified object.   * undefined, with an unspecified object.
73   */   */
74  static SCM  SCM
75  allocate_weak_vector (scm_t_bits type, SCM size, SCM fill, const char* caller)  scm_i_allocate_weak_vector (scm_t_bits type, SCM size, SCM fill, const char* caller)
76  #define FUNC_NAME caller  #define FUNC_NAME caller
77  {  {
78    if (SCM_INUMP (size))    if (SCM_INUMP (size))
# Line 108  allocate_weak_vector (scm_t_bits type, S Line 118  allocate_weak_vector (scm_t_bits type, S
118  }  }
119  #undef FUNC_NAME  #undef FUNC_NAME
120    
   
121  SCM_DEFINE (scm_make_weak_vector, "make-weak-vector", 1, 1, 0,  SCM_DEFINE (scm_make_weak_vector, "make-weak-vector", 1, 1, 0,
122              (SCM size, SCM fill),              (SCM size, SCM fill),
123              "Return a weak vector with @var{size} elements. If the optional\n"              "Return a weak vector with @var{size} elements. If the optional\n"
# Line 117  SCM_DEFINE (scm_make_weak_vector, "make- Line 126  SCM_DEFINE (scm_make_weak_vector, "make-
126              "empty list.")              "empty list.")
127  #define FUNC_NAME s_scm_make_weak_vector  #define FUNC_NAME s_scm_make_weak_vector
128  {  {
129    return allocate_weak_vector (0, size, fill, FUNC_NAME);    return scm_i_allocate_weak_vector (0, size, fill, FUNC_NAME);
130  }  }
131  #undef FUNC_NAME  #undef FUNC_NAME
132    
# Line 170  SCM_DEFINE (scm_weak_vector_p, "weak-vec Line 179  SCM_DEFINE (scm_weak_vector_p, "weak-vec
179    
180    
181    
182  SCM_DEFINE (scm_make_weak_key_hash_table, "make-weak-key-hash-table", 0, 1, 0,  SCM_DEFINE (scm_make_weak_key_alist_vector, "make-weak-key-alist-vector", 0, 1, 0,
183              (SCM size),              (SCM size),
184              "@deffnx {Scheme Procedure} make-weak-value-hash-table size\n"              "@deffnx {Scheme Procedure} make-weak-value-alist-vector size\n"
185              "@deffnx {Scheme Procedure} make-doubly-weak-hash-table size\n"              "@deffnx {Scheme Procedure} make-doubly-weak-alist-vector size\n"
186              "Return a weak hash table with @var{size} buckets. As with any\n"              "Return a weak hash table with @var{size} buckets. As with any\n"
187              "hash table, choosing a good size for the table requires some\n"              "hash table, choosing a good size for the table requires some\n"
188              "caution.\n"              "caution.\n"
189              "\n"              "\n"
190              "You can modify weak hash tables in exactly the same way you\n"              "You can modify weak hash tables in exactly the same way you\n"
191              "would modify regular hash tables. (@pxref{Hash Tables})")              "would modify regular hash tables. (@pxref{Hash Tables})")
192  #define FUNC_NAME s_scm_make_weak_key_hash_table  #define FUNC_NAME s_scm_make_weak_key_alist_vector
193  {  {
194    if (SCM_UNBNDP (size))    return scm_i_allocate_weak_vector
195      return scm_vector_to_hash_table (allocate_weak_vector (1, SCM_MAKINUM (31),      (1, SCM_UNBNDP (size) ? SCM_MAKINUM (31) : size, SCM_EOL, FUNC_NAME);
                                                            SCM_EOL, FUNC_NAME));  
   else  
     return allocate_weak_vector (1, size, SCM_EOL, FUNC_NAME);  
196  }  }
197  #undef FUNC_NAME  #undef FUNC_NAME
198    
199    
200  SCM_DEFINE (scm_make_weak_value_hash_table, "make-weak-value-hash-table", 0, 1, 0,  SCM_DEFINE (scm_make_weak_value_alist_vector, "make-weak-value-alist-vector", 0, 1, 0,
201              (SCM size),              (SCM size),
202              "Return a hash table with weak values with @var{size} buckets.\n"              "Return a hash table with weak values with @var{size} buckets.\n"
203              "(@pxref{Hash Tables})")              "(@pxref{Hash Tables})")
204  #define FUNC_NAME s_scm_make_weak_value_hash_table  #define FUNC_NAME s_scm_make_weak_value_alist_vector
205  {  {
206    if (SCM_UNBNDP (size))    return scm_i_allocate_weak_vector
207      return scm_vector_to_hash_table (allocate_weak_vector (2, SCM_MAKINUM (31),      (2, SCM_UNBNDP (size) ? SCM_MAKINUM (31) : size, SCM_EOL, FUNC_NAME);
                                                            SCM_EOL, FUNC_NAME));  
   else  
     return allocate_weak_vector (2, size, SCM_EOL, FUNC_NAME);  
208  }  }
209  #undef FUNC_NAME  #undef FUNC_NAME
210    
211    
212  SCM_DEFINE (scm_make_doubly_weak_hash_table, "make-doubly-weak-hash-table", 1, 0, 0,  SCM_DEFINE (scm_make_doubly_weak_alist_vector, "make-doubly-weak-alist-vector", 1, 0, 0,
213              (SCM size),              (SCM size),
214              "Return a hash table with weak keys and values with @var{size}\n"              "Return a hash table with weak keys and values with @var{size}\n"
215              "buckets.  (@pxref{Hash Tables})")              "buckets.  (@pxref{Hash Tables})")
216  #define FUNC_NAME s_scm_make_doubly_weak_hash_table  #define FUNC_NAME s_scm_make_doubly_weak_alist_vector
217  {  {
218    if (SCM_UNBNDP (size))    return scm_i_allocate_weak_vector
219      return scm_vector_to_hash_table (allocate_weak_vector (3, SCM_MAKINUM (31),      (3, SCM_UNBNDP (size) ? SCM_MAKINUM (31) : size, SCM_EOL, FUNC_NAME);
                                                            SCM_EOL, FUNC_NAME));  
   else  
     return allocate_weak_vector (3, size, SCM_EOL, FUNC_NAME);  
220  }  }
221  #undef FUNC_NAME  #undef FUNC_NAME
222    
223    
224  SCM_DEFINE (scm_weak_key_hash_table_p, "weak-key-hash-table?", 1, 0, 0,  SCM_DEFINE (scm_weak_key_alist_vector_p, "weak-key-alist-vector?", 1, 0, 0,
225             (SCM obj),             (SCM obj),
226              "@deffnx {Scheme Procedure} weak-value-hash-table? obj\n"              "@deffnx {Scheme Procedure} weak-value-alist-vector? obj\n"
227              "@deffnx {Scheme Procedure} doubly-weak-hash-table? obj\n"              "@deffnx {Scheme Procedure} doubly-weak-alist-vector? obj\n"
228              "Return @code{#t} if @var{obj} is the specified weak hash\n"              "Return @code{#t} if @var{obj} is the specified weak hash\n"
229              "table. Note that a doubly weak hash table is neither a weak key\n"              "table. Note that a doubly weak hash table is neither a weak key\n"
230              "nor a weak value hash table.")              "nor a weak value hash table.")
231  #define FUNC_NAME s_scm_weak_key_hash_table_p  #define FUNC_NAME s_scm_weak_key_alist_vector_p
232  {  {
233    return SCM_BOOL (SCM_WVECTP (obj) && SCM_IS_WHVEC (obj));    return SCM_BOOL (SCM_WVECTP (obj) && SCM_IS_WHVEC (obj));
234  }  }
235  #undef FUNC_NAME  #undef FUNC_NAME
236    
237    
238  SCM_DEFINE (scm_weak_value_hash_table_p, "weak-value-hash-table?", 1, 0, 0,  SCM_DEFINE (scm_weak_value_alist_vector_p, "weak-value-alist-vector?", 1, 0, 0,
239              (SCM obj),              (SCM obj),
240              "Return @code{#t} if @var{obj} is a weak value hash table.")              "Return @code{#t} if @var{obj} is a weak value hash table.")
241  #define FUNC_NAME s_scm_weak_value_hash_table_p  #define FUNC_NAME s_scm_weak_value_alist_vector_p
242  {  {
243    return SCM_BOOL (SCM_WVECTP (obj) && SCM_IS_WHVEC_V (obj));    return SCM_BOOL (SCM_WVECTP (obj) && SCM_IS_WHVEC_V (obj));
244  }  }
245  #undef FUNC_NAME  #undef FUNC_NAME
246    
247    
248  SCM_DEFINE (scm_doubly_weak_hash_table_p, "doubly-weak-hash-table?", 1, 0, 0,  SCM_DEFINE (scm_doubly_weak_alist_vector_p, "doubly-weak-alist-vector?", 1, 0, 0,
249              (SCM obj),              (SCM obj),
250              "Return @code{#t} if @var{obj} is a doubly weak hash table.")              "Return @code{#t} if @var{obj} is a doubly weak hash table.")
251  #define FUNC_NAME s_scm_doubly_weak_hash_table_p  #define FUNC_NAME s_scm_doubly_weak_alist_vector_p
252  {  {
253    return SCM_BOOL (SCM_WVECTP (obj) && SCM_IS_WHVEC_B (obj));    return SCM_BOOL (SCM_WVECTP (obj) && SCM_IS_WHVEC_B (obj));
254  }  }
# Line 325  scm_scan_weak_vectors (void *dummy1 SCM_ Line 325  scm_scan_weak_vectors (void *dummy1 SCM_
325              if (UNMARKED_CELL_P (ptr[j]))              if (UNMARKED_CELL_P (ptr[j]))
326                ptr[j] = SCM_BOOL_F;                ptr[j] = SCM_BOOL_F;
327          }          }
328        else /* if (SCM_IS_WHVEC_ANY (scm_weak_vectors[i])) */        /* check if we should scan the alist vector here (hashtables
329             have their own scan function in hashtab.c). */
330          else if (!SCM_WVECT_NOSCAN_P (w))
331          {          {
332            SCM obj = w;            SCM obj = w;
333            register long n = SCM_VECTOR_LENGTH (w);            register long n = SCM_VECTOR_LENGTH (w);
# Line 378  scm_weaks_prehistory () Line 380  scm_weaks_prehistory ()
380  }  }
381    
382    
383    SCM
384    scm_init_weaks_builtins ()
385    {
386    #include "libguile/weaks.x"
387      return SCM_UNSPECIFIED;
388    }
389    
390  void  void
391  scm_init_weaks ()  scm_init_weaks ()
392  {  {
393  #include "libguile/weaks.x"    scm_c_define_gsubr ("%init-weaks-builtins", 0, 0, 0,
394                          scm_init_weaks_builtins);
395  }  }
396    
397    

Legend:
Removed from v.1.53  
changed lines
  Added in v.1.54

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26