Ruby  2.0.0p247(2013-06-27revision41674)
Data Structures | Defines | Typedefs | Functions | Variables
st.c File Reference
#include "ruby/ruby.h"
#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Data Structures

struct  st_table_entry
struct  st_packed_entry

Defines

#define STATIC_ASSERT(name, expr)   typedef int static_assert_##name##_check[(expr) ? 1 : -1];
#define ST_DEFAULT_MAX_DENSITY   5
#define ST_DEFAULT_INIT_TABLE_SIZE   11
#define ST_DEFAULT_SECOND_TABLE_SIZE   19
#define ST_DEFAULT_PACKED_TABLE_SIZE   18
#define PACKED_UNIT   (int)(sizeof(st_packed_entry) / sizeof(st_table_entry*))
#define MAX_PACKED_HASH   (int)(ST_DEFAULT_PACKED_TABLE_SIZE * sizeof(st_table_entry*) / sizeof(st_packed_entry))
#define type_numhash   st_hashtype_num
#define malloc   xmalloc
#define calloc   xcalloc
#define realloc   xrealloc
#define free(x)   xfree(x)
#define numberof(array)   (int)(sizeof(array) / sizeof((array)[0]))
#define EQUAL(table, x, y)   ((x)==(y) || (*(table)->type->compare)((x),(y)) == 0)
#define do_hash(key, table)   (st_index_t)(*(table)->type->hash)((key))
#define do_hash_bin(key, table)   (do_hash((key), (table))%(table)->num_bins)
#define st_alloc_entry()   (st_table_entry *)malloc(sizeof(st_table_entry))
#define st_free_entry(entry)   free(entry)
#define st_alloc_table()   (st_table *)malloc(sizeof(st_table))
#define st_dealloc_table(table)   free(table)
#define st_alloc_bins(size)   (st_table_entry **)calloc(size, sizeof(st_table_entry *))
#define st_free_bins(bins, size)   free(bins)
#define bins   as.big.bins
#define head   as.big.head
#define tail   as.big.tail
#define real_entries   as.packed.real_entries
#define PACKED_BINS(table)   ((table)->as.packed.entries)
#define PACKED_ENT(table, i)   PACKED_BINS(table)[i]
#define PKEY(table, i)   PACKED_ENT((table), (i)).key
#define PVAL(table, i)   PACKED_ENT((table), (i)).val
#define PHASH(table, i)   PACKED_ENT((table), (i)).hash
#define PKEY_SET(table, i, v)   (PKEY((table), (i)) = (v))
#define PVAL_SET(table, i, v)   (PVAL((table), (i)) = (v))
#define PHASH_SET(table, i, v)   (PHASH((table), (i)) = (v))
#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 FOUND_ENTRY
#define FIND_ENTRY(table, ptr, hash_val, bin_pos)   ((ptr) = find_entry((table), key, (hash_val), ((bin_pos) = (hash_val)%(table)->num_bins)))
#define collision_check   0
#define collision_check   1
#define FNV1_32A_INIT   0x811c9dc5
#define FNV_32_PRIME   0x01000193
#define UNALIGNED_WORD_ACCESS   0
#define MURMUR   2
#define MurmurMagic_1   (st_index_t)0xc6a4a793
#define MurmurMagic_2   (st_index_t)0x5bd1e995
#define MurmurMagic   MurmurMagic_2
#define murmur_step(h, k)   murmur((h), (k), 16)
#define murmur1(h)   murmur_step((h), 24)
#define data_at(n)   (st_index_t)((unsigned char)data[(n)])
#define UNALIGNED_ADD_4   UNALIGNED_ADD(2); UNALIGNED_ADD(1); UNALIGNED_ADD(0)
#define UNALIGNED_ADD_ALL   UNALIGNED_ADD_4
#define UNALIGNED_ADD(n)
#define UNALIGNED_ADD(n)
#define UNALIGNED_ADD(n)

Typedefs

typedef struct st_table_entry st_table_entry
typedef struct st_packed_entry st_packed_entry

Functions

 STATIC_ASSERT (st_packed_entry, sizeof(st_packed_entry)==sizeof(st_table_entry *[PACKED_UNIT]))
