Ruby  2.4.2p198(2017-09-14revision59899)
Data Structures | Macros | Typedefs | Functions
id_table.c File Reference
#include "id_table.h"
#include "ruby_assert.h"
Include dependency graph for id_table.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  list_id_table
 
struct  rb_id_item
 
struct  hash_id_table
 
struct  mix_id_table
 

Macros

#define ID_TABLE_DEBUG   0
 
#define NDEBUG
 
#define ID_TABLE_IMPL   34
 
#define ID_TABLE_NAME   mix
 
#define ID_TABLE_IMPL_TYPE   struct mix_id_table
 
#define ID_TABLE_USE_MIX   1
 
#define ID_TABLE_USE_MIX_LIST_MAX_CAPA   64
 
#define ID_TABLE_USE_ID_SERIAL   1
 
#define ID_TABLE_USE_LIST   1
 
#define ID_TABLE_USE_CALC_VALUES   1
 
#define ID_TABLE_USE_LIST_SORTED   1
 
#define ID_TABLE_USE_SMALL_HASH   1
 
#define IMPL1(name, op)   TOKEN_PASTE(name, _id##op) /* expand `name' */
 
#define IMPL(op)   IMPL1(ID_TABLE_NAME, _table##op) /* but prevent `op' */
 
#define UNUSED(func)   static func
 
#define LIST_MIN_CAPA   4
 
#define TABLE_VALUES(tbl)   ((VALUE *)((tbl)->keys + (tbl)->capa))
 
#define FOREACH_LAST()
 
#define ITEM_GET_KEY(tbl, i)   ((tbl)->items[i].key >> 1)
 
#define ITEM_KEY_ISSET(tbl, i)   ((tbl)->items[i].key > 1)
 
#define ITEM_COLLIDED(tbl, i)   ((tbl)->items[i].key & 1)
 
#define ITEM_SET_COLLIDED(tbl, i)   ((tbl)->items[i].key |= 1)
 
#define LIST_LIMIT_P(mix)   ((mix)->aux.size.num == ID_TABLE_USE_MIX_LIST_MAX_CAPA)
 
#define LIST_P(mix)   ((mix)->aux.size.capa <= ID_TABLE_USE_MIX_LIST_MAX_CAPA)
 
#define IMPL_TYPE1(type, prot, name, args)   RUBY_ALIAS_FUNCTION_TYPE(type, prot, name, args)
 
#define IMPL_TYPE(type, name, prot, args)   IMPL_TYPE1(type, rb_id_table_##name prot, IMPL(_##name), args)
 
#define IMPL_VOID1(prot, name, args)   RUBY_ALIAS_FUNCTION_VOID(prot, name, args)
 
#define IMPL_VOID(name, prot, args)   IMPL_VOID1(rb_id_table_##name prot, IMPL(_##name), args)
 
#define id_tbl   (ID_TABLE_IMPL_TYPE *)tbl
 

Typedefs

typedef rb_id_serial_t id_key_t
 
typedef struct rb_id_item item_t
 

Functions

 UNUSED (ID_TABLE_IMPL_TYPE *IMPL(_create)(size_t))
 
 UNUSED (void IMPL(_free)(ID_TABLE_IMPL_TYPE *))
 
 UNUSED (void IMPL(_clear)(ID_TABLE_IMPL_TYPE *))
 
 UNUSED (size_t IMPL(_size)(const ID_TABLE_IMPL_TYPE *))
 
 UNUSED (size_t IMPL(_memsize)(const ID_TABLE_IMPL_TYPE *))
 
 UNUSED (int IMPL(_insert)(ID_TABLE_IMPL_TYPE *, ID, VALUE))
 
 UNUSED (int IMPL(_lookup)(ID_TABLE_IMPL_TYPE *, ID, VALUE *))
 
 UNUSED (int IMPL(_delete)(ID_TABLE_IMPL_TYPE *, ID))
 
 UNUSED (void IMPL(_foreach)(ID_TABLE_IMPL_TYPE *, rb_id_table_foreach_func_t *, void *))
 
 UNUSED (void IMPL(_foreach_values)(ID_TABLE_IMPL_TYPE *, rb_id_table_foreach_values_func_t *, void *))
 
