~drizzle-trunk/drizzle/development

641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
1
/*****************************************************************************
2
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
3
Copyright (C) 2007, 2009, Innobase Oy. All Rights Reserved.
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
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
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
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
2234 by Brian Aker
Mass removal of ifdef/endif in favor of pragma once.
28
#pragma once
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
29
#ifndef ha0storage_h
30
#define ha0storage_h
31
32
#include "univ.i"
33
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
34
/** 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.
35
is allocated later when/if it is needed. */
36
#define HA_STORAGE_DEFAULT_HEAP_BYTES	1024
37
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
38
/** 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.
39
constant per ha_storage's lifetime. */
40
#define HA_STORAGE_DEFAULT_HASH_CELLS	4096
41
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
42
/** Hash storage */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
43
typedef struct ha_storage_struct	ha_storage_t;
44
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
45
/*******************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
46
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
47
value is used.
48
@return	own: hash storage */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
49
UNIV_INLINE
50
ha_storage_t*
51
ha_storage_create(
52
/*==============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
53
	ulint	initial_heap_bytes,	/*!< in: initial heap's size */
54
	ulint	initial_hash_cells);	/*!< in: initial number of cells
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
55
					in the hash table */
56
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
57
/*******************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
58
Copies data into the storage and returns a pointer to the copy. If the
59
same data chunk is already present, then pointer to it is returned.
60
Data chunks are considered to be equal if len1 == len2 and
61
memcmp(data1, data2, len1) == 0. If "data" is not present (and thus
62
data_len bytes need to be allocated) and the size of storage is going to
63
become more than "memlim" then "data" is not added and NULL is returned.
64
To disable this behavior "memlim" can be set to 0, which stands for
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
65
"no limit".
66
@return	pointer to the copy */
67
UNIV_INTERN
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
68
const void*
69
ha_storage_put_memlim(
70
/*==================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
71
	ha_storage_t*	storage,	/*!< in/out: hash storage */
72
	const void*	data,		/*!< in: data to store */
73
	ulint		data_len,	/*!< in: data length */
74
	ulint		memlim);	/*!< in: memory limit to obey */
75
76
/*******************************************************************//**
77
Same as ha_storage_put_memlim() but without memory limit.
78
@param storage	in/out: hash storage
79
@param data	in: data to store
80
@param data_len	in: data length
81
@return		pointer to the copy of the string */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
82
#define ha_storage_put(storage, data, data_len)	\
83
	ha_storage_put_memlim((storage), (data), (data_len), 0)
84
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
85
/*******************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
86
Copies string into the storage and returns a pointer to the copy. If the
87
same string is already present, then pointer to it is returned.
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
88
Strings are considered to be equal if strcmp(str1, str2) == 0.
89
@param storage	in/out: hash storage
90
@param str	in: string to put
91
@return		pointer to the copy of the string */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
92
#define ha_storage_put_str(storage, str)	\
93
	((const char*) ha_storage_put((storage), (str), strlen(str) + 1))
94
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
95
/*******************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
96
Copies string into the storage and returns a pointer to the copy obeying
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
97
a memory limit.
98
If the same string is already present, then pointer to it is returned.
99
Strings are considered to be equal if strcmp(str1, str2) == 0.
100
@param storage	in/out: hash storage
101
@param str	in: string to put
102
@param memlim	in: memory limit to obey
103
@return		pointer to the copy of the string */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
104
#define ha_storage_put_str_memlim(storage, str, memlim)	\
105
	((const char*) ha_storage_put_memlim((storage), (str),	\
106
					     strlen(str) + 1, (memlim)))
107
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
108
/*******************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
109
Empties a hash storage, freeing memory occupied by data chunks.
110
This invalidates any pointers previously returned by ha_storage_put().
111
The hash storage is not invalidated itself and can be used again. */
112
UNIV_INLINE
113
void
114
ha_storage_empty(
115
/*=============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
116
	ha_storage_t**	storage);	/*!< in/out: hash storage */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
117
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
118
/*******************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
119
Frees a hash storage and everything it contains, it cannot be used after
120
this call.
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
121
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.
122
UNIV_INLINE
123
void
124
ha_storage_free(
125
/*============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
126
	ha_storage_t*	storage);	/*!< in, own: hash storage */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
127
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
128
/*******************************************************************//**
129
Gets the size of the memory used by a storage.
130
@return	bytes used */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
131
UNIV_INLINE
132
ulint
133
ha_storage_get_size(
134
/*================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
135
	const ha_storage_t*	storage);	/*!< in: hash storage */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
136
137
#ifndef UNIV_NONINL
138
#include "ha0storage.ic"
139
#endif
140
141
#endif /* ha0storage_h */