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

st.c File Reference

#include "config.h"
#include "defines.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "st.h"

Go to the source code of this file.

Data Structures

struct  st_table_entry

Defines

#define ST_DEFAULT_MAX_DENSITY   5
#define ST_DEFAULT_INIT_TABLE_SIZE   11
#define alloc(type)   (type*)malloc((unsigned)sizeof(type))
#define Calloc(n, s)   (char*)calloc((n),(s))
#define EQUAL(table, x, y)   ((x)==(y) || (*table->type->compare)((x),(y)) == 0)
#define do_hash(key, table)   (unsigned int)(*(table)->type->hash)((key))
#define do_hash_bin(key, table)   (do_hash(key, table)%(table)->num_bins)
#define MINSIZE   8
#define PTR_NOT_EQUAL(table, ptr, hash_val, key)   ((ptr) != 0 && (ptr->hash != (hash_val) || !EQUAL((table), (key), (ptr)->key)))
#define COLLISION
#define FIND_ENTRY(table, ptr, hash_val, bin_pos)
#define ADD_DIRECT(table, key, value, hash_val, bin_pos)

Typedefs

typedef st_table_entry st_table_entry

Functions

int numcmp (long, long)
int numhash (long)
int strhash (const char *)
void rehash (st_table *)
int new_size (int size)
st_tablest_init_table_with_size (struct st_hash_type *type, int size)
st_tablest_init_table (struct st_hash_type *type)
st_tablest_init_numtable (void)
st_tablest_init_numtable_with_size (int size)
st_tablest_init_strtable (void)
st_tablest_init_strtable_with_size (int size)
void st_free_table (st_table *table)
int st_lookup (st_table *table, st_data_t key, st_data_t *value)
int st_insert (st_table *table, st_data_t key, st_data_t value)
void st_add_direct (st_table *table, st_data_t key, st_data_t value)
st_tablest_copy (st_table *old_table)
int st_delete (st_table *table, st_data_t *key, st_data_t *value)
int st_delete_safe (st_table *table, st_data_t *key, st_data_t *value, st_data_t never)
int delete_never (st_data_t key, st_data_t value, st_data_t never)
void st_cleanup_safe (st_table *table, st_data_t never)
int st_foreach (st_table *table, func, st_data_t arg)

Variables

st_hash_type type_numhash
st_hash_type type_strhash
long primes []


Define Documentation

#define ADD_DIRECT table,
key,
value,
hash_val,
bin_pos   ) 
 

Value:

do {\
    st_table_entry *entry;\
    if (table->num_entries/(table->num_bins) > ST_DEFAULT_MAX_DENSITY) {\
        rehash(table);\
        bin_pos = hash_val % table->num_bins;\
    }\
    \
    entry = alloc(st_table_entry);\
    \
    entry->hash = hash_val;\
    entry->key = key;\
    entry->record = value;\
    entry->next = table->bins[bin_pos];\
    table->bins[bin_pos] = entry;\
    table->num_entries++;\
} while (0)

Definition at line 257 of file st.c.

Referenced by st_add_direct(), and st_insert().

#define alloc type   )     (type*)malloc((unsigned)sizeof(type))
 

Definition at line 51 of file st.c.

Referenced by extract_path(), st_copy(), and st_init_table_with_size().

#define Calloc n,
 )     (char*)calloc((n),(s))
 

Definition at line 52 of file st.c.

Referenced by rehash(), st_copy(), and st_init_table_with_size().

#define COLLISION
 

Definition at line 221 of file st.c.

#define do_hash key,
table   )     (unsigned int)(*(table)->type->hash)((key))
 

Definition at line 56 of file st.c.

Referenced by st_add_direct(), st_insert(), and st_lookup().

#define do_hash_bin key,
table   )     (do_hash(key, table)%(table)->num_bins)
 

Definition at line 57 of file st.c.

Referenced by st_delete(), and st_delete_safe().

#define EQUAL table,
x,
 )     ((x)==(y) || (*table->type->compare)((x),(y)) == 0)
 

Definition at line 54 of file st.c.

Referenced by st_delete(), and st_delete_safe().

#define FIND_ENTRY table,
ptr,
hash_val,
bin_pos   ) 
 

Value:

do {\
    bin_pos = hash_val%(table)->num_bins;\
    ptr = (table)->bins[bin_pos];\
    if (PTR_NOT_EQUAL(table, ptr, hash_val, key)) {\
        COLLISION;\
        while (PTR_NOT_EQUAL(table, ptr->next, hash_val, key)) {\
            ptr = ptr->next;\
        }\
        ptr = ptr->next;\
    }\
} while (0)

Definition at line 224 of file st.c.