static ID key2id (id_key_t key)
 
static id_key_t id2key (ID id)
 
static struct list_id_tablelist_id_table_init (struct list_id_table *tbl, size_t capa)
 
static void list_id_table_free (struct list_id_table *tbl)
 
static void list_id_table_clear (struct list_id_table *tbl)
 
static size_t list_id_table_size (const struct list_id_table *tbl)
 
static size_t list_id_table_memsize (const struct list_id_table *tbl)
 
static void list_table_extend (struct list_id_table *tbl)
 
static void tbl_assert (struct list_id_table *tbl)
 
static int list_ids_bsearch (const id_key_t *keys, id_key_t key, int num)
 
static int list_table_index (struct list_id_table *tbl, id_key_t key)
 
static int list_id_table_lookup (struct list_id_table *tbl, ID id, VALUE *valp)
 
static int list_id_table_insert (struct list_id_table *tbl, ID id, VALUE val)
 
static int list_delete_index (struct list_id_table *tbl, id_key_t key, int index)
 
static int list_id_table_delete (struct list_id_table *tbl, ID id)
 
static void list_id_table_foreach (struct list_id_table *tbl, rb_id_table_foreach_func_t *func, void *data)
 
static void list_id_table_foreach_values (struct list_id_table *tbl, rb_id_table_foreach_values_func_t *func, void *data)
 
static void ITEM_SET_KEY (struct hash_id_table *tbl, int i, id_key_t key)
 
static int round_capa (int capa)
 
static struct hash_id_tablehash_id_table_init (struct hash_id_table *tbl, int capa)
 
static void hash_id_table_free (struct hash_id_table *tbl)
 
static void hash_id_table_clear (struct hash_id_table *tbl)
 
static size_t hash_id_table_size (const struct hash_id_table *tbl)
 
static size_t hash_id_table_memsize (const struct hash_id_table *tbl)
 
static int hash_table_index (struct hash_id_table *tbl, id_key_t key)
 
static void hash_table_raw_insert (struct hash_id_table *tbl, id_key_t key, VALUE val)
 
static int hash_delete_index (struct hash_id_table *tbl, int ix)
 
static void hash_table_extend (struct hash_id_table *tbl)
 
static int hash_id_table_lookup (struct hash_id_table *tbl, ID id, VALUE *valp)
 
static int hash_id_table_insert_key (struct hash_id_table *tbl, const id_key_t key, const VALUE val)
 
static int hash_id_table_insert (struct hash_id_table *tbl, ID id, VALUE val)
 
static int hash_id_table_delete (struct hash_id_table *tbl, ID id)
 
static void hash_id_table_foreach (struct hash_id_table *tbl, rb_id_table_foreach_func_t *func, void *data)
 
static void hash_id_table_foreach_values (struct hash_id_table *tbl, rb_id_table_foreach_values_func_t *func, void *data)
 
static struct mix_id_tablemix_id_table_create (size_t size)
 
static void mix_id_table_free (struct mix_id_table *tbl)
 
static void mix_id_table_clear (struct mix_id_table *tbl)
 
static size_t mix_id_table_size (const struct mix_id_table *tbl)
 
static size_t mix_id_table_memsize (const struct mix_id_table *tbl)
 
static int mix_id_table_insert (struct mix_id_table *tbl, ID id, VALUE val)
 
static int mix_id_table_lookup (struct mix_id_table *tbl, ID id, VALUE *valp)
 
static int mix_id_table_delete (struct mix_id_table *tbl, ID id)
 
static void mix_id_table_foreach (struct mix_id_table *tbl, rb_id_table_foreach_func_t *func, void *data)
 
