1
/******************************************************
3
Provides a data structure that stores chunks of data in
4
its own storage, avoiding duplicates.
8
Created September 22, 2007 Vasil Dimov
9
*******************************************************/
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
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
24
typedef struct ha_storage_struct ha_storage_t;
26
/***********************************************************************
27
Creates a hash storage. If any of the parameters is 0, then a default
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
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
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 */
57
/***********************************************************************
58
Same as ha_storage_put_memlim() but without memory limit. */
60
#define ha_storage_put(storage, data, data_len) \
61
ha_storage_put_memlim((storage), (data), (data_len), 0)
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. */
68
#define ha_storage_put_str(storage, str) \
69
((const char*) ha_storage_put((storage), (str), strlen(str) + 1))
71
/***********************************************************************
72
Copies string into the storage and returns a pointer to the copy obeying
75
#define ha_storage_put_str_memlim(storage, str, memlim) \
76
((const char*) ha_storage_put_memlim((storage), (str), \
77
strlen(str) + 1, (memlim)))
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. */
87
ha_storage_t** storage); /* in/out: hash storage */
89
/***********************************************************************
90
Frees a hash storage and everything it contains, it cannot be used after
92
This invalidates any pointers previously returned by ha_storage_put().
98
ha_storage_t* storage); /* in/out: hash storage */
100
/***********************************************************************
101
Gets the size of the memory used by a storage. */
106
/* out: bytes used */
107
const ha_storage_t* storage); /* in: hash storage */
110
#include "ha0storage.ic"
113
#endif /* ha0storage_h */