static st_index_t strhash (st_data_t)
static st_index_t strcasehash (st_data_t)
static void rehash (st_table *)
static st_table_entry ** st_realloc_bins (st_table_entry **bins, st_index_t newsize, st_index_t oldsize)
static void remove_packed_entry (st_table *table, st_index_t i)
static void remove_safe_packed_entry (st_table *table, st_index_t i, st_data_t never)
static st_index_t new_size (st_index_t size)
st_tablest_init_table_with_size (const struct st_hash_type *type, st_index_t size)
st_tablest_init_table (const struct st_hash_type *type)
st_tablest_init_numtable (void)
st_tablest_init_numtable_with_size (st_index_t size)
st_tablest_init_strtable (void)
st_tablest_init_strtable_with_size (st_index_t size)
st_tablest_init_strcasetable (void)
st_tablest_init_strcasetable_with_size (st_index_t size)
void st_clear (st_table *table)
void st_free_table (st_table *table)
size_t st_memsize (const st_table *table)
static st_table_entryfind_entry (st_table *table, st_data_t key, st_index_t hash_val, st_index_t bin_pos)
static st_index_t find_packed_index (st_table *table, st_index_t hash_val, st_data_t key)
int st_lookup (st_table *table, register st_data_t key, st_data_t *value)
int st_get_key (st_table *table, register st_data_t key, st_data_t *result)
static st_table_entrynew_entry (st_table *table, st_data_t key, st_data_t value, st_index_t hash_val, register st_index_t bin_pos)
static void add_direct (st_table *table, st_data_t key, st_data_t value, st_index_t hash_val, register st_index_t bin_pos)
static void unpack_entries (register st_table *table)
static void add_packed_direct (st_table *table, st_data_t key, st_data_t value, st_index_t hash_val)
int st_insert (register st_table *table, register st_data_t key, st_data_t value)
int st_insert2 (register st_table *table, register st_data_t key, st_data_t value, st_data_t(*func)(st_data_t))
void st_add_direct (st_table *table, st_data_t key, st_data_t value)
static void rehash (register st_table *table)
st_tablest_copy (st_table *old_table)
static void remove_entry (st_table *table, st_table_entry *ptr)
int st_delete (register st_table *table, register st_data_t *key, st_data_t *value)
int st_delete_safe (register st_table *table, register 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_update (st_table *table, st_data_t key, st_update_callback_func *func, st_data_t arg)
int st_foreach_check (st_table *table, int(*func)(ANYARGS), st_data_t arg, st_data_t never)
int st_foreach (st_table *table, int(*func)(ANYARGS), st_data_t arg)
static st_index_t murmur (st_index_t h, st_index_t k, int r)
static st_index_t murmur_finish (st_index_t h)
st_index_t st_hash (const void *ptr, size_t len, st_index_t h)
st_index_t st_hash_uint32 (st_index_t h, uint32_t i)
st_index_t st_hash_uint (st_index_t h, st_index_t i)
st_index_t st_hash_end (st_index_t h)
st_index_t st_hash_start (st_index_t h)
int st_strcasecmp (const char *s1, const char *s2)
int st_strncasecmp (const char *s1, const char *s2, size_t n)
int st_numcmp (st_data_t x, st_data_t y)
st_index_t st_numhash (st_data_t n)

Variables

static struct st_hash_type type_strhash
static struct st_hash_type type_strcasehash
static const unsigned int primes []

Define Documentation

#define bins   as.big.bins

Definition at line 106 of file st.c.

Referenced by st_realloc_bins().

#define calloc   xcalloc

Definition at line 78 of file st.c.

#define COLLISION

Definition at line 373 of file st.c.

Referenced by find_entry().

#define collision_check   0

Definition at line 465 of file st.c.

#define collision_check   1

Definition at line 465 of file st.c.

#define data_at (   n)    (st_index_t)((unsigned char)data[(n)])
#define do_hash (   key,
  table 
)    (st_index_t)(*(table)->type->hash)((key))
#define do_hash_bin (   key,
  table 
)    (do_hash((key), (table))%(table)->num_bins)

Definition at line 88 of file st.c.

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

Definition at line 85 of file st.c.

Referenced by find_packed_index(), st_delete(), and st_delete_safe().

#define FIND_ENTRY (   table,
  ptr,
  hash_val,
  bin_pos 
)    ((ptr) = find_entry((table), key, (hash_val), ((bin_pos) = (hash_val)%(table)->num_bins)))

Definition at line 377 of file st.c.

Referenced by st_foreach(), st_foreach_check(), st_insert(), st_insert2(), and st_update().

#define FNV1_32A_INIT   0x811c9dc5

Definition at line 1215 of file st.c.

Referenced by strcasehash(), and strhash().

#define FNV_32_PRIME   0x01000193