static void mix_id_table_foreach_values (struct mix_id_table *tbl, rb_id_table_foreach_values_func_t *func, void *data)
 

Macro Definition Documentation

◆ FOREACH_LAST

#define FOREACH_LAST ( )
Value:
do { \
switch (ret) { \
case ID_TABLE_STOP: \
break; \
list_delete_index(tbl, key, i); \
values = TABLE_VALUES(tbl); \
num = tbl->num; \
i--; /* redo same index */ \
break; \
} \
} while (0)
#define TABLE_VALUES(tbl)
Definition: id_table.c:373

Definition at line 721 of file id_table.c.

Referenced by list_id_table_foreach(), and list_id_table_foreach_values().

◆ ID_TABLE_DEBUG

#define ID_TABLE_DEBUG   0

Definition at line 6 of file id_table.c.

◆ ID_TABLE_IMPL

#define ID_TABLE_IMPL   34

Definition at line 36 of file id_table.c.

◆ ID_TABLE_IMPL_TYPE

#define ID_TABLE_IMPL_TYPE   struct mix_id_table

Definition at line 153 of file id_table.c.

◆ ID_TABLE_NAME

#define ID_TABLE_NAME   mix

Definition at line 152 of file id_table.c.

◆ ID_TABLE_USE_CALC_VALUES

#define ID_TABLE_USE_CALC_VALUES   1

Definition at line 161 of file id_table.c.

◆ ID_TABLE_USE_ID_SERIAL

#define ID_TABLE_USE_ID_SERIAL   1

Definition at line 158 of file id_table.c.

◆ ID_TABLE_USE_LIST

#define ID_TABLE_USE_LIST   1

Definition at line 160 of file id_table.c.

◆ ID_TABLE_USE_LIST_SORTED

#define ID_TABLE_USE_LIST_SORTED   1

Definition at line 162 of file id_table.c.

◆ ID_TABLE_USE_MIX

#define ID_TABLE_USE_MIX   1

Definition at line 155 of file id_table.c.

◆ ID_TABLE_USE_MIX_LIST_MAX_CAPA

#define ID_TABLE_USE_MIX_LIST_MAX_CAPA   64

Definition at line 156 of file id_table.c.

◆ ID_TABLE_USE_SMALL_HASH

#define ID_TABLE_USE_SMALL_HASH   1

Definition at line 164 of file id_table.c.

◆ id_tbl

#define id_tbl   (ID_TABLE_IMPL_TYPE *)tbl

Definition at line 1563 of file id_table.c.

◆ IMPL

#define IMPL (   op)    IMPL1(ID_TABLE_NAME, _table##op) /* but prevent `op' */

Definition at line 192 of file id_table.c.

◆ IMPL1

#define IMPL1 (   name,
  op 
)    TOKEN_PASTE(name, _id##op) /* expand `name' */

Definition at line 191 of file id_table.c.

◆ IMPL_TYPE

#define IMPL_TYPE (   type,
  name,
  prot,
  args 
)    IMPL_TYPE1(type, rb_id_table_##name prot, IMPL(_##name), args)

Definition at line 1557 of file id_table.c.

◆ IMPL_TYPE1

#define IMPL_TYPE1 (   type,
  prot,
  name,
  args 
)    RUBY_ALIAS_FUNCTION_TYPE(type, prot, name, args)

Definition at line 1555 of file id_table.c.

◆ IMPL_VOID

#define IMPL_VOID (   name,
  prot,
  args 
)    IMPL_VOID1(rb_id_table_##name prot, IMPL(_##name), args)

Definition at line 1561 of file id_table.c.

◆ IMPL_VOID1

#define IMPL_VOID1 (   prot,
  name,
  args 
)    RUBY_ALIAS_FUNCTION_VOID(prot, name, args)

Definition at line 1559 of file id_table.c.

◆ ITEM_COLLIDED

#define ITEM_COLLIDED (   tbl,
 
)    ((tbl)->items[i].key & 1)

