CUBRID Engine  latest
memory_hash.c File Reference
#include "config.h"
#include <stdio.h>
#include <assert.h>
#include "memory_hash.h"
#include "chartype.h"
#include "misc_string.h"
#include "error_manager.h"
#include "memory_alloc.h"
#include "message_catalog.h"
#include "environment_variable.h"
#include "set_object.h"
#include "language_support.h"
#include "intl_support.h"
#include "object_primitive.h"
#include "dbtype.h"
Include dependency graph for memory_hash.c:

Go to the source code of this file.

Macros

#define GET_PTR_FOR_HASH(key)   (((UINT64)(key)) & 0xFFFFFFFFUL)
 
#define NPRIMES   170
 

Typedefs

typedef enum mht_put_opt MHT_PUT_OPT
 

Enumerations

enum  mht_put_opt { MHT_OPT_DEFAULT = 0, MHT_OPT_KEEP_KEY = 1, MHT_OPT_INSERT_ONLY = 2, MHT_OPT_INSERT_IF_NOT_EXISTS = 4 }
 

Functions

static unsigned int mht_1str_pseudo_key (const void *key, int key_size)
 
static unsigned int mht_3str_pseudo_key (const void *key, int key_size, const unsigned int max_value)
 
static unsigned int mht_4str_pseudo_key (const void *key, int key_size)
 
static unsigned int mht_5str_pseudo_key (const void *key, int key_size)
 
static unsigned int mht_calculate_htsize (unsigned int ht_size)
 
static int mht_rehash (MHT_TABLE *ht)
 
static const void * mht_put_internal (MHT_TABLE *ht, const void *key, void *data, MHT_PUT_OPT opt)
 
static const void * mht_put2_internal (MHT_TABLE *ht, const void *key, void *data, MHT_PUT_OPT opt)
 
static const void * mht_put_hls_internal (MHT_HLS_TABLE *ht, const void *key, void *data, MHT_PUT_OPT opt)
 
static unsigned int mht_get_shiftmult32 (unsigned int key, const unsigned int ht_size)
 
unsigned int mht_2str_pseudo_key (const void *key, int key_size)
 
unsigned int mht_1strlowerhash (const void *key, const unsigned int ht_size)
 
unsigned int mht_1strhash (const void *key, const unsigned int ht_size)
 
unsigned int mht_2strhash (const void *key, const unsigned int ht_size)
 
unsigned int mht_3strhash (const void *key, const unsigned int ht_size)
 
unsigned int mht_4strhash (const void *key, const unsigned int ht_size)
 
unsigned int mht_5strhash (const void *key, const unsigned int ht_size)
 
unsigned int mht_numhash (const void *key, const unsigned int ht_size)
 
unsigned int mht_ptrhash (const void *key, const unsigned int ht_size)
 
unsigned int mht_valhash (const void *key, const unsigned int ht_size)
 
int mht_compare_ints_are_equal (const void *key1, const void *key2)
 
int mht_compare_logpageids_are_equal (const void *key1, const void *key2)
 
int mht_compare_identifiers_equal (const void *key1, const void *key2)
 
int mht_compare_strings_are_equal (const void *key1, const void *key2)
 
int mht_compare_ptrs_are_equal (const void *key1, const void *key2)
 
int mht_compare_dbvalues_are_equal (const void *key1, const void *key2)
 
MHT_TABLEmht_create (const char *name, int est_size, unsigned int(*hash_func)(const void *key, unsigned int ht_size), int(*cmp_func)(const void *key1, const void *key2))
 
MHT_HLS_TABLEmht_create_hls (const char *name, int est_size, unsigned int(*hash_func)(const void *key, unsigned int ht_size), int(*cmp_func)(const void *key1, const void *key2))
 
void mht_destroy (MHT_TABLE *ht)
 
void mht_destroy_hls (MHT_HLS_TABLE *ht)
 
int mht_clear (MHT_TABLE *ht, int(*rem_func)(const void *key, void *data, void *args), void *func_args)
 
int mht_clear_hls (MHT_HLS_TABLE *ht, int(*rem_func)(const void *key, void *data, void *args), void *func_args)
 
int mht_dump (THREAD_ENTRY *thread_p, FILE *out_fp, const MHT_TABLE *ht, const int print_id_opt, int(*print_func)(THREAD_ENTRY *thread_p, FILE *fp, const void *key, void *data, void *args), void *func_args)
 
int mht_dump_hls (THREAD_ENTRY *thread_p, FILE *out_fp, const MHT_HLS_TABLE *ht, const int print_id_opt, int(*print_func)(THREAD_ENTRY *thread_p, FILE *fp, const void *data, void *args), void *func_args)
 