Definition at line 1220 of file st.c.

Referenced by strcasehash().

#define FOUND_ENTRY

Definition at line 374 of file st.c.

Referenced by find_entry().

#define free (   x)    xfree(x)

Definition at line 80 of file st.c.

#define head   as.big.head
#define malloc   xmalloc

Definition at line 77 of file st.c.

Definition at line 40 of file st.c.

Referenced by st_init_table_with_size(), and unpack_entries().

#define MINSIZE   8

Definition at line 146 of file st.c.

Referenced by new_size().

#define MURMUR   2

Definition at line 1256 of file st.c.

#define murmur1 (   h)    murmur_step((h), 24)

Definition at line 1309 of file st.c.

Referenced by st_hash_uint().

#define murmur_step (   h,
 
)    murmur((h), (k), 16)

Definition at line 1304 of file st.c.

Referenced by st_hash(), st_hash_end(), and st_hash_uint32().

#define MurmurMagic   MurmurMagic_2

Definition at line 1267 of file st.c.

Referenced by murmur(), murmur_finish(), and st_hash().

#define MurmurMagic_1   (st_index_t)0xc6a4a793

Definition at line 1259 of file st.c.

#define MurmurMagic_2   (st_index_t)0x5bd1e995

Definition at line 1260 of file st.c.

#define numberof (   array)    (int)(sizeof(array) / sizeof((array)[0]))

Definition at line 83 of file st.c.

Referenced by new_size().

#define PACKED_BINS (   table)    ((table)->as.packed.entries)

Definition at line 112 of file st.c.

Referenced by unpack_entries().

#define PACKED_ENT (   table,
 
)    PACKED_BINS(table)[i]

Definition at line 113 of file st.c.

Referenced by remove_packed_entry(), and st_cleanup_safe().

Definition at line 39 of file st.c.

#define PHASH (   table,
 
)    PACKED_ENT((table), (i)).hash

Definition at line 116 of file st.c.

Referenced by find_packed_index(), st_foreach(), and st_foreach_check().

#define PHASH_SET (   table,
  i,
 
)    (PHASH((table), (i)) = (v))

Definition at line 119 of file st.c.

Referenced by add_packed_direct(), and remove_safe_packed_entry().

#define PKEY (   table,
 
)    PACKED_ENT((table), (i)).key
#define PKEY_SET (   table,
  i,
 
)    (PKEY((table), (i)) = (v))

Definition at line 117 of file st.c.

Referenced by add_packed_direct(), and remove_safe_packed_entry().

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

Definition at line 352 of file st.c.

Referenced by find_entry().

#define PVAL (   table,
 
)    PACKED_ENT((table), (i)).val

Definition at line 115 of file st.c.

Referenced by st_delete(), st_delete_safe(), st_foreach(), st_foreach_check(), st_lookup(), and st_update().

#define PVAL_SET (   table,
  i,
 
)    (PVAL((table), (i)) = (v))

Definition at line 118 of file st.c.

Referenced by add_packed_direct(), remove_safe_packed_entry(), st_insert(), st_insert2(), and st_update().

#define realloc   xrealloc

Definition at line 79 of file st.c.

Referenced by st_realloc_bins().

Definition at line 95 of file st.c.

Referenced by st_copy(), and st_init_table_with_size().

Definition at line 91 of file st.c.

Referenced by new_entry(), and st_copy().

#define st_alloc_table ( )    (st_table *)malloc(sizeof(st_table))

Definition at line 93 of file st.c.

Referenced by st_copy(), and st_init_table_with_size().

#define st_dealloc_table (   table)    free(table)

Definition at line 94 of file st.c.

Referenced by st_copy(), and st_free_table().

#define ST_DEFAULT_INIT_TABLE_SIZE   11

Definition at line 36 of file st.c.

Referenced by unpack_entries().

#define ST_DEFAULT_MAX_DENSITY   5

Definition at line 35 of file st.c.

Referenced by add_direct().

Definition at line 38 of file st.c.

Referenced by st_init_table_with_size().

Definition at line 37 of file st.c.

#define st_free_bins (   bins,
  size 
)    free(bins)

Definition at line 96 of file st.c.

Referenced by st_free_table().

#define st_free_entry (   entry)    free(entry)

Definition at line 92 of file st.c.

Referenced by st_cleanup_safe(), st_clear(), st_delete(), st_foreach(), and st_update().

#define STATIC_ASSERT (   name,
  expr 
)    typedef int static_assert_##name##_check[(expr) ? 1 : -1];