◆ ITEM_GET_KEY

#define ITEM_GET_KEY (   tbl,
 
)    ((tbl)->items[i].key >> 1)

Definition at line 1180 of file id_table.c.

Referenced by hash_id_table_foreach(), hash_table_extend(), and hash_table_index().

◆ ITEM_KEY_ISSET

#define ITEM_KEY_ISSET (   tbl,
 
)    ((tbl)->items[i].key > 1)

◆ ITEM_SET_COLLIDED

#define ITEM_SET_COLLIDED (   tbl,
 
)    ((tbl)->items[i].key |= 1)

Definition at line 1183 of file id_table.c.

Referenced by hash_table_raw_insert().

◆ LIST_LIMIT_P

#define LIST_LIMIT_P (   mix)    ((mix)->aux.size.num == ID_TABLE_USE_MIX_LIST_MAX_CAPA)

Definition at line 1442 of file id_table.c.

Referenced by mix_id_table_insert().

◆ LIST_MIN_CAPA

#define LIST_MIN_CAPA   4

Definition at line 361 of file id_table.c.

Referenced by list_table_extend().

◆ LIST_P

#define LIST_P (   mix)    ((mix)->aux.size.capa <= ID_TABLE_USE_MIX_LIST_MAX_CAPA)

◆ NDEBUG

#define NDEBUG

Definition at line 10 of file id_table.c.

◆ TABLE_VALUES

#define TABLE_VALUES (   tbl)    ((VALUE *)((tbl)->keys + (tbl)->capa))

◆ UNUSED

#define UNUSED (   func )    static func

Definition at line 197 of file id_table.c.

Typedef Documentation

◆ id_key_t

Definition at line 212 of file id_table.c.

◆ item_t

typedef struct rb_id_item item_t

Function Documentation

◆ hash_delete_index()

static int hash_delete_index ( struct hash_id_table tbl,
int  ix 
)
static

◆ hash_id_table_clear()

static void hash_id_table_clear ( struct hash_id_table tbl)
static

◆ hash_id_table_delete()

static int hash_id_table_delete ( struct hash_id_table tbl,
ID  id 
)
static

Definition at line 1385 of file id_table.c.

References hash_delete_index(), hash_table_index(), and id2key().

Referenced by list_id_table_foreach_values(), and mix_id_table_delete().

◆ hash_id_table_foreach()

static void hash_id_table_foreach ( struct hash_id_table tbl,
rb_id_table_foreach_func_t func,
void *  data 
)
static

◆ hash_id_table_foreach_values()

static void hash_id_table_foreach_values ( struct hash_id_table tbl,
rb_id_table_foreach_values_func_t func,
void *  data 
)
static

◆ hash_id_table_free()

static void hash_id_table_free ( struct hash_id_table tbl)
static

Definition at line 1226 of file id_table.c.

References hash_id_table::items, and xfree().

Referenced by list_id_table_foreach_values(), and mix_id_table_free().

◆ hash_id_table_init()

static struct hash_id_table* hash_id_table_init ( struct hash_id_table tbl,
int  capa 
)
static

Definition at line 1205 of file id_table.c.

References ALLOC, hash_id_table::capa, hash_id_table::items, MEMZERO, round_capa(), and ZALLOC_N.

Referenced by mix_id_table_insert().

◆ hash_id_table_insert()

static int hash_id_table_insert ( struct hash_id_table tbl,
ID  id,
VALUE  val 
)
static

Definition at line 1379 of file id_table.c.

References hash_id_table_insert_key(), and id2key().

Referenced by list_id_table_foreach_values(), and mix_id_table_insert().

◆ hash_id_table_insert_key()

static int hash_id_table_insert_key ( struct hash_id_table tbl,
const id_key_t  key,
const VALUE  val 
)
static

◆ hash_id_table_lookup()

static int hash_id_table_lookup ( struct hash_id_table tbl,
ID  id,
VALUE valp 
)
static