void * mht_get (MHT_TABLE *ht, const void *key)
 
int mht_adjust_lru_list (MHT_TABLE *ht, HENTRY_PTR hentry)
 
void * mht_get2 (const MHT_TABLE *ht, const void *key, void **last)
 
void * mht_get_hls (const MHT_HLS_TABLE *ht, const void *key, void **last)
 
const void * mht_put_new (MHT_TABLE *ht, const void *key, void *data)
 
const void * mht_put_hls (MHT_HLS_TABLE *ht, const void *key, void *data)
 
const void * mht_put_if_not_exists (MHT_TABLE *ht, const void *key, void *data)
 
const void * mht_put_data (MHT_TABLE *ht, const void *key, void *data)
 
const void * mht_put (MHT_TABLE *ht, const void *key, void *data)
 
const void * mht_put2_new (MHT_TABLE *ht, const void *key, void *data)
 
int mht_rem (MHT_TABLE *ht, const void *key, int(*rem_func)(const void *key, void *data, void *args), void *func_args)
 
int mht_rem2 (MHT_TABLE *ht, const void *key, const void *data, int(*rem_func)(const void *key, void *data, void *args), void *func_args)
 
int mht_map (const MHT_TABLE *ht, int(*map_func)(const void *key, void *data, void *args), void *func_args)
 
int mht_map_no_key (THREAD_ENTRY *thread_p, const MHT_TABLE *ht, int(*map_func)(THREAD_ENTRY *thread_p, void *data, void *args), void *func_args)
 
unsigned int mht_count (const MHT_TABLE *ht)
 
unsigned int mht_get_hash_number (const int ht_size, const DB_VALUE *val)
 

Variables

static const float MHT_REHASH_TRESHOLD = 0.7f
 
static const float MHT_REHASH_FACTOR = 1.3f
 
static const unsigned int mht_Primes [NPRIMES]
 

Macro Definition Documentation

#define GET_PTR_FOR_HASH (   key)    (((UINT64)(key)) & 0xFFFFFFFFUL)

Definition at line 63 of file memory_hash.c.

Referenced by mht_ptrhash(), and mht_valhash().

#define NPRIMES   170

Definition at line 808 of file memory_hash.c.

Referenced by mht_calculate_htsize().

Typedef Documentation

typedef enum mht_put_opt MHT_PUT_OPT

Definition at line 78 of file memory_hash.c.

Enumeration Type Documentation

Enumerator
MHT_OPT_DEFAULT 
MHT_OPT_KEEP_KEY 
MHT_OPT_INSERT_ONLY 
MHT_OPT_INSERT_IF_NOT_EXISTS 

Definition at line 71 of file memory_hash.c.

Function Documentation

static unsigned int mht_1str_pseudo_key ( const void *  key,
int  key_size 
)
static

Definition at line 128 of file memory_hash.c.

References assert, and NULL.

Referenced by mht_1strhash(), and mht_valhash().

Here is the caller graph for this function:

unsigned int mht_1strhash ( const void *  key,
const unsigned int  ht_size 
)

Definition at line 447 of file memory_hash.c.

References assert, mht_1str_pseudo_key(), and NULL.

Referenced by ehash_hash_string_type(), locator_initialize(), shard_stmt_initialize(), and ws_init().

Here is the caller graph for this function:

unsigned int mht_1strlowerhash ( const void *  key,
const unsigned int  ht_size 
)

Definition at line 420 of file memory_hash.c.

References assert, char_tolower(), and NULL.

unsigned int mht_2str_pseudo_key ( const void *  key,
int  key_size 
)

Definition at line 175 of file memory_hash.c.

References assert, i, and NULL.

Referenced by lang_mht2str_default(), and mht_2strhash().

Here is the caller graph for this function:

unsigned int mht_2strhash ( const void *  key,
const unsigned int  ht_size 
)

Definition at line 466 of file memory_hash.c.

References assert, mht_2str_pseudo_key(), and NULL.

Referenced by ehash_hash_string_type().

Here is the caller graph for this function:

static unsigned int mht_3str_pseudo_key ( const void *  key,
int  key_size,
const unsigned int  max_value 
)
static

Definition at line 230 of file memory_hash.c.

References assert, and NULL.

Referenced by mht_3strhash().

Here is the caller graph for this function:

unsigned int mht_3strhash ( const void *  key,
const unsigned int  ht_size 
)

Definition at line 483 of file memory_hash.c.

References assert, mht_3str_pseudo_key(), and NULL.

Referenced by ehash_hash_string_type().

Here is the caller graph for this function:

static unsigned int mht_4str_pseudo_key ( const void *  key,
int  key_size 
)
static

Definition at line 277 of file memory_hash.c.

References assert, and NULL.

Referenced by mht_4strhash().

Here is the caller graph for this function:

unsigned int mht_4strhash ( const void *  key,
const unsigned int  ht_size 
)

Definition at line 505 of file memory_hash.c.

References assert, mht_4str_pseudo_key(), and NULL.

Referenced by pt_make_subclass_list().

Here is the caller graph for this function:

static unsigned int mht_5str_pseudo_key ( const void *  key,
int  key_size 
)
static

Definition at line 376 of file memory_hash.c.

References assert, i, and NULL.

Referenced by mht_5strhash().

Here is the caller graph for this function:

unsigned int mht_5strhash ( const void *  key,
const unsigned int  ht_size 
)

Definition at line 521 of file memory_hash.c.

References mht_5str_pseudo_key().

Referenced by er_call_stack_init(), es_name_hash_func(), xtx_add_lob_locator(), xtx_change_state_of_locator(), xtx_drop_lob_locator(), and xtx_find_lob_locator().

Here is the caller graph for this function:

int mht_adjust_lru_list ( MHT_TABLE ht,
HENTRY_PTR  hentry 
)

Definition at line 1457 of file memory_hash.c.

References assert, mht_table::build_lru_list, mht_table::lru_head, hentry::lru_next, hentry::lru_prev, mht_table::lru_tail, NO_ERROR, and NULL.

Referenced by mht_get().

Here is the caller graph for this function:

static unsigned int mht_calculate_htsize ( unsigned int  ht_size)
static

Definition at line 830 of file memory_hash.c.

References CEIL_PTVDIV, mht_Primes, and NPRIMES.

Referenced by mht_create(), mht_create_hls(), and mht_rehash().

Here is the caller graph for this function:

int mht_clear_hls ( MHT_HLS_TABLE ht,
int(*)(const void *key, void *data, void *args)  rem_func,
void *  func_args 
)
int mht_compare_dbvalues_are_equal ( const void *  key1,
const void *  key2 
)

Definition at line 791 of file memory_hash.c.

References DB_EQ, and tp_value_compare().

Referenced by qfile_compare_equal_db_value_array().

Here is the caller graph for this function:

int mht_compare_identifiers_equal ( const void *  key1,
const void *  key2 
)

Definition at line 755 of file memory_hash.c.

References intl_identifier_casecmp().

Referenced by pt_associate_label_with_value().

Here is the caller graph for this function:

int mht_compare_ints_are_equal ( const void *  key1,
const void *  key2 
)

Definition at line 731 of file memory_hash.c.

int mht_compare_logpageids_are_equal ( const void *  key1,
const void *  key2 
)

Definition at line 743 of file memory_hash.c.

Referenced by la_init_cache_log_buffer().

Here is the caller graph for this function:

int mht_compare_ptrs_are_equal ( const void *  key1,
const void *  key2 
)

Definition at line 779 of file memory_hash.c.

Referenced by tr_init().

Here is the caller graph for this function:

int mht_compare_strings_are_equal ( const void *  key1,
const void *  key2 
)

Definition at line 767 of file memory_hash.c.

Referenced by er_call_stack_init(), locator_initialize(), pt_make_subclass_list(), shard_stmt_initialize(), and ws_init().

Here is the caller graph for this function:

void mht_destroy_hls ( MHT_HLS_TABLE ht)

Definition at line 1160 of file memory_hash.c.

References assert, db_destroy_fixed_heap(), free_and_init, mht_hls_table::heap_id, NULL, and mht_hls_table::table.

Referenced by scan_close_scan().

Here is the caller graph for this function:

int mht_dump ( THREAD_ENTRY thread_p,
FILE *  out_fp,
const MHT_TABLE ht,
const int  print_id_opt,
int(*)(THREAD_ENTRY *thread_p, FILE *fp, const void *key, void *data, void *args)  print_func,
void *  func_args 
)
int mht_dump_hls ( THREAD_ENTRY thread_p,
FILE *  out_fp,
const MHT_HLS_TABLE ht,
const int  print_id_opt,
int(*)(THREAD_ENTRY *thread_p, FILE *fp, const void *data, void *args)  print_func,
void *  func_args 
)
void* mht_get ( MHT_TABLE ht,
const void *  key 
)
void* mht_get2 ( const MHT_TABLE ht,
const void *  key,
void **  last 
)
void* mht_get_hls ( const MHT_HLS_TABLE ht,
const void *  key,
void **  last 
)

Definition at line 1550 of file memory_hash.c.