Referenced by st_insert(), and st_lookup().

#define MINSIZE   8
 

Definition at line 63 of file st.c.

Referenced by new_size().

#define PTR_NOT_EQUAL table,
ptr,
hash_val,
key   )     ((ptr) != 0 && (ptr->hash != (hash_val) || !EQUAL((table), (key), (ptr)->key)))
 

Definition at line 215 of file st.c.

#define ST_DEFAULT_INIT_TABLE_SIZE   11
 

Definition at line 24 of file st.c.

#define ST_DEFAULT_MAX_DENSITY   5
 

Definition at line 23 of file st.c.


Typedef Documentation

typedef struct st_table_entry st_table_entry
 

Definition at line 14 of file st.c.

Referenced by rehash(), st_copy(), st_delete(), st_delete_safe(), st_foreach(), st_free_table(), st_init_table_with_size(), st_insert(), and st_lookup().


Function Documentation

int delete_never st_data_t  key,
st_data_t  value,
st_data_t  never
[static]
 

Definition at line 451 of file st.c.

References ST_CONTINUE, st_data_t, and ST_DELETE.

Referenced by st_cleanup_safe().

int new_size int  size  )  [static]
 

Definition at line 101 of file st.c.

References MINSIZE, and primes.

Referenced by rehash(), and st_init_table_with_size().

int numcmp long  ,
long 
[static]
 

Definition at line 559 of file st.c.

int numhash long   )  [static]
 

Definition at line 566 of file st.c.

void rehash st_table  )  [static]
 

Definition at line 311 of file st.c.

References Calloc, free, st_table_entry::hash, new_size(), st_table_entry::next, and st_table_entry.

void st_add_direct st_table table,
st_data_t  key,
st_data_t  value
 

Definition at line 298 of file st.c.

References ADD_DIRECT, do_hash, and st_data_t.

Referenced by boot_defclass(), define_final(), generic_ivar_set(), method_entry(), rb_alias_variable(), rb_autoload(), rb_copy_generic_ivar(), rb_define_class(), rb_define_module(), rb_global_entry(), rb_hash_aset(), rb_intern(), rb_source_filename(), set_syserr(), w_object(), and w_symbol().

void st_cleanup_safe st_table table,
st_data_t  never
 

Definition at line 459 of file st.c.

References delete_never(), st_data_t, and st_foreach().

Referenced by hash_foreach_ensure().

st_table* st_copy st_table old_table  ) 
 

Definition at line 337 of file st.c.

References alloc, st_table::bins, Calloc, free, st_table_entry::next, and st_table_entry.

Referenced by init_copy(), rb_copy_generic_ivar(), rb_hash_s_create(), rb_mod_init_copy(), and rb_singleton_class_clone().

int st_delete st_table table,
st_data_t key,
st_data_t value
 

Definition at line 378 of file st.c.

References do_hash_bin, EQUAL, free, st_table_entry::key, st_table_entry::next, st_table_entry::record, st_data_t, and st_table_entry.

Referenced by autoload_delete(), autoload_file(), classname(), find_class_path(), generic_ivar_remove(), rb_ary_and(), rb_ary_or(), rb_ary_uniq_bang(), rb_free_generic_ivar(), rb_hash_delete(), rb_mod_init_copy(), rb_mod_remove_const(), rb_mod_remove_cvar(), rb_obj_remove_instance_variable(), rb_require_safe(), rb_thread_local_aset(), rb_waitpid(), remove_method(), run_final(), and undefine_final().

int st_delete_safe st_table table,
st_data_t key,
st_data_t value,
st_data_t  never
 

Definition at line 420 of file st.c.

References do_hash_bin, EQUAL, st_table_entry::key, st_table_entry::next, st_table_entry::record, st_data_t, and st_table_entry.

Referenced by hash_foreach_iter(), and rb_hash_delete().

int st_foreach st_table table,
func  ,
st_data_t  arg
 

Definition at line 470 of file st.c.

References free, st_table_entry::key, st_table_entry::next, st_table_entry::record, ST_CHECK, ST_CONTINUE, st_data_t, ST_DELETE, st_retval, ST_STOP, and st_table_entry.

void st_free_table st_table table  ) 
 

Definition at line 197 of file st.c.

References free, st_table_entry::next, and st_table_entry.

Referenced by autoload_delete(), autoload_file(), check_autoload_table(), class_instance_method_list(), dump_ensure(), generic_ivar_remove(), init_copy(), load_ensure(), obj_free(), rb_autoload(), rb_const_list(), rb_copy_generic_ivar(), rb_free_generic_ivar(), rb_hash_rehash(), rb_obj_singleton_methods(), and thread_free().

st_table* st_init_numtable void   ) 
 

