1
/*****************************************************************************
3
Copyright (C) 2007, 2009, Innobase Oy. All Rights Reserved.
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
17
*****************************************************************************/
19
/**************************************************//**
20
@file include/ha0storage.h
22
Provides a data structure that stores chunks of data in
23
its own storage, avoiding duplicates.
25
Created September 22, 2007 Vasil Dimov
26
*******************************************************/
33
/** This value is used by default by ha_storage_create(). More memory
34
is allocated later when/if it is needed. */
35
#define HA_STORAGE_DEFAULT_HEAP_BYTES 1024
37
/** This value is used by default by ha_storage_create(). It is a
38
constant per ha_storage's lifetime. */
39
#define HA_STORAGE_DEFAULT_HASH_CELLS 4096
42
typedef struct ha_storage_struct ha_storage_t;
44
/*******************************************************************//**
45
Creates a hash storage. If any of the parameters is 0, then a default
47
@return own: hash storage */
52
ulint initial_heap_bytes, /*!< in: initial heap's size */
53
ulint initial_hash_cells); /*!< in: initial number of cells
56
/*******************************************************************//**
57
Copies data into the storage and returns a pointer to the copy. If the
58
same data chunk is already present, then pointer to it is returned.
59
Data chunks are considered to be equal if len1 == len2 and
60
memcmp(data1, data2, len1) == 0. If "data" is not present (and thus
61
data_len bytes need to be allocated) and the size of storage is going to
62
become more than "memlim" then "data" is not added and NULL is returned.
63
To disable this behavior "memlim" can be set to 0, which stands for
65
@return pointer to the copy */
68
ha_storage_put_memlim(
69
/*==================*/
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 */
81
#define ha_storage_put(storage, data, data_len) \
82
ha_storage_put_memlim((storage), (data), (data_len), 0)
84
/*******************************************************************//**
85
Copies string into the storage and returns a pointer to the copy. If the
86
same string is already present, then pointer to it is returned.
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 */
91
#define ha_storage_put_str(storage, str) \
92
((const char*) ha_storage_put((storage), (str), strlen(str) + 1))
94
/*******************************************************************//**
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 */
103
#define ha_storage_put_str_memlim(storage, str, memlim) \
104
((const char*) ha_storage_put_memlim((storage), (str), \
105
strlen(str) + 1, (memlim)))
107
/*******************************************************************//**
108
Empties a hash storage, freeing memory occupied by data chunks.
109
This invalidates any pointers previously returned by ha_storage_put().
110
The hash storage is not invalidated itself and can be used again. */
115
ha_storage_t** storage); /*!< in/out: hash storage */
117
/*******************************************************************//**
118
Frees a hash storage and everything it contains, it cannot be used after
120
This invalidates any pointers previously returned by ha_storage_put(). */
125
ha_storage_t* storage); /*!< in, own: hash storage */
127
/*******************************************************************//**
128
Gets the size of the memory used by a storage.
129
@return bytes used */
134
const ha_storage_t* storage); /*!< in: hash storage */
137
#include "ha0storage.ic"
140
#endif /* ha0storage_h */