References assert, hentry_hls::data, mht_hls_table::hash_func, NULL, mht_hls_table::size, and mht_hls_table::table.

Referenced by scan_hash_probe_next().

Here is the caller graph for this function:

static unsigned int mht_get_shiftmult32 ( unsigned int  key,
const unsigned int  ht_size 
)
static

Definition at line 2512 of file memory_hash.c.

Referenced by mht_get_hash_number().

Here is the caller graph for this function:

unsigned int mht_numhash ( const void *  key,
const unsigned int  ht_size 
)

Definition at line 533 of file memory_hash.c.

References assert, and NULL.

unsigned int mht_ptrhash ( const void *  key,
const unsigned int  ht_size 
)

Definition at line 547 of file memory_hash.c.

References assert, GET_PTR_FOR_HASH, and NULL.

Referenced by tr_init().

Here is the caller graph for this function:

const void* mht_put2_new ( MHT_TABLE ht,
const void *  key,
void *  data 
)
const void* mht_put_data ( MHT_TABLE ht,
const void *  key,
void *  data 
)

Definition at line 1756 of file memory_hash.c.

References assert, MHT_OPT_KEEP_KEY, mht_put_internal(), and NULL.

Referenced by pt_associate_label_with_value().

Here is the caller graph for this function:

const void* mht_put_hls ( MHT_HLS_TABLE ht,
const void *  key,
void *  data 
)

Definition at line 1730 of file memory_hash.c.

References assert, MHT_OPT_INSERT_ONLY, mht_put_hls_internal(), and NULL.

Referenced by scan_build_hash_list_scan().

Here is the caller graph for this function:

static const void * mht_put_hls_internal ( MHT_HLS_TABLE ht,
const void *  key,
void *  data,
MHT_PUT_OPT  opt 
)
static
const void* mht_put_if_not_exists ( MHT_TABLE ht,
const void *  key,
void *  data 
)

Definition at line 1749 of file memory_hash.c.

References assert, MHT_OPT_INSERT_IF_NOT_EXISTS, mht_put_internal(), and NULL.

Referenced by catcls_put_entry(), and partition_cache_pruning_context().

Here is the caller graph for this function:

const void* mht_put_new ( MHT_TABLE ht,
const void *  key,
void *  data 
)

Definition at line 1723 of file memory_hash.c.

References assert, MHT_OPT_INSERT_ONLY, mht_put_internal(), and NULL.

Referenced by heap_stats_add_bestspace(), and qfile_update_list_cache_entry().

Here is the caller graph for this function:

unsigned int mht_valhash ( const void *  key,
const unsigned int  ht_size 
)

Variable Documentation

const unsigned int mht_Primes[NPRIMES]
static
Initial value:
= {
11, 23, 37, 53, 67, 79, 97, 109, 127, 149,
167, 191, 211, 227, 251, 269, 293, 311, 331, 349,
367, 389, 409, 431, 449, 467, 487, 509, 541, 563,
587, 607, 631, 653, 673, 521, 541, 557, 569, 587,
599, 613, 641, 673, 701, 727, 751, 787, 821, 853,
881, 907, 941, 977, 1039, 1087, 1129, 1171, 1213, 1259,
1301, 1361, 1409, 1471, 1523, 1579, 1637, 1693, 1747, 1777,
1823, 1867, 1913, 1973, 2017, 2129, 2237, 2339, 2441, 2543,
2647, 2749, 2851, 2953, 3061, 3163, 3271, 3373, 3491, 3593,
3697, 3803, 3907, 4013, 4177, 4337, 4493, 4649, 4801, 4957,
5059, 5167, 5273, 5381, 5483, 5591, 5693, 5801, 5903, 6007,
6113, 6217, 6317, 6421, 6521, 6637, 6737, 6841, 6847, 7057,
7283, 7487, 7687, 7901, 8101, 8311, 8513, 8713, 8923, 9127,
9337, 9539, 9739, 9941, 10141, 10343, 10559, 10771, 10973, 11177,
11383, 11587, 11789, 12007, 12409, 12809, 13217, 13619, 14029, 14431,
14831, 15233, 15641, 16057, 16477, 16879, 17291, 18097, 18899, 19699,
20507, 21313, 22123, 23131, 24133, 25147, 26153, 27179, 28181, 29123
}

Definition at line 809 of file memory_hash.c.

Referenced by mht_calculate_htsize().

const float MHT_REHASH_FACTOR = 1.3f
static

Definition at line 68 of file memory_hash.c.

Referenced by mht_rehash().

const float MHT_REHASH_TRESHOLD = 0.7f
static

Definition at line 67 of file memory_hash.c.

Referenced by mht_create(), and mht_rehash().