Definition at line 33 of file st.c.

#define tail   as.big.tail
#define UNALIGNED_ADD (   n)
Value:
case SIZEOF_ST_INDEX_T - (n) - 1:       \
                t |= data_at(n) << CHAR_BIT*(n)
#define UNALIGNED_ADD (   n)
Value:
case (n) + 1: \
                d |= data_at(n) << CHAR_BIT*(n)
#define UNALIGNED_ADD (   n)
Value:
case (n) + 1: \
        t |= data_at(n) << CHAR_BIT*(n)

Referenced by st_hash().

#define UNALIGNED_WORD_ACCESS   0

Definition at line 1251 of file st.c.


Typedef Documentation

Definition at line 18 of file st.c.


Function Documentation

static void add_direct ( st_table table,
st_data_t  key,
st_data_t  value,
st_index_t  hash_val,
register st_index_t  bin_pos 
) [inline, static]
static void add_packed_direct ( st_table table,
st_data_t  key,
st_data_t  value,
st_index_t  hash_val 
) [static]
static st_table_entry* find_entry ( st_table table,
st_data_t  key,
st_index_t  hash_val,
st_index_t  bin_pos 
) [static]

Definition at line 381 of file st.c.

References st_table::bins, COLLISION, FOUND_ENTRY, st_table_entry::next, and PTR_NOT_EQUAL.

Referenced by st_get_key(), and st_lookup().

static st_index_t find_packed_index ( st_table table,
st_index_t  hash_val,
st_data_t  key 
) [inline, static]
static st_index_t murmur ( st_index_t  h,
st_index_t  k,
int  r 
) [inline, static]

Definition at line 1272 of file st.c.

References MurmurMagic.

Referenced by murmur_finish().

static st_index_t murmur_finish ( st_index_t  h) [inline, static]

Definition at line 1291 of file st.c.

References murmur(), and MurmurMagic.

Referenced by st_hash().

static st_table_entry* new_entry ( st_table table,
st_data_t  key,
st_data_t  value,
st_index_t  hash_val,
register st_index_t  bin_pos 
) [inline, static]
static st_index_t new_size ( st_index_t  size) [static]
static void rehash ( st_table ) [static]

Referenced by add_direct().

static void rehash ( register st_table table) [static]
static void remove_entry ( st_table table,
st_table_entry ptr 
) [inline, static]
static void remove_packed_entry ( st_table table,
st_index_t  i 
) [inline, static]

Definition at line 123 of file st.c.

References MEMMOVE, st_table::num_entries, PACKED_ENT, st_table::real_entries, and real_entries.

Referenced by st_delete(), st_foreach(), and st_update().

static void remove_safe_packed_entry ( st_table table,
st_index_t  i,
st_data_t  never 
) [inline, static]

Definition at line 134 of file st.c.

References st_table::num_entries, PHASH_SET, PKEY_SET, and PVAL_SET.

Referenced by st_delete_safe(), and st_foreach_check().