Definition at line 171 of file st.c.

References st_init_table(), and type_numhash.

Referenced by class_instance_method_list(), define_final(), find_class_path(), generic_ivar_set(), include_class_new(), Init_Exception(), Init_var_tables(), marshal_dump(), marshal_load(), mod_av_set(), rb_autoload(), rb_class_boot(), rb_ivar_set(), rb_mod_const_at(), rb_mod_init_copy(), rb_module_new(), rb_obj_singleton_methods(), rb_singleton_class_attached(), rb_singleton_class_clone(), rb_thread_local_aset(), and rb_waitpid().

st_table* st_init_numtable_with_size int  size  ) 
 

Definition at line 177 of file st.c.

References st_init_table_with_size(), and type_numhash.

Referenced by Init_sym().

st_table* st_init_strtable void   ) 
 

Definition at line 184 of file st.c.

References st_init_table(), and type_strhash.

Referenced by Init_GC(), and rb_require_safe().

st_table* st_init_strtable_with_size int  size  ) 
 

Definition at line 190 of file st.c.

References st_init_table_with_size(), and type_strhash.

Referenced by Init_sym().

st_table* st_init_table struct st_hash_type type  ) 
 

Definition at line 164 of file st.c.

References st_init_table_with_size().

Referenced by hash_alloc(), st_init_numtable(), and st_init_strtable().

st_table* st_init_table_with_size struct st_hash_type type,
int  size
 

Definition at line 139 of file st.c.

References alloc, st_table::bins, Calloc, new_size(), st_table::num_bins, st_table::num_entries, st_table_entry, and st_table::type.

Referenced by rb_hash_rehash(), st_init_numtable_with_size(), st_init_strtable_with_size(), and st_init_table().

int st_insert st_table table,
st_data_t  key,
st_data_t  value
 

Definition at line 276 of file st.c.

References ADD_DIRECT, do_hash, FIND_ENTRY, st_table_entry::record, st_data_t, and st_table_entry.

Referenced by classname(), clone_method(), find_class_path(), generic_ivar_set(), mod_av_set(), r_symreal(), rb_add_method(), rb_alias(), rb_autoload(), rb_copy_generic_ivar(), rb_cvar_set(), rb_gc_copy_finalizer(), rb_hash_aset(), rb_hash_rehash_i(), rb_ivar_set(), rb_require_safe(), rb_singleton_class_attached(), rb_thread_local_aset(), rb_waitpid(), and sv_i().

int st_lookup st_table table,
st_data_t  key,
st_data_t value
 

Definition at line 237 of file st.c.

References do_hash, FIND_ENTRY, st_table_entry::record, st_data_t, and st_table_entry.

Referenced by autoload_delete(), autoload_file(), classname(), cvar_override_check(), define_final(), equal_i(), ev_const_defined(), ev_const_get(), fc_path(), generic_ivar_defined(), generic_ivar_get(), generic_ivar_remove(), generic_ivar_set(), get_syserr(), ivar_get(), load_wait(), method_entry(), mod_av_set(), r_symlink(), rb_alias(), rb_alias_variable(), rb_ary_diff(), rb_autoload(), rb_autoload_p(), rb_class_path(), rb_const_defined_0(), rb_const_get_0(), rb_copy_generic_ivar(), rb_cvar_defined(), rb_cvar_get(), rb_cvar_set(), rb_eval(), rb_f_untrace_var(), rb_gc_copy_finalizer(), rb_generic_ivar_table(), rb_global_entry(), rb_hash_aref(), rb_hash_aset(), rb_hash_fetch(), rb_hash_has_key(), rb_id2name(), rb_intern(), rb_ivar_defined(), rb_mark_generic_ivar(), rb_obj_instance_variables(), rb_provided(), rb_source_filename(), rb_thread_key_p(), rb_thread_local_aref(), rb_waitpid(), search_method(), set_syserr(), sv_i(), syserr_initialize(), w_object(), and w_symbol().

int strhash const char *   )  [static]
 

Definition at line 520 of file st.c.


Variable Documentation

long primes[] [static]
 

Definition at line 68 of file st.c.

Referenced by new_size().

struct st_hash_type type_numhash [static]
 

Initial value:

 {
    numcmp,
    numhash,
}

Definition at line 37 of file st.c.

Referenced by st_init_numtable(), and st_init_numtable_with_size().

struct st_hash_type type_strhash [static]
 

Initial value:

 {
    strcmp,
    strhash,
}

Definition at line 44 of file st.c.

Referenced by st_init_strtable(), and st_init_strtable_with_size().


Generated on Wed Jan 18 23:32:11 2006 for Ruby by doxygen 1.3.5