32
/* This value is used by default by ha_storage_create(). More memory
33
/** This value is used by default by ha_storage_create(). More memory
33
34
is allocated later when/if it is needed. */
34
35
#define HA_STORAGE_DEFAULT_HEAP_BYTES 1024
36
/* This value is used by default by ha_storage_create(). It is a
37
/** This value is used by default by ha_storage_create(). It is a
37
38
constant per ha_storage's lifetime. */
38
39
#define HA_STORAGE_DEFAULT_HASH_CELLS 4096
40
42
typedef struct ha_storage_struct ha_storage_t;
42
/***********************************************************************
44
/*******************************************************************//**
43
45
Creates a hash storage. If any of the parameters is 0, then a default
47
@return own: hash storage */
49
/* out, own: hash storage */
50
ulint initial_heap_bytes, /* in: initial heap's size */
51
ulint initial_hash_cells); /* in: initial number of cells
52
ulint initial_heap_bytes, /*!< in: initial heap's size */
53
ulint initial_hash_cells); /*!< in: initial number of cells
52
54
in the hash table */
54
/***********************************************************************
56
/*******************************************************************//**
55
57
Copies data into the storage and returns a pointer to the copy. If the
56
58
same data chunk is already present, then pointer to it is returned.
57
59
Data chunks are considered to be equal if len1 == len2 and
59
61
data_len bytes need to be allocated) and the size of storage is going to
60
62
become more than "memlim" then "data" is not added and NULL is returned.
61
63
To disable this behavior "memlim" can be set to 0, which stands for
65
@return pointer to the copy */
65
68
ha_storage_put_memlim(
66
69
/*==================*/
67
/* out: pointer to the copy */
68
ha_storage_t* storage, /* in/out: hash storage */
69
const void* data, /* in: data to store */
70
ulint data_len, /* in: data length */
71
ulint memlim); /* in: memory limit to obey */
73
/***********************************************************************
74
Same as ha_storage_put_memlim() but without memory limit. */
70
ha_storage_t* storage, /*!< in/out: hash storage */
71
const void* data, /*!< in: data to store */
72
ulint data_len, /*!< in: data length */
73
ulint memlim); /*!< in: memory limit to obey */
75
/*******************************************************************//**
76
Same as ha_storage_put_memlim() but without memory limit.
77
@param storage in/out: hash storage
78
@param data in: data to store
79
@param data_len in: data length
80
@return pointer to the copy of the string */
76
81
#define ha_storage_put(storage, data, data_len) \
77
82
ha_storage_put_memlim((storage), (data), (data_len), 0)
79
/***********************************************************************
84
/*******************************************************************//**
80
85
Copies string into the storage and returns a pointer to the copy. If the
81
86
same string is already present, then pointer to it is returned.
82
Strings are considered to be equal if strcmp(str1, str2) == 0. */
87
Strings are considered to be equal if strcmp(str1, str2) == 0.
88
@param storage in/out: hash storage
89
@param str in: string to put
90
@return pointer to the copy of the string */
84
91
#define ha_storage_put_str(storage, str) \
85
92
((const char*) ha_storage_put((storage), (str), strlen(str) + 1))
87
/***********************************************************************
94
/*******************************************************************//**
88
95
Copies string into the storage and returns a pointer to the copy obeying
97
If the same string is already present, then pointer to it is returned.
98
Strings are considered to be equal if strcmp(str1, str2) == 0.
99
@param storage in/out: hash storage
100
@param str in: string to put
101
@param memlim in: memory limit to obey
102
@return pointer to the copy of the string */
91
103
#define ha_storage_put_str_memlim(storage, str, memlim) \
92
104
((const char*) ha_storage_put_memlim((storage), (str), \
93
105
strlen(str) + 1, (memlim)))
95
/***********************************************************************
107
/*******************************************************************//**
96
108
Empties a hash storage, freeing memory occupied by data chunks.
97
109
This invalidates any pointers previously returned by ha_storage_put().
98
110
The hash storage is not invalidated itself and can be used again. */
101
113
ha_storage_empty(
102
114
/*=============*/
103
ha_storage_t** storage); /* in/out: hash storage */
115
ha_storage_t** storage); /*!< in/out: hash storage */
105
/***********************************************************************
117
/*******************************************************************//**
106
118
Frees a hash storage and everything it contains, it cannot be used after
108
This invalidates any pointers previously returned by ha_storage_put().
120
This invalidates any pointers previously returned by ha_storage_put(). */
114
ha_storage_t* storage); /* in/out: hash storage */
125
ha_storage_t* storage); /*!< in, own: hash storage */
116
/***********************************************************************
117
Gets the size of the memory used by a storage. */
127
/*******************************************************************//**
128
Gets the size of the memory used by a storage.
129
@return bytes used */
120
132
ha_storage_get_size(
121
133
/*================*/
122
/* out: bytes used */
123
const ha_storage_t* storage); /* in: hash storage */
134
const ha_storage_t* storage); /*!< in: hash storage */
125
136
#ifndef UNIV_NONINL
126
137
#include "ha0storage.ic"