~jaypipes/drizzle/new-test-runner

« back to all changes in this revision

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

  • Committer: Jay Pipes
  • Date: 2008-12-11 17:52:34 UTC
  • mfrom: (482.16.152 testable)
  • Revision ID: jpipes@serialcoder-20081211175234-uqsfvmgxejvmellq
merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************
 
2
Hash storage.
 
3
Provides a data structure that stores chunks of data in
 
4
its own storage, avoiding duplicates.
 
5
 
 
6
(c) 2007 Innobase Oy
 
7
 
 
8
Created September 22, 2007 Vasil Dimov
 
9
*******************************************************/
 
10
 
 
11
#ifndef ha0storage_h
 
12
#define ha0storage_h
 
13
 
 
14
#include "univ.i"
 
15
 
 
16
/* This value is used by default by ha_storage_create(). More memory
 
17
is allocated later when/if it is needed. */
 
18
#define HA_STORAGE_DEFAULT_HEAP_BYTES   1024
 
19
 
 
20
/* This value is used by default by ha_storage_create(). It is a
 
21
constant per ha_storage's lifetime. */
 
22
#define HA_STORAGE_DEFAULT_HASH_CELLS   4096
 
23
 
 
24
typedef struct ha_storage_struct        ha_storage_t;
 
25
 
 
26
/***********************************************************************
 
27
Creates a hash storage. If any of the parameters is 0, then a default
 
28
value is used. */
 
29
UNIV_INLINE
 
30
ha_storage_t*
 
31
ha_storage_create(
 
32
/*==============*/
 
33
                                        /* out, own: hash storage */
 
34
        ulint   initial_heap_bytes,     /* in: initial heap's size */
 
35
        ulint   initial_hash_cells);    /* in: initial number of cells
 
36
                                        in the hash table */
 
37
 
 
38
/***********************************************************************
 
39
Copies data into the storage and returns a pointer to the copy. If the
 
40
same data chunk is already present, then pointer to it is returned.
 
41
Data chunks are considered to be equal if len1 == len2 and
 
42
memcmp(data1, data2, len1) == 0. If "data" is not present (and thus
 
43
data_len bytes need to be allocated) and the size of storage is going to
 
44
become more than "memlim" then "data" is not added and NULL is returned.
 
45
To disable this behavior "memlim" can be set to 0, which stands for
 
46
"no limit". */
 
47
 
 
48
const void*
 
49
ha_storage_put_memlim(
 
50
/*==================*/
 
51
                                        /* out: pointer to the copy */
 
52
        ha_storage_t*   storage,        /* in/out: hash storage */
 
53
        const void*     data,           /* in: data to store */
 
54
        ulint           data_len,       /* in: data length */
 
55
        ulint           memlim);        /* in: memory limit to obey */
 
56
 
 
57
/***********************************************************************
 
58
Same as ha_storage_put_memlim() but without memory limit. */
 
59
 
 
60
#define ha_storage_put(storage, data, data_len) \
 
61
        ha_storage_put_memlim((storage), (data), (data_len), 0)
 
62
 
 
63
/***********************************************************************
 
64
Copies string into the storage and returns a pointer to the copy. If the
 
65
same string is already present, then pointer to it is returned.
 
66
Strings are considered to be equal if strcmp(str1, str2) == 0. */
 
67
 
 
68
#define ha_storage_put_str(storage, str)        \
 
69
        ((const char*) ha_storage_put((storage), (str), strlen(str) + 1))
 
70
 
 
71
/***********************************************************************
 
72
Copies string into the storage and returns a pointer to the copy obeying
 
73
a memory limit. */
 
74
 
 
75
#define ha_storage_put_str_memlim(storage, str, memlim) \
 
76
        ((const char*) ha_storage_put_memlim((storage), (str),  \
 
77
                                             strlen(str) + 1, (memlim)))
 
78
 
 
79
/***********************************************************************
 
80
Empties a hash storage, freeing memory occupied by data chunks.
 
81
This invalidates any pointers previously returned by ha_storage_put().
 
82
The hash storage is not invalidated itself and can be used again. */
 
83
UNIV_INLINE
 
84
void
 
85
ha_storage_empty(
 
86
/*=============*/
 
87
        ha_storage_t**  storage);       /* in/out: hash storage */
 
88
 
 
89
/***********************************************************************
 
90
Frees a hash storage and everything it contains, it cannot be used after
 
91
this call.
 
92
This invalidates any pointers previously returned by ha_storage_put().
 
93
*/
 
94
UNIV_INLINE
 
95
void
 
96
ha_storage_free(
 
97
/*============*/
 
98
        ha_storage_t*   storage);       /* in/out: hash storage */
 
99
 
 
100
/***********************************************************************
 
101
Gets the size of the memory used by a storage. */
 
102
UNIV_INLINE
 
103
ulint
 
104
ha_storage_get_size(
 
105
/*================*/
 
106
                                                /* out: bytes used */
 
107
        const ha_storage_t*     storage);       /* in: hash storage */
 
108
 
 
109
#ifndef UNIV_NONINL
 
110
#include "ha0storage.ic"
 
111
#endif
 
112
 
 
113
#endif /* ha0storage_h */