◆ hash_id_table_memsize()

static size_t hash_id_table_memsize ( const struct hash_id_table tbl)
static

Definition at line 1247 of file id_table.c.

References hash_id_table::capa.

Referenced by list_id_table_foreach_values(), and mix_id_table_memsize().

◆ hash_id_table_size()

static size_t hash_id_table_size ( const struct hash_id_table tbl)
static

Definition at line 1241 of file id_table.c.

References hash_id_table::num.

Referenced by list_id_table_foreach_values(), and mix_id_table_size().

◆ hash_table_extend()

static void hash_table_extend ( struct hash_id_table tbl)
static

◆ hash_table_index()

static int hash_table_index ( struct hash_id_table tbl,
id_key_t  key 
)
static

◆ hash_table_raw_insert()

static void hash_table_raw_insert ( struct hash_id_table tbl,
id_key_t  key,
VALUE  val 
)
static

◆ id2key()

static id_key_t id2key ( ID  id)
inlinestatic

◆ ITEM_SET_KEY()

static void ITEM_SET_KEY ( struct hash_id_table tbl,
int  i,
id_key_t  key 
)
inlinestatic

Definition at line 1185 of file id_table.c.

References ITEM_COLLIDED, hash_id_table::items, and rb_id_item::key.

Referenced by hash_delete_index(), and hash_table_raw_insert().

◆ key2id()

static ID key2id ( id_key_t  key)
inlinestatic

◆ list_delete_index()

static int list_delete_index ( struct list_id_table tbl,
id_key_t  key,
int  index 
)
static

Definition at line 685 of file id_table.c.

References FALSE, list_id_table::keys, list_id_table::num, TABLE_VALUES, tbl_assert(), and TRUE.

Referenced by list_id_table_delete().

◆ list_id_table_clear()

static void list_id_table_clear ( struct list_id_table tbl)
static

Definition at line 421 of file id_table.c.

References list_id_table::num.

Referenced by mix_id_table_clear().

◆ list_id_table_delete()

static int list_id_table_delete ( struct list_id_table tbl,
ID  id 
)
static

Definition at line 714 of file id_table.c.

References id2key(), list_delete_index(), and list_table_index().

Referenced by mix_id_table_delete().

◆ list_id_table_foreach()

static void list_id_table_foreach ( struct list_id_table tbl,
rb_id_table_foreach_func_t func,
void *  data 
)
static

◆ list_id_table_foreach_values()

static void list_id_table_foreach_values ( struct list_id_table tbl,
rb_id_table_foreach_values_func_t func,
void *  data 
)
static

◆ list_id_table_free()

static void list_id_table_free ( struct list_id_table tbl)
static

Definition at line 411 of file id_table.c.

References list_id_table::keys, and xfree().

Referenced by mix_id_table_free().

◆ list_id_table_init()

static struct list_id_table* list_id_table_init ( struct list_id_table tbl,
size_t  capa 
)
static

Definition at line 379 of file id_table.c.

References ALLOC_N, list_id_table::capa, list_id_table::keys, xmalloc, and ZALLOC.

Referenced by mix_id_table_create().

◆ list_id_table_insert()

static int list_id_table_insert ( struct list_id_table tbl,
ID  id,
VALUE  val 
)
static

◆ list_id_table_lookup()

static int list_id_table_lookup ( struct list_id_table tbl,
ID  id,
VALUE valp 
)
static

Definition at line 619 of file id_table.c.

References FALSE, id2key(), list_id_table::keys, list_table_index(), TABLE_VALUES, and TRUE.

Referenced by mix_id_table_lookup().

◆ list_id_table_memsize()

static size_t list_id_table_memsize ( const struct list_id_table tbl)
static

Definition at line 433 of file id_table.c.

References list_id_table::capa.

Referenced by mix_id_table_memsize().

◆ list_id_table_size()

static size_t list_id_table_size ( const struct list_id_table tbl)
static

