~drizzle-trunk/drizzle/development

641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
1
/*****************************************************************************
2
3
Copyright (c) 2007, 2009, Innobase Oy. All Rights Reserved.
4
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.
8
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.
12
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., 59 Temple
15
Place, Suite 330, Boston, MA 02111-1307 USA
16
17
*****************************************************************************/
18
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
19
/**************************************************//**
20
@file include/ha0storage.h
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
21
Hash storage.
22
Provides a data structure that stores chunks of data in
23
its own storage, avoiding duplicates.
24
25
Created September 22, 2007 Vasil Dimov
26
*******************************************************/
27
28
#ifndef ha0storage_h
29
#define ha0storage_h
30
31
#include "univ.i"
32
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
33
/** This value is used by default by ha_storage_create(). More memory
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
34
is allocated later when/if it is needed. */
35
#define HA_STORAGE_DEFAULT_HEAP_BYTES	1024
36
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
37
/** This value is used by default by ha_storage_create(). It is a
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
38
constant per ha_storage's lifetime. */
39
#define HA_STORAGE_DEFAULT_HASH_CELLS	4096
40
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
41
/** Hash storage */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
42
typedef struct ha_storage_struct	ha_storage_t;
43
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
44
/*******************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
45
Creates a hash storage. If any of the parameters is 0, then a default
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
46
value is used.
47
@return	own: hash storage */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
48
UNIV_INLINE
49
ha_storage_t*
50
ha_storage_create(
51
/*==============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
52
	ulint	initial_heap_bytes,	/*!< in: initial heap's size */
53
	ulint	initial_hash_cells);	/*!< in: initial number of cells
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
54
					in the hash table */
55
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
56
/*******************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
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
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
64
"no limit".
65
@return	pointer to the copy */
66
UNIV_INTERN
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
67
const void*
68
ha_storage_put_memlim(
69
/*==================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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 */
74
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 */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
81
#define ha_storage_put(storage, data, data_len)	\
82
	ha_storage_put_memlim((storage), (data), (data_len), 0)
83
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
84
/*******************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
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.
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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 */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
91
#define ha_storage_put_str(storage, str)	\
92
	((const char*) ha_storage_put((storage), (str), strlen(str) + 1))
93
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
94
/*******************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
95
Copies string into the storage and returns a pointer to the copy obeying
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
96
a memory limit.
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 */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
103
#define ha_storage_put_str_memlim(storage, str, memlim)	\
104
	((const char*) ha_storage_put_memlim((storage), (str),	\
105
					     strlen(str) + 1, (memlim)))
106
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
107
/*******************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
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. */
111
UNIV_INLINE
112
void
113
ha_storage_empty(
114
/*=============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
115
	ha_storage_t**	storage);	/*!< in/out: hash storage */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
116
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
117
/*******************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
118
Frees a hash storage and everything it contains, it cannot be used after
119
this call.
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
120
This invalidates any pointers previously returned by ha_storage_put(). */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
121
UNIV_INLINE
122
void
123
ha_storage_free(
124
/*============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
125
	ha_storage_t*	storage);	/*!< in, own: hash storage */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
126
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
127
/*******************************************************************//**
128
Gets the size of the memory used by a storage.
129
@return	bytes used */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
130
UNIV_INLINE
131
ulint
132
ha_storage_get_size(
133
/*================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
134
	const ha_storage_t*	storage);	/*!< in: hash storage */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
135
136
#ifndef UNIV_NONINL
137
#include "ha0storage.ic"
138
#endif
139
140
#endif /* ha0storage_h */