~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/include/ha0storage.h

  • Committer: Brian Aker
  • Date: 2010-06-28 16:17:36 UTC
  • mfrom: (1637.4.1 drizzle)
  • Revision ID: brian@gaz-20100628161736-eormhb2mnd551i2h
MergeĀ unused

Show diffs side-by-side

added added

removed removed

Lines of Context:
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., 51 Franklin
15
 
St, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/**************************************************//**
20
 
@file include/ha0storage.h
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
 
 
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
36
 
 
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
40
 
 
41
 
/** Hash storage */
42
 
typedef struct ha_storage_struct        ha_storage_t;
43
 
 
44
 
/*******************************************************************//**
45
 
Creates a hash storage. If any of the parameters is 0, then a default
46
 
value is used.
47
 
@return own: hash storage */
48
 
UNIV_INLINE
49
 
ha_storage_t*
50
 
ha_storage_create(
51
 
/*==============*/
52
 
        ulint   initial_heap_bytes,     /*!< in: initial heap's size */
53
 
        ulint   initial_hash_cells);    /*!< in: initial number of cells
54
 
                                        in the hash table */
55
 
 
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
64
 
"no limit".
65
 
@return pointer to the copy */
66
 
UNIV_INTERN
67
 
const void*
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 */
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 */
81
 
#define ha_storage_put(storage, data, data_len) \
82
 
        ha_storage_put_memlim((storage), (data), (data_len), 0)
83
 
 
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))
93
 
 
94
 
/*******************************************************************//**
95
 
Copies string into the storage and returns a pointer to the copy obeying
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 */
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
 
 
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. */
111
 
UNIV_INLINE
112
 
void
113
 
ha_storage_empty(
114
 
/*=============*/
115
 
        ha_storage_t**  storage);       /*!< in/out: hash storage */
116
 
 
117
 
/*******************************************************************//**
118
 
Frees a hash storage and everything it contains, it cannot be used after
119
 
this call.
120
 
This invalidates any pointers previously returned by ha_storage_put(). */
121
 
UNIV_INLINE
122
 
void
123
 
ha_storage_free(
124
 
/*============*/
125
 
        ha_storage_t*   storage);       /*!< in, own: hash storage */
126
 
 
127
 
/*******************************************************************//**
128
 
Gets the size of the memory used by a storage.
129
 
@return bytes used */
130
 
UNIV_INLINE
131
 
ulint
132
 
ha_storage_get_size(
133
 
/*================*/
134
 
        const ha_storage_t*     storage);       /*!< in: hash storage */
135
 
 
136
 
#ifndef UNIV_NONINL
137
 
#include "ha0storage.ic"
138
 
#endif
139
 
 
140
 
#endif /* ha0storage_h */