Definition at line 427 of file id_table.c.

References list_id_table::num.

Referenced by mix_id_table_size().

◆ list_ids_bsearch()

static int list_ids_bsearch ( const id_key_t keys,
id_key_t  key,
int  num 
)
static

Definition at line 548 of file id_table.c.

References assert, key, max(), and list_id_table::num.

Referenced by list_table_index().

◆ list_table_extend()

static void list_table_extend ( struct list_id_table tbl)
static

◆ list_table_index()

static int list_table_index ( struct list_id_table tbl,
id_key_t  key 
)
static

◆ mix_id_table_clear()

static void mix_id_table_clear ( struct mix_id_table tbl)
static

◆ mix_id_table_create()

static struct mix_id_table* mix_id_table_create ( size_t  size)
static

Definition at line 1446 of file id_table.c.

References list_id_table_init(), and ZALLOC.

◆ mix_id_table_delete()

static int mix_id_table_delete ( struct mix_id_table tbl,
ID  id 
)
static

◆ mix_id_table_foreach()

static void mix_id_table_foreach ( struct mix_id_table tbl,
rb_id_table_foreach_func_t func,
void *  data 
)
static

◆ mix_id_table_foreach_values()

static void mix_id_table_foreach_values ( struct mix_id_table tbl,
rb_id_table_foreach_values_func_t func,
void *  data 
)
static

◆ mix_id_table_free()

static void mix_id_table_free ( struct mix_id_table tbl)
static

◆ mix_id_table_insert()

static int mix_id_table_insert ( struct mix_id_table tbl,
ID  id,
VALUE  val 
)
static

◆ mix_id_table_lookup()

static int mix_id_table_lookup ( struct mix_id_table tbl,
ID  id,
VALUE valp 
)
static

◆ mix_id_table_memsize()

static size_t mix_id_table_memsize ( const struct mix_id_table tbl)
static

◆ mix_id_table_size()

static size_t mix_id_table_size ( const struct mix_id_table tbl)
static

◆ round_capa()

static int round_capa ( int  capa)
inlinestatic

Definition at line 1192 of file id_table.c.

Referenced by hash_id_table_init(), and hash_table_extend().

◆ tbl_assert()

static void tbl_assert ( struct list_id_table tbl)
static

Definition at line 528 of file id_table.c.

References list_id_table::keys, list_id_table::num, and rb_bug().

Referenced by list_delete_index(), and list_id_table_insert().

◆ UNUSED() [1/10]

UNUSED ( ID_TABLE_IMPL_TYPE IMPL_create)(size_t)

◆ UNUSED() [2/10]

UNUSED ( void   IMPL_free)(ID_TABLE_IMPL_TYPE *)

◆ UNUSED() [3/10]

UNUSED ( void   IMPL_clear)(ID_TABLE_IMPL_TYPE *)

◆ UNUSED() [4/10]

UNUSED ( size_t   IMPL_size)(const ID_TABLE_IMPL_TYPE *)

◆ UNUSED() [5/10]

UNUSED ( size_t   IMPL_memsize)(const ID_TABLE_IMPL_TYPE *)

◆ UNUSED() [6/10]

UNUSED ( int   IMPL_insert)(ID_TABLE_IMPL_TYPE *, ID, VALUE)

◆ UNUSED() [7/10]

UNUSED ( int   IMPL_lookup)(ID_TABLE_IMPL_TYPE *, ID, VALUE *)

◆ UNUSED() [8/10]

UNUSED ( int   IMPL_delete)(ID_TABLE_IMPL_TYPE *, ID)

◆ UNUSED() [9/10]

UNUSED ( void   IMPL_foreach)(ID_TABLE_IMPL_TYPE *, rb_id_table_foreach_func_t *, void *)

◆ UNUSED() [10/10]

UNUSED ( void   IMPL_foreach_values)(ID_TABLE_IMPL_TYPE *, rb_id_table_foreach_values_func_t *, void *)