void st_add_direct ( st_table table,
st_data_t  key,
st_data_t  value 
)
void st_cleanup_safe ( st_table table,
st_data_t  never 
)
void st_clear ( st_table table)
st_table* st_copy ( st_table old_table)
int st_delete ( register st_table table,
register st_data_t key,
st_data_t value 
)
int st_delete_safe ( register st_table table,
register st_data_t key,
st_data_t value,
st_data_t  never 
)
int st_foreach ( st_table table,
int(*)(ANYARGS func,
st_data_t  arg 
)

Definition at line 1000 of file st.c.

References st_table::bins, st_table::entries_packed, FIND_ENTRY, st_table_entry::fore, st_table_entry::hash, hash(), st_table::head, st_table_entry::key, key, last, st_table_entry::next, st_table::num_bins, PHASH, PKEY, PVAL, st_table::real_entries, st_table_entry::record, remove_entry(), remove_packed_entry(), ST_CHECK, ST_CONTINUE, ST_DELETE, st_free_entry, ST_STOP, and val.

Referenced by class_instance_method_list(), clear_coverage(), count_nodes(), count_objects(), count_objects_size(), count_tdata_objects(), enc_names(), exit_handler(), extract_keywords(), fc_i(), get_loaded_features_index(), include_modules_at(), mark_const_tbl(), mark_hash(), mark_m_tbl(), mark_marshal_compat_t(), mark_set(), mark_tbl(), proc_waitall(), rb_ary_uniq(), rb_ary_uniq_bang(), rb_check_deadlock(), rb_check_exec_env(), rb_check_exec_options(), rb_clear_trace_func(), rb_coverage_result(), rb_econv_asciicompat_encoding(), rb_enc_aliases(), rb_enc_name_list(), rb_execarg_extract_options(), rb_execarg_fixup(), rb_feature_p(), rb_free_const_table(), rb_free_m_table(), rb_mod_init_copy(), rb_obj_singleton_methods(), rb_objspace_call_finalizer(), rb_prepend_module(), rb_singleton_class_clone_and_attach(), rb_sym_all_symbols(), rb_thread_atfork_internal(), rb_thread_fd_close(), rb_thread_keys(), rb_thread_list(), rb_thread_terminate_all(), rb_vm_check_redefinition_by_prepend(), rb_vm_mark(), rb_waitpid(), reachable_objects_from(), thgroup_list(), transcode_search_path(), validate_labels(), wmap_free(), wmap_mark(), and wmap_memsize().

int st_foreach_check ( st_table table,
int(*)(ANYARGS func,
st_data_t  arg,
st_data_t  never 
)
void st_free_table ( st_table table)
int st_get_key ( st_table table,
register st_data_t  key,
st_data_t result 
)
st_index_t st_hash ( const void *  ptr,
size_t  len,
st_index_t  h 
)

Definition at line 1313 of file st.c.

References CHAR_BIT, murmur_finish(), murmur_step, MurmurMagic, SIZEOF_ST_INDEX_T, and UNALIGNED_ADD_ALL.

Referenced by hash_i(), and strhash().

Definition at line 1477 of file st.c.

References murmur_step.

Definition at line 1486 of file st.c.

References st_hash_start.

Definition at line 1446 of file st.c.

References murmur1.

Definition at line 1440 of file st.c.

References murmur_step.

Definition at line 278 of file st.c.

References st_init_table_with_size(), and type_numhash.

Referenced by Init_sym().

Definition at line 302 of file st.c.

References st_init_table_with_size().

Definition at line 284 of file st.c.

References st_init_table().

Referenced by Init_load(), load_lock(), and zone_str().

Definition at line 290 of file st.c.

References st_init_table_with_size().

Definition at line 266 of file st.c.

References st_init_table_with_size().

Referenced by rb_hash_tbl(), st_init_numtable(), st_init_strcasetable(), and st_init_strtable().

int st_insert ( register st_table table,
register st_data_t  key,
st_data_t  value 
)
int st_insert2 ( register st_table table,
register st_data_t  key,
st_data_t  value,
st_data_t(*)(st_data_t func 
)
int st_lookup ( st_table table,
register st_data_t  key,
st_data_t value 
)
size_t st_memsize ( const st_table table)
int st_numcmp ( st_data_t  x,
st_data_t  y 
)

Definition at line 1569 of file st.c.

Referenced by STATIC_ASSERT().

Definition at line 1575 of file st.c.

Referenced by STATIC_ASSERT().

static st_table_entry** st_realloc_bins ( st_table_entry **  bins,
st_index_t  newsize,
st_index_t  oldsize 
) [inline, static]

Definition at line 98 of file st.c.

References bins, MEMZERO, and realloc.

Referenced by rehash(), and unpack_entries().

int st_strcasecmp ( const char *  s1,
const char *  s2 
)

Definition at line 1500 of file st.c.

int st_strncasecmp ( const char *  s1,
const char *  s2,
size_t  n 
)

Definition at line 1524 of file st.c.

int st_update ( st_table table,
st_data_t  key,
st_update_callback_func func,
st_data_t  arg 
)

Definition at line 42 of file st.c.

References st_hashtype_num, st_numcmp(), and st_numhash().

static st_index_t strcasehash ( st_data_t  arg) [static]

Definition at line 1549 of file st.c.

References FNV1_32A_INIT, and FNV_32_PRIME.

static st_index_t strhash ( st_data_t  arg) [static]

Definition at line 1492 of file st.c.

References FNV1_32A_INIT, st_hash(), and strlen().

static void unpack_entries ( register st_table table) [static]

Variable Documentation

const unsigned int primes[] [static]

Definition at line 151 of file st.c.

struct st_hash_type type_strcasehash [static]
Initial value:

Definition at line 69 of file st.c.

struct st_hash_type type_strhash [static]
Initial value:
 {
    strcmp,
    strhash,
}

Definition at line 63 of file st.c.